From 0a1e82b55d0d7ddeba6ec0a29480a048b5b97c57 Mon Sep 17 00:00:00 2001 From: Artem Brezhnev Date: Wed, 3 Jan 2018 22:47:05 +0200 Subject: [PATCH 1/2] Register the listeners within subscriber. Fixed README.md --- README.md | 99 ++++++++++++++++--------- src/Listeners/PluginEventSubscriber.php | 3 + 2 files changed, 67 insertions(+), 35 deletions(-) diff --git a/README.md b/README.md index 1f43795..84765c7 100644 --- a/README.md +++ b/README.md @@ -23,13 +23,13 @@ Install dependency via Composer $ composer require brezzhnev/atlassian-connect-core ``` -Register **route middleware** `jwt` by adding to the `app\Http\Kernel.php` following line +Register **route middleware** `jwt` by adding to `app\Http\Kernel.php` the following line: ``` php 'jwt' => \AtlassianConnectCore\Http\Middleware\JWTAuth::class ``` -Set authentication driver to `jwt` in `config/auth.php` +Set authentication driver to `jwt` in `config/auth.php`: ``` php 'guards' => [ @@ -40,7 +40,7 @@ Set authentication driver to `jwt` in `config/auth.php` ... ``` -Set model class in `config/auth.php` **providers** section +Set model class in `config/auth.php` **providers** section: ``` php 'providers' => [ @@ -51,22 +51,9 @@ Set model class in `config/auth.php` **providers** section ... ``` -Register plugin events by adding to the `app/Providers/EventServiceProvider.php` to the `listen` property value following +Register the subscriber in the `app/Providers/EventServiceProvider.php`: ``` php -\AtlassianConnectCore\Events\Installed::class => [ - \AtlassianConnectCore\Listeners\CreateOrUpdateTenant::class -], -\AtlassianConnectCore\Events\Uninstalled::class => [ - \AtlassianConnectCore\Listeners\DeleteTenant::class -] -``` - -> You can use any add-on events to register your own listeners - -Register subscriber in the same file: - -``` /** * The subscriber classes to register. * @@ -77,14 +64,14 @@ protected $subscribe = [ ]; ``` -Configure database and run +Configure database and run the following: ``` php artisan migrate php artisan plugin:install ``` -Command `php artisan plugin:install` will publish config, views and resources that you can change whatever you want. +The command `php artisan plugin:install` will publish config, views and resources that you can change for your needs. Also, it will create "dummy" tenant needed for local testing and development without the need of installing the add-on in real JIRA or Confluence instance. @@ -92,17 +79,19 @@ without the need of installing the add-on in real JIRA or Confluence instance. ### Get it working If your application returns the add-on descriptor on the request -to URL `http://localhost:8000/atlassian-connect.json` it means you are close to getting it working and you can +to URL `http://localhost:8000/atlassian-connect.json` it means you are close to happiness and you can install the add-on. -Firstly, you need to enable development options. -Go to the "Manage add-ons" page. You'll see the link "Settings" at bottom of page. +Firstly, you need to enable the development options. +Go to the "Manage add-ons" page. You'll see the link "Settings" at bottom of the page. After clicking you'll see two checkboxes that must be selected. Apply your changes. -For installing the add-on in the instance it should see your server. -If you working locally the easiest way is use [ngrok](https://ngrok.com/). +For installing the add-on in the instance, the last one should see your server. +If you are working locally the easiest way is to use [ngrok](https://ngrok.com/). -After you are visible for the JIRA or Atlassian instance you should put your actual website URL to environment variable `PLUGIN_URL`. Also, you need to configure your add-on by editing the file `config/plugin.php`. Most values may be overwritten using env vars. +After you are visible in the worldwide you should put your actual website URL to environment variable `PLUGIN_URL`. +Also, you need to configure your add-on by editing the file `config/plugin.php`. +Most values may be overwritten using env vars. Then you need to upload the add-on. Click "Upload add-on" and paste your public URL with descriptor path, eg. `https://d1ea31ce.ngrok.io/atlassian-connect.json` or `https://yourplugindomain.com/atlassian-connect.json` @@ -112,7 +101,7 @@ eg. `https://d1ea31ce.ngrok.io/atlassian-connect.json` or `https://yourplugindom After successfully installing you can see "Your add-on" top menu item (in case of JIRA). You also can go to the add-on general page by direct link `:product_base_url/plugins/servlet/ac/sample-plugin/hello-page` -Instead `:product_base_url` you should put your JIRA or Cofluence instance URL (eg. `https://google-dev.atlassian.net`). +> Instead `:product_base_url` you should put your JIRA or Cofluence instance URL (eg. `https://google-dev.atlassian.net`). If you see page working, the application configured and add-on installed correctly. @@ -120,24 +109,25 @@ If you see page working, the application configured and add-on installed correct Instead of using `plugin:install` you can perform actions manually. -To copy all publishes you should use following commands: +To copy all the publishes you should use the following command: ``` -artisan vendor:publish --provider="AtlassianConnectCore\ServiceProvider" +php artisan vendor:publish --provider="AtlassianConnectCore\ServiceProvider" ``` To copy only specific publish you must call this command with option `--tag`. -Value can be `public` (to copy assets), `views` and `config`. +The value can be `public` (to copy assets), `views` and `config`. ## Workflow ### Add-On Configuration -After copying publishes you can see the file `config/plugin.php` in your application. Please, use this configuration file to change add-on properties. +After copying publishes you can see the file `config/plugin.php` in your application. +Please, use this configuration file to change add-on properties. ### Default routes -The following routes registered by default +The following routes are registered by default: * `GET /atlassian-connect.json` descriptor contents * `POST /installed` add-on installed callback @@ -146,7 +136,7 @@ The following routes registered by default * `POST /disabled` add-on disabled callback * `GET /hello` sample page to persuade all working correctly -You can disable it by setting to `false` config value `plugin.loadRoutes`. +You can disable them by setting to `false` config value `plugin.loadRoutes`. ### Descriptor @@ -170,10 +160,11 @@ Descriptor::base() // base descriptor contents ### Performing requests -In most of cases in development add-on for Atlassian Product you need to perform requests to the instance. +In most cases of add-on development for Atlassian Product you need to perform requests to the instance. + +For this case you can use `JWTClient`. It uses [GuzzleHttp](https://github.com/guzzle/guzzle) as HTTP client. -For this case you should use `JWTClient`. It uses [GuzzleHttp](https://github.com/guzzle/guzzle) as HTTP client and -if you want to have custom handling (middlewares etc.) you can pass client instance to the constructor. +> If you want to have custom handling (middlewares etc.) you can pass client instance to the constructor. #### Pagination @@ -187,6 +178,44 @@ There are two paginators: Of course you can extend `Paginator` class and create your own. +#### Examples + +**Get a Confluence page content** + +``` php +use AtlassianConnectCore\Http\Clients\JWTClient; + +... + + +public function pageContent(int $id): array +{ + $client = new JWTClient($this->tenant); // or Auth::user() if you performing a request from the instance + + return $client->get('rest/api/content/ . $id', [ + 'query' => [ + 'expand' => 'body.storage' + ] + ]); +} +``` + +**Get a JIRA issue** + +``` php +use AtlassianConnectCore\Http\Clients\JWTClient; + +... + + +public function viewIssue(string $key): array +{ + $client = new JWTClient($this->tenant); + + return $client->get('rest/api/2/issue/ . $key'); +} +``` + ### Console commands * `plugin:install` is a helper command that creates "dummy" tenant with fake data and publishes package resources (config, views, assets) diff --git a/src/Listeners/PluginEventSubscriber.php b/src/Listeners/PluginEventSubscriber.php index d087d82..8f9db4c 100644 --- a/src/Listeners/PluginEventSubscriber.php +++ b/src/Listeners/PluginEventSubscriber.php @@ -16,6 +16,9 @@ class PluginEventSubscriber */ public function subscribe($events) { + $events->listen(\AtlassianConnectCore\Events\Installed::class, CreateOrUpdateTenant::class); + $events->listen(\AtlassianConnectCore\Events\Uninstalled::class, DeleteTenant::class); + $events->listen([ \AtlassianConnectCore\Events\Installed::class, \AtlassianConnectCore\Events\Uninstalled::class, From 2a956bbe2ec1e52e7ed1185edfb87b40f2d7b8bb Mon Sep 17 00:00:00 2001 From: Artem Brezhnev Date: Wed, 3 Jan 2018 22:56:07 +0200 Subject: [PATCH 2/2] Updated CHANGELOG.md --- CHANGELOG.md | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bc3c277..f23177d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). +## [1.2.1] - 2018-01-03 + +### Fixed +- Register the listeners in the subscriber instead of putting to the **EventServiceProvider** +- Fixed and improved README + ## [1.2.0] - 2017-09-24 ### Added @@ -39,7 +45,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ### Fixed - Package keywords at composer.json -[Unreleased]: https://github.com/brezzhnev/atlassian-connect-core/compare/v1.2.0...HEAD +[Unreleased]: https://github.com/brezzhnev/atlassian-connect-core/compare/v1.2.1...HEAD +[1.2.1]: https://github.com/brezzhnev/atlassian-connect-core/compare/v1.2.0...v1.2.1 [1.2.0]: https://github.com/brezzhnev/atlassian-connect-core/compare/v1.1.0...v1.2.0 [1.1.0]: https://github.com/brezzhnev/atlassian-connect-core/compare/v1.0.2...v1.1.0 [1.0.2]: https://github.com/brezzhnev/atlassian-connect-core/compare/v1.0.1...v1.0.2