diff --git a/CHANGELOG.md b/CHANGELOG.md index e1ba498..f3d3633 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,14 @@ +# Version 1.6.5 +This update takes advantage on the most recent seat-notification update (>1.1.0). Notifications may now be selected individually: +* SeatGroup Sync Event: Dispatched whenever a user group is attached or detached from a role +* SeATGroup Error Event: Dispatched whenever an error happens and laravel log should be investigated +* Missing Refresh Token Event: Dispatched every time SeAT Group finds a refresh token to be missing. Please note you can stop SeAT to notify you about a certain user that might have left your corporation or sold his character by deactivating the user (link is provided inside the notification to do so). + +Furthermore: +* Fixed smaller typos +* Assure `eveseat/web ~3.0.14` is present +* Changed licence to MIT + # Version 1.6.4 * Include new seat plugin service pattern. * Use proper form-id to subscribe to notifications diff --git a/composer.json b/composer.json index f91c0eb..7fc367d 100644 --- a/composer.json +++ b/composer.json @@ -1,18 +1,18 @@ { "name": "herpaderpaldent/seat-groups", - "description": "A module for SeAT that adds the ability of using goups to assign roles to user that are in a group", + "description": "A module for SeAT that adds the ability of using groups to assign roles to user that are in a group", "type": "seat-plugin", "require": { "php": ">=7.1", "laravel/framework": "5.5.*", - "eveseat/web": ">=3.0.10" + "eveseat/web": "~3.0.14" }, "require-dev": { "orchestra/testbench": "3.5.*", "orchestra/database" : "~3.5", "phpunit/phpunit": "~6.0" }, - "license": "GPL-2.0-only", + "license": "MIT", "authors": [ { "name": "Felix Huber", diff --git a/src/Http/Controllers/Notifications/MissingRefreshTokenController.php b/src/Http/Controllers/Notifications/MissingRefreshTokenController.php new file mode 100644 index 0000000..c77ba3d --- /dev/null +++ b/src/Http/Controllers/Notifications/MissingRefreshTokenController.php @@ -0,0 +1,116 @@ +getPrivateChannel($via); + + if(is_null($channel_id)) + return redirect()->back()->with('error', 'Something went wrong, please assure you have setup your personal delivery channel correctly.'); + + if($this->subscribeToChannel($channel_id, $via, 'missing_refreshtoken')) + return redirect()->back()->with('success', 'You are going to be notified about missing refresh_tokens every time SeAT Group Sync runs.'); + + return redirect()->back()->with('error', 'Something went wrong, please assure you have setup your personal delivery channel correctly.'); + } + + public function unsubscribeDm($via) + { + $channel_id = $this->getPrivateChannel($via); + + if(is_null($channel_id)) + return redirect()->back()->with('error', 'Something went wrong, please assure you have setup your personal delivery channel correctly.'); + + if($this->unsubscribeFromChannel($channel_id, 'missing_refreshtoken')) + return redirect()->back()->with('success', 'You are no longer going to be notified about missing_refreshtoken events.'); + + return redirect()->back()->with('error', 'Something went wrong, please assure you have setup your personal delivery channel correctly.'); + } + + public function subscribeChannel() + { + + $via = (string) request('via'); + $channel_id = (string) request('channel_id'); + + if(is_null($channel_id) || is_null($channel_id)) + return abort(500); + + if($this->subscribeToChannel($channel_id, $via, 'missing_refreshtoken', true)) + return redirect()->back()->with('success', 'This channel is going to be notified about missing refresh_tokens every time SeAT Group Sync runs.'); + + return abort(500); + } + + public function unsubscribeChannel($channel) + { + $channel_id = $this->getChannelChannelId($channel, 'missing_refreshtoken'); + + if(is_null($channel_id)) + return abort(500); + + if($this->unsubscribeFromChannel($channel_id, 'missing_refreshtoken')) + return redirect()->back()->with('success', 'Channel will no longer receive missing_refreshtoken notifications.'); + + return abort(500); + } + + public function isSubscribed($view, $channel) + { + return $this->getSubscribtionStatus($channel, $view, 'missing_refreshtoken'); + } + + public function isDisabledButton($view, $channel) : bool + { + return $this->isDisabled($channel, $view, 'seatgroups.create'); + } + + public function isAvailable() : bool + { + return $this->hasPermission('seatgroups.create'); + } +} diff --git a/src/Http/Controllers/Notifications/SeatGroupErrorController.php b/src/Http/Controllers/Notifications/SeatGroupErrorController.php new file mode 100644 index 0000000..0f18a3c --- /dev/null +++ b/src/Http/Controllers/Notifications/SeatGroupErrorController.php @@ -0,0 +1,116 @@ +getPrivateChannel($via); + + if(is_null($channel_id)) + return redirect()->back()->with('error', 'Something went wrong, please assure you have setup your personal delivery channel correctly.'); + + if($this->subscribeToChannel($channel_id, $via, 'seatgroup_error')) + return redirect()->back()->with('success', 'You are going to be notified about sync error events from SeAT Groups.'); + + return redirect()->back()->with('error', 'Something went wrong, please assure you have setup your personal delivery channel correctly.'); + } + + public function unsubscribeDm($via) + { + $channel_id = $this->getPrivateChannel($via); + + if(is_null($channel_id)) + return redirect()->back()->with('error', 'Something went wrong, please assure you have setup your personal delivery channel correctly.'); + + if($this->unsubscribeFromChannel($channel_id, 'seatgroup_error')) + return redirect()->back()->with('success', 'You are no longer going to be notified about seatgroup_error events.'); + + return redirect()->back()->with('error', 'Something went wrong, please assure you have setup your personal delivery channel correctly.'); + } + + public function subscribeChannel() + { + + $via = (string) request('via'); + $channel_id = (string) request('channel_id'); + + if(is_null($channel_id) || is_null($channel_id)) + return abort(500); + + if($this->subscribeToChannel($channel_id, $via, 'seatgroup_error', true)) + return redirect()->back()->with('success', 'Channel will receive seatgroup_error notifications from now on.'); + + return abort(500); + } + + public function unsubscribeChannel($channel) + { + $channel_id = $this->getChannelChannelId($channel, 'seatgroup_error'); + + if(is_null($channel_id)) + return abort(500); + + if($this->unsubscribeFromChannel($channel_id, 'seatgroup_error')) + return redirect()->back()->with('success', 'Channel will no longer receive seatgroup_error notifications.'); + + return abort(500); + } + + public function isSubscribed($view, $channel) + { + return $this->getSubscribtionStatus($channel, $view, 'seatgroup_error'); + } + + public function isDisabledButton($view, $channel) : bool + { + return $this->isDisabled($channel, $view, 'seatgroups.create'); + } + + public function isAvailable() : bool + { + return $this->hasPermission('seatgroups.create'); + } +} diff --git a/src/Http/Controllers/Notifications/SeatGroupSyncController.php b/src/Http/Controllers/Notifications/SeatGroupSyncController.php new file mode 100644 index 0000000..ef932c6 --- /dev/null +++ b/src/Http/Controllers/Notifications/SeatGroupSyncController.php @@ -0,0 +1,93 @@ +getPrivateChannel($via); + + if(is_null($channel_id)) + return redirect()->back()->with('error', 'Something went wrong, please assure you have setup your personal delivery channel correctly.'); + + if($this->subscribeToChannel($channel_id, $via, 'seatgroup_sync')) + return redirect()->back()->with('success', 'You are going to be notified about sync events from SeAT Groups.'); + + return redirect()->back()->with('error', 'Something went wrong, please assure you have setup your personal delivery channel correctly.'); + } + + public function unsubscribeDm($via) + { + $channel_id = $this->getPrivateChannel($via); + + if(is_null($channel_id)) + return redirect()->back()->with('error', 'Something went wrong, please assure you have setup your personal delivery channel correctly.'); + + if($this->unsubscribeFromChannel($channel_id, 'seatgroup_sync')) + return redirect()->back()->with('success', 'You are no longer going to be notified about deleted seatgroup_sync events.'); + + return redirect()->back()->with('error', 'Something went wrong, please assure you have setup your personal delivery channel correctly.'); + } + + public function subscribeChannel() + { + + $via = (string) request('via'); + $channel_id = (string) request('channel_id'); + + if(is_null($channel_id) || is_null($channel_id)) + return abort(500); + + if($this->subscribeToChannel($channel_id, $via, 'seatgroup_sync', true)) + return redirect()->back()->with('success', 'Channel will receive seatgroup_sync notifications from now on.'); + + return abort(500); + } + + public function unsubscribeChannel($channel) + { + $channel_id = $this->getChannelChannelId($channel, 'seatgroup_sync'); + + if(is_null($channel_id)) + return abort(500); + + if($this->unsubscribeFromChannel($channel_id, 'seatgroup_sync')) + return redirect()->back()->with('success', 'Channel will no longer receive seatgroup_sync notifications.'); + + return abort(500); + } + + public function isSubscribed($view, $channel) + { + return $this->getSubscribtionStatus($channel, $view, 'seatgroup_sync'); + } + + public function isDisabledButton($view, $channel) : bool + { + return $this->isDisabled($channel, $view, 'seatgroups.create'); + } + + public function isAvailable() : bool + { + return $this->hasPermission('seatgroups.create'); + } +} diff --git a/src/Http/Controllers/SeatGroupNotificationController.php b/src/Http/Controllers/SeatGroupNotificationController.php deleted file mode 100644 index 2c763b9..0000000 --- a/src/Http/Controllers/SeatGroupNotificationController.php +++ /dev/null @@ -1,74 +0,0 @@ - $request->input('channel_id')], - ['via' => $request->input('via')] - ); - - return redirect()->back()->with('success', 'Channel will receive SeAT groups notifications from now on.'); - } - - public function unsubscribeChannel($via) - { - - SeatGroupNotification::where('via', $via) - ->delete(); - - return redirect()->back()->with('success', 'Channel will not receive SeAT groups notifications from this point on.'); - } - - public function isDisabledButton($channel) : bool - { - // return false if slack has not been setup - if($channel === 'slack') { - if(is_null(setting('herpaderp.seatnotifications.slack.credentials.token', true))) - return true; - } - - // return false if discord has not been setup - if($channel === 'discord') { - if(is_null(setting('herpaderp.seatnotifications.discord.credentials.bot_token', true))) - return true; - } - - return false; - } - - public function isSubscribed($via) : bool - { - return SeatGroupNotification::where('via', $via)->count() > 0 ? true : false; - } -} diff --git a/src/Http/routes.php b/src/Http/routes.php index bdaccab..add51c1 100644 --- a/src/Http/routes.php +++ b/src/Http/routes.php @@ -127,20 +127,84 @@ ]); }); - // Routes for SeatgroupsLogs + // Routes for Seatgroup Notifications Route::group([ + 'namespace' => 'Notifications', 'prefix' => 'notifications', 'middleware' => 'bouncer:seatgroups.create', ], function () { - Route::post('/subscribe', [ - 'as' => 'seatgroups.subscribe', - 'uses' => 'SeatGroupNotificationController@subscribeChannel', + // SeatGroupSync + Route::get('/seatgroup_sync/{via}/subscribe/private', [ + 'as' => 'seatnotifications.seatgroup_sync.subscribe.user', + 'uses' => 'SeatGroupSyncController@subscribeDm', + ]); + + Route::get('/seatgroup_sync/{via}/unsubscribe/private', [ + 'as' => 'seatnotifications.seatgroup_sync.unsubscribe.user', + 'uses' => 'SeatGroupSyncController@unsubscribeDm', + ]); + + // SeatGroupError + Route::get('/seatgroup_error/{via}/subscribe/private', [ + 'as' => 'seatnotifications.seatgroup_error.subscribe.user', + 'uses' => 'SeatGroupErrorController@subscribeDm', + ]); + + Route::get('/seatgroup_error/{via}/unsubscribe/private', [ + 'as' => 'seatnotifications.seatgroup_error.unsubscribe.user', + 'uses' => 'SeatGroupErrorController@unsubscribeDm', + ]); + + // SeatGroupMissingRefreshToken + Route::get('/missing_refreshtoken/{via}/subscribe/private', [ + 'as' => 'seatnotifications.missing_refreshtoken.subscribe.user', + 'uses' => 'MissingRefreshTokenController@subscribeDm', ]); - Route::get('/unsubscribe/{via}', [ - 'as' => 'seatgroups.unsubscribe', - 'uses' => 'SeatGroupNotificationController@unsubscribeChannel', + + Route::get('/missing_refreshtoken/{via}/unsubscribe/private', [ + 'as' => 'seatnotifications.missing_refreshtoken.unsubscribe.user', + 'uses' => 'MissingRefreshTokenController@unsubscribeDm', ]); + + Route::group([ + 'middleware' => ['bouncer:seatnotifications.configuration'], + ], function () { + + // SeatGroupSync + Route::post('/seatgroup_sync/channel', [ + 'as' => 'seatnotifications.seatgroup_sync.subscribe.channel', + 'uses' => 'SeatGroupSyncController@subscribeChannel', + ]); + + Route::get('/seatgroup_sync/{via}/unsubscribe', [ + 'as' => 'seatnotifications.seatgroup_sync.unsubscribe.channel', + 'uses' => 'SeatGroupSyncController@unsubscribeChannel', + ]); + + // SeatGroupError + Route::post('/seatgroup_error/channel', [ + 'as' => 'seatnotifications.seatgroup_error.subscribe.channel', + 'uses' => 'SeatGroupErrorController@subscribeChannel', + ]); + + Route::get('/seatgroup_error/{via}/unsubscribe', [ + 'as' => 'seatnotifications.seatgroup_error.unsubscribe.channel', + 'uses' => 'SeatGroupErrorController@unsubscribeChannel', + ]); + + // SeatGroupError + Route::post('/missing_refreshtoken/channel', [ + 'as' => 'seatnotifications.missing_refreshtoken.subscribe.channel', + 'uses' => 'MissingRefreshTokenController@subscribeChannel', + ]); + + Route::get('/missing_refreshtoken/{via}/unsubscribe', [ + 'as' => 'seatnotifications.missing_refreshtoken.unsubscribe.channel', + 'uses' => 'MissingRefreshTokenController@unsubscribeChannel', + ]); + }); + }); // TODO Cleanup the legacy routes from prior 1.1.0 diff --git a/src/Listeners/GroupSyncFailedNotification.php b/src/Listeners/GroupSyncFailedNotification.php index 43dd998..a8a919d 100644 --- a/src/Listeners/GroupSyncFailedNotification.php +++ b/src/Listeners/GroupSyncFailedNotification.php @@ -31,7 +31,11 @@ public function handle(GroupSyncFailed $event) if ($should_send){ - $recipients = SeatGroupNotification::all(); + $recipients = SeatGroupNotification::all() + ->filter(function ($recipient) { + return $recipient->shouldReceive('seatgroup_error'); + }); + $message = sprintf('An error occurred while syncing user group of %s (%s). Please check the logs.', $event->main_character->name, $event->group->users->map(function ($user) {return $user->name; })->implode(', ') diff --git a/src/Listeners/GroupSyncedNotification.php b/src/Listeners/GroupSyncedNotification.php index 378d422..d0e6e2f 100644 --- a/src/Listeners/GroupSyncedNotification.php +++ b/src/Listeners/GroupSyncedNotification.php @@ -9,8 +9,8 @@ namespace Herpaderpaldent\Seat\SeatGroups\Listeners; use Herpaderpaldent\Seat\SeatGroups\Events\GroupSynced; -use Herpaderpaldent\Seat\SeatGroups\Models\SeatGroupNotification; -use Herpaderpaldent\Seat\SeatGroups\Notifications\SeatGroupUpdateNotification; +use Herpaderpaldent\Seat\SeatGroups\Notifications\SeatGroupSyncNotification; +use Herpaderpaldent\Seat\SeatNotifications\Models\SeatNotificationRecipient; use Herpaderpaldent\Seat\SeatNotifications\Notifications\BaseNotification; use Illuminate\Support\Facades\Notification; @@ -36,9 +36,12 @@ public function handle(GroupSynced $event) if ($should_send){ - $recipients = SeatGroupNotification::all(); + $recipients = SeatNotificationRecipient::all() + ->filter(function ($recipient) { + return $recipient->shouldReceive('seatgroup_sync'); + }); - Notification::send($recipients, (new SeatGroupUpdateNotification($event->group, $event->sync))); + Notification::send($recipients, (new SeatGroupSyncNotification($event->group, $event->sync))); } } } diff --git a/src/Listeners/MissingRefreshTokenNotification.php b/src/Listeners/MissingRefreshTokenNotification.php index ce22e61..173e9e6 100644 --- a/src/Listeners/MissingRefreshTokenNotification.php +++ b/src/Listeners/MissingRefreshTokenNotification.php @@ -31,7 +31,10 @@ public function handle(MissingRefreshToken $event) if ($should_send){ - $recipients = SeatGroupNotification::all(); + $recipients = SeatGroupNotification::all() + ->filter(function ($recipient) { + return $recipient->shouldReceive('missing_refreshtoken'); + }); Notification::send($recipients, (new RefreshTokenNotification($event->user))); } diff --git a/src/Notifications/SeatGroupUpdateNotification.php b/src/Notifications/SeatGroupSyncNotification.php similarity index 92% rename from src/Notifications/SeatGroupUpdateNotification.php rename to src/Notifications/SeatGroupSyncNotification.php index dbe333c..45f1d79 100644 --- a/src/Notifications/SeatGroupUpdateNotification.php +++ b/src/Notifications/SeatGroupSyncNotification.php @@ -16,12 +16,12 @@ use Seat\Web\Models\Acl\Role; use Seat\Web\Models\Group; -class SeatGroupUpdateNotification extends BaseNotification +class SeatGroupSyncNotification extends BaseNotification { /** * @var array */ - protected $tags = ['seat_group', 'update']; + protected $tags = ['seat_group', 'sync']; protected $image; @@ -52,6 +52,8 @@ public function __construct(Group $group, array $sync) if (! empty($sync['detached'])) $this->detached_roles = Role::whereIn('id', $sync['detached'])->pluck('title')->implode(', '); + + array_push($this->tags, 'group_id:' . $group->id); } /** @@ -65,16 +67,12 @@ public function via($notifiable) switch($notifiable->via) { case 'discord': - $this->tags = array_merge($this->tags, [ - 'discord', - ]); + array_push($this->tags, 'discord'); return [DiscordChannel::class]; break; case 'slack': - $this->tags = array_merge($this->tags, [ - 'slack', - ]); + array_push($this->tags, 'slack'); return [SlackChannel::class]; break; diff --git a/src/config/seatgroups.config.php b/src/config/seatgroups.config.php index 1bc46bc..4f1c64c 100644 --- a/src/config/seatgroups.config.php +++ b/src/config/seatgroups.config.php @@ -1,12 +1,30 @@ '1.6.4', + 'version' => '1.6.5', ]; //TODO: Update Version diff --git a/src/config/seatgroups.services.php b/src/config/seatgroups.services.php index c388942..b622106 100644 --- a/src/config/seatgroups.services.php +++ b/src/config/seatgroups.services.php @@ -3,7 +3,9 @@ return [ 'seat-notification' => [ - 'seatgroup' => Herpaderpaldent\Seat\SeatGroups\Http\Controllers\SeatGroupNotificationController::class, + 'seatgroup_sync' => Herpaderpaldent\Seat\SeatGroups\Http\Controllers\Notifications\SeatGroupSyncController::class, + 'seatgroup_error' => Herpaderpaldent\Seat\SeatGroups\Http\Controllers\Notifications\SeatGroupErrorController::class, + 'missing_refreshtoken' => Herpaderpaldent\Seat\SeatGroups\Http\Controllers\Notifications\MissingRefreshTokenController::class, ], ]; diff --git a/src/config/seatgroups.sidebar.php b/src/config/seatgroups.sidebar.php index a318503..215725b 100644 --- a/src/config/seatgroups.sidebar.php +++ b/src/config/seatgroups.sidebar.php @@ -1,13 +1,7 @@ [ + 'seatgroups' => [ 'name' => 'SeAT Groups', 'icon' => 'fa-group', 'route_segment' => 'seatgroups', diff --git a/src/database/migrations/2019_02_05_205150_delete_seat_group_notification_table.php b/src/database/migrations/2019_02_05_205150_delete_seat_group_notification_table.php new file mode 100644 index 0000000..3f14c3c --- /dev/null +++ b/src/database/migrations/2019_02_05_205150_delete_seat_group_notification_table.php @@ -0,0 +1,57 @@ +string('channel_id'); + $table->string('via'); + $table->timestamps(); + + $table->primary('channel_id', 'herpaderp_seatgroup_notification_primary'); + }); + } +} diff --git a/src/resources/views/notification/channel.blade.php b/src/resources/views/notification/channel.blade.php deleted file mode 100644 index 275ae68..0000000 --- a/src/resources/views/notification/channel.blade.php +++ /dev/null @@ -1,135 +0,0 @@ -@inject('SeatGroupNotificationController', 'Herpaderpaldent\Seat\SeatGroups\Http\Controllers\SeatGroupNotificationController') - -@if( $SeatGroupNotificationController->isDisabledButton('discord') ) - - Discord - -@elseif(! $SeatGroupNotificationController->isSubscribed('discord') ) - - Discord - -@else - - - Discord - -@endif - -@if( $SeatGroupNotificationController->isDisabledButton('slack') ) - - Slack - -@elseif(! $SeatGroupNotificationController->isSubscribed('slack') ) - - Slack - -@else - - - Slack - -@endif - - -
Receive a notification every time SeAT Group attempts to sync roles and detects a missing Refresh Token.
\ No newline at end of file diff --git a/src/resources/views/notification/missing_refreshtoken/partials/discord-channel-modal.blade.php b/src/resources/views/notification/missing_refreshtoken/partials/discord-channel-modal.blade.php new file mode 100644 index 0000000..10af886 --- /dev/null +++ b/src/resources/views/notification/missing_refreshtoken/partials/discord-channel-modal.blade.php @@ -0,0 +1,50 @@ +Receive an update whenever a group receives or loses a role.
\ No newline at end of file diff --git a/src/resources/views/notification/private.blade.php b/src/resources/views/notification/private.blade.php deleted file mode 100644 index a80e620..0000000 --- a/src/resources/views/notification/private.blade.php +++ /dev/null @@ -1,2 +0,0 @@ -not supported - diff --git a/src/resources/views/notification/seatgroup_error/channel.blade.php b/src/resources/views/notification/seatgroup_error/channel.blade.php new file mode 100644 index 0000000..6bef6d0 --- /dev/null +++ b/src/resources/views/notification/seatgroup_error/channel.blade.php @@ -0,0 +1,46 @@ +@inject('SeatGroupErrorController', 'Herpaderpaldent\Seat\SeatGroups\Http\Controllers\Notifications\SeatGroupErrorController') + +@if($SeatGroupErrorController->isAvailable()) + + @if( $SeatGroupErrorController->isDisabledButton('channel', 'discord') ) + + Discord + + @elseif(! $SeatGroupErrorController->isSubscribed('channel', 'discord')) + + Discord + + @include('seatgroups::notification.seatgroup_error.partials.discord-channel-modal') + @else + + + Discord + + @endif + + @if( $SeatGroupErrorController->isDisabledButton('channel', 'slack')) + + Slack + + @elseif(! $SeatGroupErrorController->isSubscribed('channel', 'slack')) + + Slack + + @include('seatgroups::notification.seatgroup_error.partials.slack-channel-modal') + @else + + + Slack + + @endif + +@else + + @include('seatnotifications::seatnotifications.partials.missing-permissions') + +@endif + diff --git a/src/resources/views/notification/seatgroup_error/notification.blade.php b/src/resources/views/notification/seatgroup_error/notification.blade.php new file mode 100644 index 0000000..8f171a3 --- /dev/null +++ b/src/resources/views/notification/seatgroup_error/notification.blade.php @@ -0,0 +1,2 @@ +SeAT Group Error +Receive a notification about error during SeAT Group Syncs.
\ No newline at end of file diff --git a/src/resources/views/notification/seatgroup_error/partials/discord-channel-modal.blade.php b/src/resources/views/notification/seatgroup_error/partials/discord-channel-modal.blade.php new file mode 100644 index 0000000..6acb4b4 --- /dev/null +++ b/src/resources/views/notification/seatgroup_error/partials/discord-channel-modal.blade.php @@ -0,0 +1,50 @@ +Receive a notification about attached or detached roles to user groups.
\ No newline at end of file diff --git a/src/resources/views/notification/seatgroup_sync/partials/discord-channel-modal.blade.php b/src/resources/views/notification/seatgroup_sync/partials/discord-channel-modal.blade.php new file mode 100644 index 0000000..04508bc --- /dev/null +++ b/src/resources/views/notification/seatgroup_sync/partials/discord-channel-modal.blade.php @@ -0,0 +1,50 @@ +