From 8b16527fda0ce26b3026a308e4c26c9e2ba9f6cc Mon Sep 17 00:00:00 2001 From: Herpaderp Aldent Date: Sun, 31 Mar 2019 14:23:42 +0200 Subject: [PATCH] Release/1.7.0 (#100) * Feature/seat notifications/2.0.0 (#93) * Introduce SeatGroupSyncNotification for SeatNotification 2.0 * Remove unneeded blade resources * create abstract class * add group class * remove php storm creation comment * Missing Refresh Token for seat-notification 2.0 * SeAT Group Application Notification for SeAT-Notifications 2.0 * SeAT Group Error Notification * Added permissions to permission check * remove unneeded routes * Changelog and version bump * Apply fixes from StyleCI * Stopping the propagation of an event in case no one subscribed for event reference: https://laravel.com/docs/5.5/events#defining-listeners * Do not send the same MissingRefreshTokenNotification twice between 4hrs * use qu1ckkk feedback and use sha1 instead of md5 * Apply fixes from StyleCI (#94) * correctly assert recipients group instead of the applicant ones. * Implement `dontSend()` for Sync, Error * Apply fixes from StyleCI (#97) * Develop (#98) * Apply fixes from StyleCI (#94) (#95) * Release/1.7.0 (#96) * Apply fixes from StyleCI (#94) * correctly assert recipients group instead of the applicant ones. * Implement `dontSend()` for Sync, Error * Apply fixes from StyleCI (#97) * prevent seat-group spamming and resolves: https://github.com/herpaderpaldent/seat-groups/issues/91 * Add fix changelog note --- CHANGELOG.md | 11 ++ composer.json | 2 +- src/Http/routes.php | 91 ---------- .../GroupApplicationNotification.php | 39 +++-- src/Listeners/GroupSyncFailedNotification.php | 34 ++-- src/Listeners/GroupSyncedNotification.php | 51 ++++-- .../MissingRefreshTokenNotification.php | 26 ++- ...bstractMissingRefreshTokenNotification.php | 154 +++++++++++++++++ ...DiscordMissingRefreshTokenNotification.php | 86 ++++++++++ .../SlackMissingRefreshTokenNotification.php | 87 ++++++++++ .../MissingRefreshTokenNotification.php | 149 ---------------- ...stractSeatGroupApplicationNotification.php | 162 ++++++++++++++++++ ...iscordSeatGroupApplicationNotification.php | 79 +++++++++ .../SlackSeatGroupApplicationNotification.php | 82 +++++++++ .../SeatGroupApplicationNotification.php | 160 ----------------- .../AbstractSeatGroupErrorNotification.php | 149 ++++++++++++++++ .../DiscordSeatGroupErrorNotification.php | 81 +++++++++ .../SlackSeatGroupErrorNotification.php | 79 +++++++++ .../SeatGroupErrorNotification.php | 130 -------------- .../AbstractSeatGroupSyncNotification.php | 162 ++++++++++++++++++ .../DiscordSeatGroupSyncNotification.php | 88 ++++++++++ .../SlackSeatGroupSyncNotification.php | 91 ++++++++++ .../SeatGroupSyncNotification.php | 161 ----------------- src/config/seatgroups.config.php | 2 +- src/config/seatgroups.permission.php | 4 + src/config/seatgroups.services.php | 20 ++- .../missing_refreshtoken/channel.blade.php | 46 ----- .../notification.blade.php | 2 - .../partials/discord-channel-modal.blade.php | 50 ------ .../partials/slack-channel-modal.blade.php | 53 ------ .../missing_refreshtoken/private.blade.php | 43 ----- .../seatgroup_application/channel.blade.php | 4 - .../notification.blade.php | 2 - .../seatgroup_application/private.blade.php | 43 ----- .../seatgroup_error/channel.blade.php | 46 ----- .../seatgroup_error/notification.blade.php | 2 - .../partials/discord-channel-modal.blade.php | 50 ------ .../partials/slack-channel-modal.blade.php | 53 ------ .../seatgroup_error/private.blade.php | 43 ----- .../seatgroup_sync/channel.blade.php | 46 ----- .../seatgroup_sync/notification.blade.php | 2 - .../partials/discord-channel-modal.blade.php | 50 ------ .../partials/slack-channel-modal.blade.php | 53 ------ .../seatgroup_sync/private.blade.php | 43 ----- 44 files changed, 1444 insertions(+), 1367 deletions(-) create mode 100644 src/Notifications/MissingRefreshToken/AbstractMissingRefreshTokenNotification.php create mode 100644 src/Notifications/MissingRefreshToken/DiscordMissingRefreshTokenNotification.php create mode 100644 src/Notifications/MissingRefreshToken/SlackMissingRefreshTokenNotification.php delete mode 100644 src/Notifications/MissingRefreshTokenNotification.php create mode 100644 src/Notifications/SeatGroupApplication/AbstractSeatGroupApplicationNotification.php create mode 100644 src/Notifications/SeatGroupApplication/DiscordSeatGroupApplicationNotification.php create mode 100644 src/Notifications/SeatGroupApplication/SlackSeatGroupApplicationNotification.php delete mode 100644 src/Notifications/SeatGroupApplicationNotification.php create mode 100644 src/Notifications/SeatGroupError/AbstractSeatGroupErrorNotification.php create mode 100644 src/Notifications/SeatGroupError/DiscordSeatGroupErrorNotification.php create mode 100644 src/Notifications/SeatGroupError/SlackSeatGroupErrorNotification.php delete mode 100644 src/Notifications/SeatGroupErrorNotification.php create mode 100644 src/Notifications/SeatGroupSync/AbstractSeatGroupSyncNotification.php create mode 100644 src/Notifications/SeatGroupSync/DiscordSeatGroupSyncNotification.php create mode 100644 src/Notifications/SeatGroupSync/SlackSeatGroupSyncNotification.php delete mode 100644 src/Notifications/SeatGroupSyncNotification.php delete mode 100644 src/resources/views/notification/missing_refreshtoken/channel.blade.php delete mode 100644 src/resources/views/notification/missing_refreshtoken/notification.blade.php delete mode 100644 src/resources/views/notification/missing_refreshtoken/partials/discord-channel-modal.blade.php delete mode 100644 src/resources/views/notification/missing_refreshtoken/partials/slack-channel-modal.blade.php delete mode 100644 src/resources/views/notification/missing_refreshtoken/private.blade.php delete mode 100644 src/resources/views/notification/seatgroup_application/channel.blade.php delete mode 100644 src/resources/views/notification/seatgroup_application/notification.blade.php delete mode 100644 src/resources/views/notification/seatgroup_application/private.blade.php delete mode 100644 src/resources/views/notification/seatgroup_error/channel.blade.php delete mode 100644 src/resources/views/notification/seatgroup_error/notification.blade.php delete mode 100644 src/resources/views/notification/seatgroup_error/partials/discord-channel-modal.blade.php delete mode 100644 src/resources/views/notification/seatgroup_error/partials/slack-channel-modal.blade.php delete mode 100644 src/resources/views/notification/seatgroup_error/private.blade.php delete mode 100644 src/resources/views/notification/seatgroup_sync/channel.blade.php delete mode 100644 src/resources/views/notification/seatgroup_sync/notification.blade.php delete mode 100644 src/resources/views/notification/seatgroup_sync/partials/discord-channel-modal.blade.php delete mode 100644 src/resources/views/notification/seatgroup_sync/partials/slack-channel-modal.blade.php delete mode 100644 src/resources/views/notification/seatgroup_sync/private.blade.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 848089a..8febe23 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,14 @@ +# Version 1.7.0 +This version allows the usage of seat-notifications 2.0. Be aware your subscriptions have been reset and you must resubscribe. + +New features: +* Identical Missing Refresh Token SeAT-Groups notifications will not be resend within 4hrs period. +* Identical Sync SeAT-Groups notifications will not be resend within 4hrs period. +* Identical Error SeAT-Groups notifications will not be resend within 4hrs period. + +Fixes: +* SeAT-Group Application notification were previously not send out correctly to all groups administrators + # Version 1.6.9 Small improvement based on community feedback: diff --git a/composer.json b/composer.json index b76fd1d..bc60e17 100644 --- a/composer.json +++ b/composer.json @@ -13,7 +13,7 @@ "phpunit/phpunit": "~6.0" }, "conflict": { - "herpaderpaldent/seat-notifications": "^2.0.0" + "herpaderpaldent/seat-notifications": "<2.0.0" }, "license": "MIT", "authors": [ diff --git a/src/Http/routes.php b/src/Http/routes.php index c4bc5b2..e4ba954 100644 --- a/src/Http/routes.php +++ b/src/Http/routes.php @@ -151,97 +151,6 @@ ]); }); - // Routes for Seatgroup Notifications - Route::group([ - 'namespace' => 'Notifications', - 'prefix' => 'notifications', - 'middleware' => 'bouncer:seatgroups.create', - ], function () { - - // 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('/missing_refreshtoken/{via}/unsubscribe/private', [ - 'as' => 'seatnotifications.missing_refreshtoken.unsubscribe.user', - 'uses' => 'MissingRefreshTokenController@unsubscribeDm', - ]); - - // SeatGroupApplication - Route::get('/seatgroup_application/{via}/subscribe/private', [ - 'as' => 'seatnotifications.seatgroup_application.subscribe.user', - 'uses' => 'SeatGroupApplicationController@subscribeDm', - ]); - - Route::get('/seatgroup_application/{via}/unsubscribe/private', [ - 'as' => 'seatnotifications.seatgroup_application.unsubscribe.user', - 'uses' => 'SeatGroupApplicationController@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 Route::group([ 'middleware' => ['web', 'auth'], diff --git a/src/Listeners/GroupApplicationNotification.php b/src/Listeners/GroupApplicationNotification.php index 52cfafe..48ccb8f 100644 --- a/src/Listeners/GroupApplicationNotification.php +++ b/src/Listeners/GroupApplicationNotification.php @@ -26,10 +26,11 @@ namespace Herpaderpaldent\Seat\SeatGroups\Listeners; use Herpaderpaldent\Seat\SeatGroups\Events\GroupApplication; -use Herpaderpaldent\Seat\SeatGroups\Notifications\SeatGroupApplicationNotification; -use Herpaderpaldent\Seat\SeatNotifications\Models\SeatNotificationRecipient; -use Herpaderpaldent\Seat\SeatNotifications\Notifications\BaseNotification; +use Herpaderpaldent\Seat\SeatGroups\Notifications\SeatGroupApplication\AbstractSeatGroupApplicationNotification; +use Herpaderpaldent\Seat\SeatNotifications\Models\NotificationRecipient; +use Herpaderpaldent\Seat\SeatNotifications\SeatNotificationsServiceProvider; use Illuminate\Support\Facades\Notification; +use Seat\Web\Models\Group; class GroupApplicationNotification { @@ -42,19 +43,26 @@ public function handle(GroupApplication $event) { $should_send = false; - if (class_exists(BaseNotification::class)) + if (class_exists(SeatNotificationsServiceProvider::class)) $should_send = true; if ($should_send){ - $recipients = SeatNotificationRecipient::all() + $recipients = NotificationRecipient::all() ->filter(function ($recipient) { - return $recipient->shouldReceive('seatgroup_application'); + return $recipient->shouldReceive(AbstractSeatGroupApplicationNotification::class); + }) + ->filter(function ($recipient) { + + //Filter public subscription as only private subscription is allowed + return ! empty($recipient->group_id); }) ->filter(function ($recipient) use ($event) { + $recipient_group = Group::find($recipient->group_id); + // Check if recipient is superuser - foreach ($event->group->roles as $role) { + foreach ($recipient_group->roles as $role) { foreach ($role->permissions as $permission) { if ($permission->title === 'superuser') return true; @@ -62,11 +70,22 @@ public function handle(GroupApplication $event) } // Check if recipient is manager - return $event->seatgroup->isManager($recipient->notification_user->group); + return $event->seatgroup->isManager($recipient_group); }); - if($recipients->isNotEmpty()) - Notification::send($recipients, (new SeatGroupApplicationNotification($event->seatgroup, $event->group))); + if($recipients->isEmpty()){ + logger()->debug('No Receiver found for ' . AbstractSeatGroupApplicationNotification::getTitle() . ' Notification. This job is going to be deleted.'); + + return false; + } + + $recipients->groupBy('driver') + ->each(function ($grouped_recipients) use ($event) { + $driver = (string) $grouped_recipients->first()->driver; + $notification_class = AbstractSeatGroupApplicationNotification::getDriverImplementation($driver); + + Notification::send($grouped_recipients, (new $notification_class($event->seatgroup, $event->group))); + }); } } } diff --git a/src/Listeners/GroupSyncFailedNotification.php b/src/Listeners/GroupSyncFailedNotification.php index 0e87632..0b72a51 100644 --- a/src/Listeners/GroupSyncFailedNotification.php +++ b/src/Listeners/GroupSyncFailedNotification.php @@ -26,9 +26,9 @@ namespace Herpaderpaldent\Seat\SeatGroups\Listeners; use Herpaderpaldent\Seat\SeatGroups\Events\GroupSyncFailed; -use Herpaderpaldent\Seat\SeatGroups\Notifications\SeatGroupErrorNotification; -use Herpaderpaldent\Seat\SeatNotifications\Models\SeatNotificationRecipient; -use Herpaderpaldent\Seat\SeatNotifications\Notifications\BaseNotification; +use Herpaderpaldent\Seat\SeatGroups\Notifications\SeatGroupError\AbstractSeatGroupErrorNotification; +use Herpaderpaldent\Seat\SeatNotifications\Models\NotificationRecipient; +use Herpaderpaldent\Seat\SeatNotifications\SeatNotificationsServiceProvider; use Illuminate\Support\Facades\Notification; use Seat\Web\Models\User; @@ -43,22 +43,34 @@ public function handle(GroupSyncFailed $event) { $should_send = false; - if (class_exists(BaseNotification::class)) + if (class_exists(SeatNotificationsServiceProvider::class)) $should_send = true; if ($should_send){ - $recipients = SeatNotificationRecipient::all() + $recipients = NotificationRecipient::all() ->filter(function ($recipient) { - return $recipient->shouldReceive('seatgroup_error'); + return $recipient->shouldReceive(AbstractSeatGroupErrorNotification::class); }); - $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(', ') - ); + if($recipients->isEmpty()){ + logger()->debug('No Receiver found for ' . AbstractSeatGroupErrorNotification::getTitle() . ' Notification. This job is going to be deleted.'); - Notification::send($recipients, (new SeatGroupErrorNotification(User::find($event->main_character->character_id), $message))); + return false; + } + + $recipients->groupBy('driver') + ->each(function ($grouped_recipients) use ($event) { + $driver = (string) $grouped_recipients->first()->driver; + $notification_class = AbstractSeatGroupErrorNotification::getDriverImplementation($driver); + + $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(', ') + ); + + Notification::send($grouped_recipients, (new $notification_class(User::find($event->main_character->character_id), $message))); + }); } } } diff --git a/src/Listeners/GroupSyncedNotification.php b/src/Listeners/GroupSyncedNotification.php index d0e6e2f..937fa68 100644 --- a/src/Listeners/GroupSyncedNotification.php +++ b/src/Listeners/GroupSyncedNotification.php @@ -1,17 +1,34 @@ sync['detached'])) $should_send = true; - if (! class_exists(BaseNotification::class)) + if (! class_exists(SeatNotificationsServiceProvider::class)) $should_send = false; if ($should_send){ - $recipients = SeatNotificationRecipient::all() + $recipients = NotificationRecipient::all() ->filter(function ($recipient) { - return $recipient->shouldReceive('seatgroup_sync'); + return $recipient->shouldReceive(AbstractSeatGroupSyncNotification::class); }); - Notification::send($recipients, (new SeatGroupSyncNotification($event->group, $event->sync))); + if($recipients->isEmpty()){ + logger()->debug('No Receiver found for ' . AbstractSeatGroupSyncNotification::getTitle() . ' Notification. This job is going to be deleted.'); + + return false; + } + + $recipients->groupBy('driver') + ->each(function ($grouped_recipients) use ($event) { + $driver = (string) $grouped_recipients->first()->driver; + $notification_class = AbstractSeatGroupSyncNotification::getDriverImplementation($driver); + + Notification::send($grouped_recipients, (new $notification_class($event->group, $event->sync))); + }); } } } diff --git a/src/Listeners/MissingRefreshTokenNotification.php b/src/Listeners/MissingRefreshTokenNotification.php index 9269145..c4ef850 100644 --- a/src/Listeners/MissingRefreshTokenNotification.php +++ b/src/Listeners/MissingRefreshTokenNotification.php @@ -33,9 +33,9 @@ namespace Herpaderpaldent\Seat\SeatGroups\Listeners; use Herpaderpaldent\Seat\SeatGroups\Events\MissingRefreshToken; -use Herpaderpaldent\Seat\SeatGroups\Notifications\MissingRefreshTokenNotification as RefreshTokenNotification; -use Herpaderpaldent\Seat\SeatNotifications\Models\SeatNotificationRecipient; -use Herpaderpaldent\Seat\SeatNotifications\Notifications\BaseNotification; +use Herpaderpaldent\Seat\SeatGroups\Notifications\MissingRefreshToken\AbstractMissingRefreshTokenNotification; +use Herpaderpaldent\Seat\SeatNotifications\Models\NotificationRecipient; +use Herpaderpaldent\Seat\SeatNotifications\SeatNotificationsServiceProvider; use Illuminate\Support\Facades\Notification; class MissingRefreshTokenNotification @@ -50,17 +50,29 @@ public function handle(MissingRefreshToken $event) $should_send = false; logger()->debug('notificationListener'); - if (class_exists(BaseNotification::class)) + if (class_exists(SeatNotificationsServiceProvider::class)) $should_send = true; if ($should_send){ - $recipients = SeatNotificationRecipient::all() + $recipients = NotificationRecipient::all() ->filter(function ($recipient) { - return $recipient->shouldReceive('missing_refreshtoken'); + return $recipient->shouldReceive(AbstractMissingRefreshTokenNotification::class); }); - Notification::send($recipients, (new RefreshTokenNotification($event->user))); + if($recipients->isEmpty()){ + logger()->debug('No Receiver found for ' . AbstractMissingRefreshTokenNotification::getTitle() . ' Notification. This job is going to be deleted.'); + + return false; + } + + $recipients->groupBy('driver') + ->each(function ($grouped_recipients) use ($event) { + $driver = (string) $grouped_recipients->first()->driver; + $notification_class = AbstractMissingRefreshTokenNotification::getDriverImplementation($driver); + + Notification::send($grouped_recipients, (new $notification_class($event->user))); + }); } } } diff --git a/src/Notifications/MissingRefreshToken/AbstractMissingRefreshTokenNotification.php b/src/Notifications/MissingRefreshToken/AbstractMissingRefreshTokenNotification.php new file mode 100644 index 0000000..9aae47d --- /dev/null +++ b/src/Notifications/MissingRefreshToken/AbstractMissingRefreshTokenNotification.php @@ -0,0 +1,154 @@ +user = $user; + $this->image = 'https://imageserver.eveonline.com/Character/' . $user->id . '_128.jpg'; + $this->url = route('configuration.users.edit', ['user_id' => $user->id]); + $this->main_character = $this->getMainCharacter($user->group)->name; + $this->group = $user->group; + } + + /** + * Return a title for the notification which will be displayed in UI notification list. + * @return string + */ + public static function getTitle(): string + { + return 'SeAT Group - Missing Refresh Token'; + } + + /** + * Return a description for the notification which will be displayed in UI notification list. + * @return string + */ + public static function getDescription(): string + { + return 'Receive a notification every time SeAT Group attempts to sync roles and detects a missing Refresh Token.'; + } + + /** + * Determine if a notification can target public channel (forum category, chat, etc...). + * @return bool + */ + public static function isPublic(): bool + { + return true; + } + + /** + * Determine if a notification can target personal channel (private message, e-mail, etc...). + * @return bool + */ + public static function isPersonal(): bool + { + return true; + } + + /** + * Determine the permission needed to represent driver buttons. + * @return string + */ + public static function getPermission(): string + { + return 'seatgroups.missing_refresh_token_notification'; + } + + /** + * @param $notifiable + * @return mixed + */ + abstract public function via($notifiable); + + /** + * @param $notifiable + * + * @return bool + * @throws \Exception + */ + public function dontSend($notifiable) :bool + { + $value = collect([ + 'recipient' => $notifiable->driver_id, + 'notification' => get_called_class(), + 'content' => get_object_vars($this), + ])->toJson(); + + $key = sha1($value); + + if (empty(cache($key))) { + cache([$key => $value], now()->addHours(4)); + + return false; + } + + return true; + } +} diff --git a/src/Notifications/MissingRefreshToken/DiscordMissingRefreshTokenNotification.php b/src/Notifications/MissingRefreshToken/DiscordMissingRefreshTokenNotification.php new file mode 100644 index 0000000..10e499c --- /dev/null +++ b/src/Notifications/MissingRefreshToken/DiscordMissingRefreshTokenNotification.php @@ -0,0 +1,86 @@ +dontSend($notifiable)) + return []; + + array_push($this->tags, is_null($notifiable->group_id) ? 'to channel' : 'private to: ' . $this->getMainCharacter(Group::find($notifiable->group_id))->name); + + return [DiscordChannel::class]; + } + + /** + * @param $notifiable + * @return DiscordMessage + */ + public function toDiscord($notifiable) + { + $message = sprintf('The RefreshToken of [%s](%s) is missing. ' + . 'Ask the owner of this user group to login again with this user, in order to provide a new RefreshToken. ' + . 'This user group will lose all potentially gained roles through this character.', + $this->user->name, + $this->url + ); + + return (new DiscordMessage) + ->embed(function ($embed) use ($message) { + + $embed->title('** Error **') + ->thumbnail($this->image) + ->color(self::DANGER_COLOR) + ->field('Missing Refresh Token', $message, false) + ->field('Main character', $this->main_character, true) + ->field('User group', $this->group->users->map(function ($user) {return $user->name; })->implode(', '), true); + }); + } +} diff --git a/src/Notifications/MissingRefreshToken/SlackMissingRefreshTokenNotification.php b/src/Notifications/MissingRefreshToken/SlackMissingRefreshTokenNotification.php new file mode 100644 index 0000000..2060395 --- /dev/null +++ b/src/Notifications/MissingRefreshToken/SlackMissingRefreshTokenNotification.php @@ -0,0 +1,87 @@ +dontSend($notifiable)) + return []; + + array_push($this->tags, is_null($notifiable->group_id) ? 'to channel' : 'private to: ' . $this->getMainCharacter(Group::find($notifiable->group_id))->name); + + return [SlackChannel::class]; + } + + /** + * @param $notifiable + * + * @return \Herpaderpaldent\Seat\SeatNotifications\Channels\Slack\SlackMessage + */ + public function toSlack($notifiable) + { + $message = sprintf('The RefreshToken of %s in user group of %s (%s) is missing. ' + . 'Ask the owner of this user group to login again with this user, in order to provide a new RefreshToken. ' + . 'This user group will lose all potentially gained roles through this character.', + $this->user->name, + $this->main_character, + $this->group->users->map(function ($user) {return $user->name; }) + ->implode(', ') + ); + + return (new SlackMessage) + ->warning() + ->attachment(function ($attachment) use ($message) { + $attachment + ->title('Error', $this->url) + ->thumb($this->image) + ->color(self::DANGER_COLOR) + ->content($message); + }); + } +} diff --git a/src/Notifications/MissingRefreshTokenNotification.php b/src/Notifications/MissingRefreshTokenNotification.php deleted file mode 100644 index 2b666d7..0000000 --- a/src/Notifications/MissingRefreshTokenNotification.php +++ /dev/null @@ -1,149 +0,0 @@ -user = $user; - $this->image = 'https://imageserver.eveonline.com/Character/' . $user->id . '_128.jpg'; - $this->url = route('configuration.users.edit', ['user_id' => $user->id]); - $this->main_character = $this->getMainCharacter($user->group)->name; - $this->group = $user->group; - } - - /** - * Get the notification's delivery channels. - * - * @param mixed $notifiable - * @return array - */ - public function via($notifiable) - { - - switch($notifiable->notification_channel) { - case 'discord': - $this->tags = array_merge($this->tags, [ - 'discord', - ]); - - return [DiscordChannel::class]; - break; - case 'slack': - $this->tags = array_merge($this->tags, [ - 'slack', - ]); - - return [SlackChannel::class]; - break; - default: - return ['']; - } - } - - public function toDiscord($notifiable) - { - $message = sprintf('The RefreshToken of [%s](%s) is missing. ' - . 'Ask the owner of this user group to login again with this user, in order to provide a new RefreshToken. ' - . 'This user group will lose all potentially gained roles through this character.', - $this->user->name, - $this->url - ); - - return (new DiscordMessage) - ->embed(function ($embed) use ($message) { - - $embed->title('** Error **') - ->thumbnail($this->image) - ->color('12727073') - ->field('Missing Refresh Token', $message, false) - ->field('Main character', $this->main_character, true) - ->field('User group', $this->group->users->map(function ($user) {return $user->name; })->implode(', '), true); - }); - } - - /** - * @param $notifiable - * - * @return \Herpaderpaldent\Seat\SeatNotifications\Channels\Slack\SlackMessage - */ - public function toSlack($notifiable) - { - $message = sprintf('The RefreshToken of %s in user group of %s (%s) is missing. ' - . 'Ask the owner of this user group to login again with this user, in order to provide a new RefreshToken. ' - . 'This user group will lose all potentially gained roles through this character.', - $this->user->name, - $this->main_character, - $this->group->users->map(function ($user) {return $user->name; }) - ->implode(', ') - ); - - return (new SlackMessage) - ->warning() - ->attachment(function ($attachment) use ($message) { - $attachment - ->title('Error', $this->url) - ->thumb($this->image) - ->color('C23321') - ->content($message); - }); - } -} diff --git a/src/Notifications/SeatGroupApplication/AbstractSeatGroupApplicationNotification.php b/src/Notifications/SeatGroupApplication/AbstractSeatGroupApplicationNotification.php new file mode 100644 index 0000000..2431880 --- /dev/null +++ b/src/Notifications/SeatGroupApplication/AbstractSeatGroupApplicationNotification.php @@ -0,0 +1,162 @@ +group = $group; + $this->seatgroup = $seatgroup; + + $this->main_character = $this->getMainCharacter($group); + $this->image = 'https://imageserver.eveonline.com/Character/' . $this->main_character->character_id . '_128.jpg'; + $this->url = route('seatgroups.index') . '#managed_group'; + + $this->seatgroup_string = (string) $this->seatgroup->name; + $this->usergroup_string = (string) $this->group->users->map(function ($user) {return $user->name; })->implode(', '); + + $applications_helper = $this->seatgroup + ->waitlist + ->filter(function ($group) { + return $group->id !== $this->group->id; + }) + ->map(function ($group) { + return $this->getMainCharacter($group)->name; + }); + + $this->pending_applications = (string) $applications_helper->isNotEmpty() ? $applications_helper->implode(', ') : 'none'; + } + + /** + * Return a title for the notification which will be displayed in UI notification list. + * @return string + */ + public static function getTitle(): string + { + return 'SeAT Group Applications'; + } + + /** + * Return a description for the notification which will be displayed in UI notification list. + * @return string + */ + public static function getDescription(): string + { + return 'Receive a notification about new SeAT Group candidates which are on the waitlist of a SeAT group you are managing.'; + } + + /** + * Determine if a notification can target public channel (forum category, chat, etc...). + * @return bool + */ + public static function isPublic(): bool + { + return false; + } + + /** + * Determine if a notification can target personal channel (private message, e-mail, etc...). + * @return bool + */ + public static function isPersonal(): bool + { + return true; + } + + /** + * Determine the permission needed to represent driver buttons. + * @return string + */ + public static function getPermission(): string + { + return 'seatgroups.group_application_notification'; + } + + /** + * @param $notifiable + * @return mixed + */ + abstract public function via($notifiable); +} diff --git a/src/Notifications/SeatGroupApplication/DiscordSeatGroupApplicationNotification.php b/src/Notifications/SeatGroupApplication/DiscordSeatGroupApplicationNotification.php new file mode 100644 index 0000000..e41db8f --- /dev/null +++ b/src/Notifications/SeatGroupApplication/DiscordSeatGroupApplicationNotification.php @@ -0,0 +1,79 @@ +tags, is_null($notifiable->group_id) ? 'to channel' : 'private to: ' . $this->getMainCharacter(Group::find($notifiable->group_id))->name); + + return [DiscordChannel::class]; + } + + /** + * @param $notifiable + * + * @return mixed + */ + public function toDiscord($notifiable) + { + + return (new DiscordMessage) + ->embed(function ($embed) { + + $embed->title('** New Application for a managed SeAT Group **') + ->thumbnail($this->image) + ->color(self::INFO_COLOR) + ->description(sprintf('%s just applied to a SeAT Group you are managing. Head over to [SeAT Groups](%s) and accept or deny the candidate.', + $this->main_character->name, $this->url)) + ->field('SeAT Group', $this->seatgroup_string, true) + ->field('User group', $this->usergroup_string, true) + ->field('Other pending applications', $this->pending_applications, false); + }); + } +} diff --git a/src/Notifications/SeatGroupApplication/SlackSeatGroupApplicationNotification.php b/src/Notifications/SeatGroupApplication/SlackSeatGroupApplicationNotification.php new file mode 100644 index 0000000..1fccdee --- /dev/null +++ b/src/Notifications/SeatGroupApplication/SlackSeatGroupApplicationNotification.php @@ -0,0 +1,82 @@ +tags, is_null($notifiable->group_id) ? 'to channel' : 'private to: ' . $this->getMainCharacter(Group::find($notifiable->group_id))->name); + + return [SlackChannel::class]; + } + + /** + * @param $notifiable + * + * @return \Herpaderpaldent\Seat\SeatNotifications\Channels\Slack\SlackMessage + */ + public function toSlack($notifiable) + { + + return (new SlackMessage) + ->attachment(function ($attachment) { + $attachment + ->title('New Application for a managed SeAT Group', $this->url) + ->thumb($this->image) + ->color('17A2B8') + ->content(sprintf('%s just applied to a SeAT Group you are managing. Head over to SeAT Groups and accept or deny the candidate.', + $this->main_character->name)) + ->fields([ + 'SeAT Group' => $this->seatgroup_string, + 'User group' => $this->usergroup_string, + 'Other pending applications' => $this->pending_applications, + ]); + }); + } +} diff --git a/src/Notifications/SeatGroupApplicationNotification.php b/src/Notifications/SeatGroupApplicationNotification.php deleted file mode 100644 index 53f6daf..0000000 --- a/src/Notifications/SeatGroupApplicationNotification.php +++ /dev/null @@ -1,160 +0,0 @@ -group = $group; - $this->seatgroup = $seatgroup; - - $this->main_character = $this->getMainCharacter($group); - $this->image = 'https://imageserver.eveonline.com/Character/' . $this->main_character->character_id . '_128.jpg'; - $this->url = route('seatgroups.index') . '#managed_group'; - - $this->seatgroup_string = (string) $this->seatgroup->name; - $this->usergroup_string = (string) $this->group->users->map(function ($user) {return $user->name; })->implode(', '); - - $applications_helper = $this->seatgroup - ->waitlist - ->filter(function ($group) { - return $group->id !== $this->group->id; - }) - ->map(function ($group) { - return $this->getMainCharacter($group)->name; - }); - - $this->pending_applications = (string) $applications_helper->isNotEmpty() ? $applications_helper->implode(', ') : 'none'; - } - - /** - * Get the notification's delivery channels. - * - * @param mixed $notifiable - * @return array - */ - public function via($notifiable) - { - - switch($notifiable->notification_channel) { - case 'discord': - array_push($this->tags, 'discord'); - - return [DiscordChannel::class]; - break; - case 'slack': - array_push($this->tags, 'slack'); - - return [SlackChannel::class]; - break; - default: - return ['']; - } - } - - public function toDiscord($notifiable) - { - - return (new DiscordMessage) - ->embed(function ($embed) { - - $embed->title('** New Application for a managed SeAT Group **') - ->thumbnail($this->image) - ->color('1548984') - ->description(sprintf('%s just applied to a SeAT Group you are managing. Head over to [SeAT Groups](%s) and accept or deny the candidate.', - $this->main_character->name, $this->url)) - ->field('SeAT Group', $this->seatgroup_string, true) - ->field('User group', $this->usergroup_string, true) - ->field('Other pending applications', $this->pending_applications, false); - }); - } - - /** - * @param $notifiable - * - * @return \Herpaderpaldent\Seat\SeatNotifications\Channels\Slack\SlackMessage - */ - public function toSlack($notifiable) - { - - return (new SlackMessage) - ->attachment(function ($attachment) { - $attachment - ->title('New Application for a managed SeAT Group', $this->url) - ->thumb($this->image) - ->color('17A2B8') - ->content(sprintf('%s just applied to a SeAT Group you are managing. Head over to SeAT Groups and accept or deny the candidate.', - $this->main_character->name)) - ->fields([ - 'SeAT Group' => $this->seatgroup_string, - 'User group' => $this->usergroup_string, - 'Other pending applications' => $this->pending_applications, - ]); - }); - } -} diff --git a/src/Notifications/SeatGroupError/AbstractSeatGroupErrorNotification.php b/src/Notifications/SeatGroupError/AbstractSeatGroupErrorNotification.php new file mode 100644 index 0000000..abed19d --- /dev/null +++ b/src/Notifications/SeatGroupError/AbstractSeatGroupErrorNotification.php @@ -0,0 +1,149 @@ +user = $user; + $this->image = 'https://imageserver.eveonline.com/Character/' . $this->user->id . '_128.jpg'; + $this->message = $message; + $this->url = route('character.view.sheet', ['character_id' => $this->user->id]); + } + + /** + * Return a title for the notification which will be displayed in UI notification list. + * @return string + */ + public static function getTitle(): string + { + return 'SeAT Group Error'; + } + + /** + * Return a description for the notification which will be displayed in UI notification list. + * @return string + */ + public static function getDescription(): string + { + return 'Receive a notification about error during SeAT Group Syncs.'; + } + + /** + * Determine if a notification can target public channel (forum category, chat, etc...). + * @return bool + */ + public static function isPublic(): bool + { + return true; + } + + /** + * Determine if a notification can target personal channel (private message, e-mail, etc...). + * @return bool + */ + public static function isPersonal(): bool + { + return true; + } + + /** + * Determine the permission needed to represent driver buttons. + * @return string + */ + public static function getPermission(): string + { + return 'seatgroups.error_notification'; + } + + /** + * @param $notifiable + * @return mixed + */ + abstract public function via($notifiable); + + /** + * @param $notifiable + * + * @return bool + * @throws \Exception + */ + public function dontSend($notifiable) :bool + { + $value = collect([ + 'recipient' => $notifiable->driver_id, + 'notification' => get_called_class(), + 'content' => get_object_vars($this), + ])->toJson(); + + $key = sha1($value); + + if (empty(cache($key))) { + cache([$key => $value], now()->addHours(4)); + + return false; + } + + return true; + } +} diff --git a/src/Notifications/SeatGroupError/DiscordSeatGroupErrorNotification.php b/src/Notifications/SeatGroupError/DiscordSeatGroupErrorNotification.php new file mode 100644 index 0000000..f74c3ab --- /dev/null +++ b/src/Notifications/SeatGroupError/DiscordSeatGroupErrorNotification.php @@ -0,0 +1,81 @@ +dontSend($notifiable)) + return []; + + array_push($this->tags, is_null($notifiable->group_id) ? 'to channel' : 'private to: ' + . $this->getMainCharacter(Group::find($notifiable->group_id))->name); + + return [DiscordChannel::class]; + } + + /** + * @param $notifiable + * + * @return mixed + */ + public function toDiscord($notifiable) + { + + return (new DiscordMessage) + ->embed(function ($embed) { + + $embed + ->title('** Error **', $this->url) + ->thumbnail($this->image) + ->color('12727073') + ->description($this->message); + }); + } +} diff --git a/src/Notifications/SeatGroupError/SlackSeatGroupErrorNotification.php b/src/Notifications/SeatGroupError/SlackSeatGroupErrorNotification.php new file mode 100644 index 0000000..4a78d2f --- /dev/null +++ b/src/Notifications/SeatGroupError/SlackSeatGroupErrorNotification.php @@ -0,0 +1,79 @@ +dontSend($notifiable)) + return []; + + array_push($this->tags, is_null($notifiable->group_id) ? 'to channel' : 'private to: ' + . $this->getMainCharacter(Group::find($notifiable->group_id))->name); + + return [SlackChannel::class]; + } + + /** + * @param $notifiable + * + * @return \Herpaderpaldent\Seat\SeatNotifications\Channels\Slack\SlackMessage + */ + public function toSlack($notifiable) + { + return (new SlackMessage) + ->attachment(function ($attachment) { + $attachment + ->title('Error', $this->url) + ->thumb($this->image) + ->color(self::DANGER_COLOR) + ->content($this->message); + }); + } +} diff --git a/src/Notifications/SeatGroupErrorNotification.php b/src/Notifications/SeatGroupErrorNotification.php deleted file mode 100644 index f2481c5..0000000 --- a/src/Notifications/SeatGroupErrorNotification.php +++ /dev/null @@ -1,130 +0,0 @@ -user = $user; - $this->image = 'https://imageserver.eveonline.com/Character/' . $this->user->id . '_128.jpg'; - $this->message = $message; - $this->url = route('character.view.sheet', ['character_id' => $this->user->id]); - } - - /** - * Get the notification's delivery channels. - * - * @param mixed $notifiable - * @return array - */ - public function via($notifiable) - { - - switch($notifiable->notification_channel) { - case 'discord': - $this->tags = array_merge($this->tags, [ - 'discord', - ]); - - return [DiscordChannel::class]; - break; - case 'slack': - $this->tags = array_merge($this->tags, [ - 'slack', - ]); - - return [SlackChannel::class]; - break; - default: - return ['']; - } - } - - public function toDiscord($notifiable) - { - - return (new DiscordMessage) - ->embed(function ($embed) { - - $embed - ->title('** Error **', $this->url) - ->thumbnail($this->image) - ->color('12727073') - ->description($this->message); - }); - } - - /** - * @param $notifiable - * - * @return \Herpaderpaldent\Seat\SeatNotifications\Channels\Slack\SlackMessage - */ - public function toSlack($notifiable) - { - return (new SlackMessage) - ->warning() - ->attachment(function ($attachment) { - $attachment - ->title('Error', $this->url) - ->thumb($this->image) - ->color('C23321') - ->content($this->message); - }); - } -} diff --git a/src/Notifications/SeatGroupSync/AbstractSeatGroupSyncNotification.php b/src/Notifications/SeatGroupSync/AbstractSeatGroupSyncNotification.php new file mode 100644 index 0000000..6f95566 --- /dev/null +++ b/src/Notifications/SeatGroupSync/AbstractSeatGroupSyncNotification.php @@ -0,0 +1,162 @@ +group = $group; + $this->main_character = $this->getMainCharacter($group); + $this->image = 'https://imageserver.eveonline.com/Character/' . $this->main_character->character_id . '_128.jpg'; + + if (! empty($sync['attached'])) + $this->attached_roles = Role::whereIn('id', $sync['attached'])->pluck('title')->implode(', '); + + if (! empty($sync['detached'])) + $this->detached_roles = Role::whereIn('id', $sync['detached'])->pluck('title')->implode(', '); + + array_push($this->tags, 'group_id:' . $group->id); + } + + /** + * Return a title for the notification which will be displayed in UI notification list. + * @return string + */ + public static function getTitle(): string + { + return 'SeAT Group Sync'; + } + + /** + * Return a description for the notification which will be displayed in UI notification list. + * @return string + */ + public static function getDescription(): string + { + return 'Receive a notification about attached or detached roles to user groups.'; + } + + /** + * Determine if a notification can target public channel (forum category, chat, etc...). + * @return bool + */ + public static function isPublic(): bool + { + return true; + } + + /** + * Determine if a notification can target personal channel (private message, e-mail, etc...). + * @return bool + */ + public static function isPersonal(): bool + { + return true; + } + + /** + * Determine the permission needed to represent driver buttons. + * @return string + */ + public static function getPermission(): string + { + return 'seatgroups.sync_notification'; + } + + /** + * @param $notifiable + * @return mixed + */ + abstract public function via($notifiable); + + /** + * @param $notifiable + * + * @return bool + * @throws \Exception + */ + public function dontSend($notifiable) :bool + { + $value = collect([ + 'recipient' => $notifiable->driver_id, + 'notification' => get_called_class(), + 'content' => get_object_vars($this), + ])->toJson(); + + $key = sha1($value); + + if (empty(cache($key))) { + cache([$key => $value], now()->addHours(4)); + + return false; + } + + return true; + } +} diff --git a/src/Notifications/SeatGroupSync/DiscordSeatGroupSyncNotification.php b/src/Notifications/SeatGroupSync/DiscordSeatGroupSyncNotification.php new file mode 100644 index 0000000..599c2f5 --- /dev/null +++ b/src/Notifications/SeatGroupSync/DiscordSeatGroupSyncNotification.php @@ -0,0 +1,88 @@ +dontSend($notifiable)) + return []; + + array_push($this->tags, is_null($notifiable->group_id) ? 'to channel' : 'private to: ' . $this->getMainCharacter(Group::find($notifiable->group_id))->name); + + return [DiscordChannel::class]; + } + + /** + * @param $notifiable + * @return DiscordMessage + */ + public function toDiscord($notifiable) + { + $main_character = sprintf('The user group of %s has just been updated.', + $this->main_character->name); + + $users = sprintf('Users in user group: %s', + $this->group->users->map(function ($user) { + + return $user->name; + })->implode(', ')); + + return (new DiscordMessage) + ->embed(function ($embed) use ($main_character, $users) { + + $embed->title('** ' . $main_character . ' **') + ->thumbnail($this->image) + ->color(self::INFO_COLOR) + ->description($users) + ->field('Attachhed roles', $this->attached_roles, true) + ->field('Detached roles', $this->detached_roles, true); + }); + } +} diff --git a/src/Notifications/SeatGroupSync/SlackSeatGroupSyncNotification.php b/src/Notifications/SeatGroupSync/SlackSeatGroupSyncNotification.php new file mode 100644 index 0000000..c62ace8 --- /dev/null +++ b/src/Notifications/SeatGroupSync/SlackSeatGroupSyncNotification.php @@ -0,0 +1,91 @@ +dontSend($notifiable)) + return []; + + array_push($this->tags, is_null($notifiable->group_id) ? 'to channel' : 'private to: ' . $this->getMainCharacter(Group::find($notifiable->group_id))->name); + + return [SlackChannel::class]; + } + + /** + * @param $notifiable + * + * @return \Herpaderpaldent\Seat\SeatNotifications\Channels\Slack\SlackMessage + */ + public function toSlack($notifiable) + { + $main_character = sprintf('The user group of %s has just been updated.', + $this->main_character->name); + + $users = sprintf('Users in user group: %s', + $this->group->users->map(function ($user) { + + return $user->name; + })->implode(', ')); + + return (new SlackMessage) + ->attachment(function ($attachment) use ($main_character, $users) { + $attachment + ->title($main_character, route('character.view.sheet', ['character_id' => $this->main_character->character_id])) + ->fields([ + 'Attachhed roles' => $this->attached_roles, + 'Detached roles' => $this->detached_roles, + ]) + ->content($users) + ->color(self::INFO_COLOR) + ->thumb($this->image); + }); + } +} diff --git a/src/Notifications/SeatGroupSyncNotification.php b/src/Notifications/SeatGroupSyncNotification.php deleted file mode 100644 index e1222c0..0000000 --- a/src/Notifications/SeatGroupSyncNotification.php +++ /dev/null @@ -1,161 +0,0 @@ -group = $group; - $this->main_character = $this->getMainCharacter($group); - $this->image = 'https://imageserver.eveonline.com/Character/' . $this->main_character->character_id . '_128.jpg'; - - if (! empty($sync['attached'])) - $this->attached_roles = Role::whereIn('id', $sync['attached'])->pluck('title')->implode(', '); - - if (! empty($sync['detached'])) - $this->detached_roles = Role::whereIn('id', $sync['detached'])->pluck('title')->implode(', '); - - array_push($this->tags, 'group_id:' . $group->id); - } - - /** - * Get the notification's delivery channels. - * - * @param mixed $notifiable - * @return array - */ - public function via($notifiable) - { - - switch($notifiable->notification_channel) { - case 'discord': - array_push($this->tags, 'discord'); - - return [DiscordChannel::class]; - break; - case 'slack': - array_push($this->tags, 'slack'); - - return [SlackChannel::class]; - break; - default: - return ['']; - } - } - - public function toDiscord($notifiable) - { - - $main_character = sprintf('The user group of %s has just been updated.', - $this->main_character->name); - - $users = sprintf('Users in user group: %s', - $this->group->users->map(function ($user) { - - return $user->name; - })->implode(', ')); - - return (new DiscordMessage) - ->embed(function ($embed) use ($main_character, $users) { - - $embed->title('** ' . $main_character . ' **') - ->thumbnail($this->image) - ->color('1548984') - ->description($users) - ->field('Attachhed roles', $this->attached_roles, true) - ->field('Detached roles', $this->detached_roles, true); - }); - } - - /** - * @param $notifiable - * - * @return \Herpaderpaldent\Seat\SeatNotifications\Channels\Slack\SlackMessage - */ - public function toSlack($notifiable) - { - $main_character = sprintf('The user group of %s has just been updated.', - $this->main_character->name); - - $users = sprintf('Users in user group: %s', - $this->group->users->map(function ($user) { - - return $user->name; - })->implode(', ')); - - return (new SlackMessage) - ->attachment(function ($attachment) use ($main_character, $users) { - $attachment - ->title($main_character, route('character.view.sheet', ['character_id' => $this->main_character->character_id])) - ->fields([ - 'Attachhed roles' => $this->attached_roles, - 'Detached roles' => $this->detached_roles, - ]) - ->content($users) - ->color('17A2B8') - ->thumb($this->image); - }); - } -} diff --git a/src/config/seatgroups.config.php b/src/config/seatgroups.config.php index bc33594..664c809 100644 --- a/src/config/seatgroups.config.php +++ b/src/config/seatgroups.config.php @@ -24,7 +24,7 @@ */ return [ - 'version' => '1.6.9', + 'version' => '1.7.0', ]; //TODO: Update Version diff --git a/src/config/seatgroups.permission.php b/src/config/seatgroups.permission.php index dfd1f39..3da9310 100644 --- a/src/config/seatgroups.permission.php +++ b/src/config/seatgroups.permission.php @@ -10,5 +10,9 @@ 'seatgroups' => [ 'view', 'create', + 'missing_refresh_token_notification', + 'group_application_notification', + 'error_notification', + 'sync_notification', ], ]; diff --git a/src/config/seatgroups.services.php b/src/config/seatgroups.services.php index 50f1cc3..c025c26 100644 --- a/src/config/seatgroups.services.php +++ b/src/config/seatgroups.services.php @@ -26,10 +26,22 @@ return [ 'seat-notification' => [ - '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, - 'seatgroup_application' => Herpaderpaldent\Seat\SeatGroups\Http\Controllers\Notifications\SeatGroupApplicationController::class, + Herpaderpaldent\Seat\SeatGroups\Notifications\SeatGroupSync\AbstractSeatGroupSyncNotification::class => [ + 'discord' => Herpaderpaldent\Seat\SeatGroups\Notifications\SeatGroupSync\DiscordSeatGroupSyncNotification::class, + 'slack' => Herpaderpaldent\Seat\SeatGroups\Notifications\SeatGroupSync\SlackSeatGroupSyncNotification::class, + ], + Herpaderpaldent\Seat\SeatGroups\Notifications\MissingRefreshToken\AbstractMissingRefreshTokenNotification::class => [ + 'discord' => Herpaderpaldent\Seat\SeatGroups\Notifications\MissingRefreshToken\DiscordMissingRefreshTokenNotification::class, + 'slack' => Herpaderpaldent\Seat\SeatGroups\Notifications\MissingRefreshToken\SlackMissingRefreshTokenNotification::class, + ], + Herpaderpaldent\Seat\SeatGroups\Notifications\SeatGroupApplication\AbstractSeatGroupApplicationNotification::class => [ + 'discord' => Herpaderpaldent\Seat\SeatGroups\Notifications\SeatGroupApplication\DiscordSeatGroupApplicationNotification::class, + 'slack' => Herpaderpaldent\Seat\SeatGroups\Notifications\SeatGroupApplication\SlackSeatGroupApplicationNotification::class, + ], + Herpaderpaldent\Seat\SeatGroups\Notifications\SeatGroupError\AbstractSeatGroupErrorNotification::class => [ + 'discord' => Herpaderpaldent\Seat\SeatGroups\Notifications\SeatGroupError\DiscordSeatGroupErrorNotification::class, + 'slack' => Herpaderpaldent\Seat\SeatGroups\Notifications\SeatGroupError\SlackSeatGroupErrorNotification::class, + ], ], ]; diff --git a/src/resources/views/notification/missing_refreshtoken/channel.blade.php b/src/resources/views/notification/missing_refreshtoken/channel.blade.php deleted file mode 100644 index 108d3bb..0000000 --- a/src/resources/views/notification/missing_refreshtoken/channel.blade.php +++ /dev/null @@ -1,46 +0,0 @@ -@inject('MissingRefreshTokenController', 'Herpaderpaldent\Seat\SeatGroups\Http\Controllers\Notifications\MissingRefreshTokenController') - -@if($MissingRefreshTokenController->isAvailable()) - - @if( $MissingRefreshTokenController->isDisabledButton('channel', 'discord') ) - - Discord - - @elseif(! $MissingRefreshTokenController->isSubscribed('channel', 'discord')) - - Discord - - @include('seatgroups::notification.missing_refreshtoken.partials.discord-channel-modal') - @else - - - Discord - - @endif - - @if( $MissingRefreshTokenController->isDisabledButton('channel', 'slack')) - - Slack - - @elseif(! $MissingRefreshTokenController->isSubscribed('channel', 'slack')) - - Slack - - @include('seatgroups::notification.missing_refreshtoken.partials.slack-channel-modal') - @else - - - Slack - - @endif - -@else - - @include('seatnotifications::seatnotifications.partials.missing-permissions') - -@endif - diff --git a/src/resources/views/notification/missing_refreshtoken/notification.blade.php b/src/resources/views/notification/missing_refreshtoken/notification.blade.php deleted file mode 100644 index 6e22a89..0000000 --- a/src/resources/views/notification/missing_refreshtoken/notification.blade.php +++ /dev/null @@ -1,2 +0,0 @@ -SeAT Group - Missing Refresh Token -

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 deleted file mode 100644 index 10af886..0000000 --- a/src/resources/views/notification/missing_refreshtoken/partials/discord-channel-modal.blade.php +++ /dev/null @@ -1,50 +0,0 @@ - \ No newline at end of file diff --git a/src/resources/views/notification/missing_refreshtoken/partials/slack-channel-modal.blade.php b/src/resources/views/notification/missing_refreshtoken/partials/slack-channel-modal.blade.php deleted file mode 100644 index b873dd2..0000000 --- a/src/resources/views/notification/missing_refreshtoken/partials/slack-channel-modal.blade.php +++ /dev/null @@ -1,53 +0,0 @@ - \ No newline at end of file diff --git a/src/resources/views/notification/missing_refreshtoken/private.blade.php b/src/resources/views/notification/missing_refreshtoken/private.blade.php deleted file mode 100644 index 6210be7..0000000 --- a/src/resources/views/notification/missing_refreshtoken/private.blade.php +++ /dev/null @@ -1,43 +0,0 @@ -@inject('MissingRefreshTokenController', 'Herpaderpaldent\Seat\SeatGroups\Http\Controllers\Notifications\MissingRefreshTokenController') - -@if($MissingRefreshTokenController->isAvailable()) - - @if( $MissingRefreshTokenController->isDisabledButton('private', 'discord')) - - Discord - - @elseif(! $MissingRefreshTokenController->isSubscribed('private', 'discord')) - - Discord - - @else - - - Discord - - @endif - - @if( $MissingRefreshTokenController->isDisabledButton('private','slack')) - - Slack - - @elseif(! $MissingRefreshTokenController->isSubscribed('private', 'slack')) - - Slack - - @else - - - Slack - - @endif - -@else - - @include('seatnotifications::seatnotifications.partials.missing-permissions') - -@endif diff --git a/src/resources/views/notification/seatgroup_application/channel.blade.php b/src/resources/views/notification/seatgroup_application/channel.blade.php deleted file mode 100644 index 5db49ba..0000000 --- a/src/resources/views/notification/seatgroup_application/channel.blade.php +++ /dev/null @@ -1,4 +0,0 @@ -
-

Not supported

- Managers may subscribe to new SeAT Group applications individually. -
\ No newline at end of file diff --git a/src/resources/views/notification/seatgroup_application/notification.blade.php b/src/resources/views/notification/seatgroup_application/notification.blade.php deleted file mode 100644 index 759a12d..0000000 --- a/src/resources/views/notification/seatgroup_application/notification.blade.php +++ /dev/null @@ -1,2 +0,0 @@ -SeAT Group Applications -

Receive a notification about new SeAT Group candidates which are on the wait list.

\ No newline at end of file diff --git a/src/resources/views/notification/seatgroup_application/private.blade.php b/src/resources/views/notification/seatgroup_application/private.blade.php deleted file mode 100644 index b70719f..0000000 --- a/src/resources/views/notification/seatgroup_application/private.blade.php +++ /dev/null @@ -1,43 +0,0 @@ -@inject('SeatGroupApplicationController', 'Herpaderpaldent\Seat\SeatGroups\Http\Controllers\Notifications\SeatGroupApplicationController') - -@if($SeatGroupApplicationController->isAvailable()) - - @if( $SeatGroupApplicationController->isDisabledButton('private', 'discord')) - - Discord - - @elseif(! $SeatGroupApplicationController->isSubscribed('private', 'discord')) - - Discord - - @else - - - Discord - - @endif - - @if( $SeatGroupApplicationController->isDisabledButton('private','slack')) - - Slack - - @elseif(! $SeatGroupApplicationController->isSubscribed('private', 'slack')) - - Slack - - @else - - - Slack - - @endif - -@else - - @include('seatnotifications::seatnotifications.partials.missing-permissions') - -@endif diff --git a/src/resources/views/notification/seatgroup_error/channel.blade.php b/src/resources/views/notification/seatgroup_error/channel.blade.php deleted file mode 100644 index 6bef6d0..0000000 --- a/src/resources/views/notification/seatgroup_error/channel.blade.php +++ /dev/null @@ -1,46 +0,0 @@ -@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 deleted file mode 100644 index 8f171a3..0000000 --- a/src/resources/views/notification/seatgroup_error/notification.blade.php +++ /dev/null @@ -1,2 +0,0 @@ -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 deleted file mode 100644 index 6acb4b4..0000000 --- a/src/resources/views/notification/seatgroup_error/partials/discord-channel-modal.blade.php +++ /dev/null @@ -1,50 +0,0 @@ - \ No newline at end of file diff --git a/src/resources/views/notification/seatgroup_error/partials/slack-channel-modal.blade.php b/src/resources/views/notification/seatgroup_error/partials/slack-channel-modal.blade.php deleted file mode 100644 index e2c67a6..0000000 --- a/src/resources/views/notification/seatgroup_error/partials/slack-channel-modal.blade.php +++ /dev/null @@ -1,53 +0,0 @@ - \ No newline at end of file diff --git a/src/resources/views/notification/seatgroup_error/private.blade.php b/src/resources/views/notification/seatgroup_error/private.blade.php deleted file mode 100644 index 1e92e51..0000000 --- a/src/resources/views/notification/seatgroup_error/private.blade.php +++ /dev/null @@ -1,43 +0,0 @@ -@inject('SeatGroupErrorController', 'Herpaderpaldent\Seat\SeatGroups\Http\Controllers\Notifications\SeatGroupErrorController') - -@if($SeatGroupErrorController->isAvailable()) - - @if( $SeatGroupErrorController->isDisabledButton('private', 'discord')) - - Discord - - @elseif(! $SeatGroupErrorController->isSubscribed('private', 'discord')) - - Discord - - @else - - - Discord - - @endif - - @if( $SeatGroupErrorController->isDisabledButton('private','slack')) - - Slack - - @elseif(! $SeatGroupErrorController->isSubscribed('private', 'slack')) - - Slack - - @else - - - Slack - - @endif - -@else - - @include('seatnotifications::seatnotifications.partials.missing-permissions') - -@endif diff --git a/src/resources/views/notification/seatgroup_sync/channel.blade.php b/src/resources/views/notification/seatgroup_sync/channel.blade.php deleted file mode 100644 index 28154d7..0000000 --- a/src/resources/views/notification/seatgroup_sync/channel.blade.php +++ /dev/null @@ -1,46 +0,0 @@ -@inject('SeatGroupSyncController', 'Herpaderpaldent\Seat\SeatGroups\Http\Controllers\Notifications\SeatGroupSyncController') - -@if($SeatGroupSyncController->isAvailable()) - - @if( $SeatGroupSyncController->isDisabledButton('channel', 'discord') ) - - Discord - - @elseif(! $SeatGroupSyncController->isSubscribed('channel', 'discord')) - - Discord - - @include('seatgroups::notification.seatgroup_sync.partials.discord-channel-modal') - @else - - - Discord - - @endif - - @if( $SeatGroupSyncController->isDisabledButton('channel', 'slack')) - - Slack - - @elseif(! $SeatGroupSyncController->isSubscribed('channel', 'slack')) - - Slack - - @include('seatgroups::notification.seatgroup_sync.partials.slack-channel-modal') - @else - - - Slack - - @endif - -@else - - @include('seatnotifications::seatnotifications.partials.missing-permissions') - -@endif - diff --git a/src/resources/views/notification/seatgroup_sync/notification.blade.php b/src/resources/views/notification/seatgroup_sync/notification.blade.php deleted file mode 100644 index 5b927ff..0000000 --- a/src/resources/views/notification/seatgroup_sync/notification.blade.php +++ /dev/null @@ -1,2 +0,0 @@ -SeAT Group Sync -

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 deleted file mode 100644 index 04508bc..0000000 --- a/src/resources/views/notification/seatgroup_sync/partials/discord-channel-modal.blade.php +++ /dev/null @@ -1,50 +0,0 @@ - \ No newline at end of file diff --git a/src/resources/views/notification/seatgroup_sync/partials/slack-channel-modal.blade.php b/src/resources/views/notification/seatgroup_sync/partials/slack-channel-modal.blade.php deleted file mode 100644 index 6b23e6d..0000000 --- a/src/resources/views/notification/seatgroup_sync/partials/slack-channel-modal.blade.php +++ /dev/null @@ -1,53 +0,0 @@ - \ No newline at end of file diff --git a/src/resources/views/notification/seatgroup_sync/private.blade.php b/src/resources/views/notification/seatgroup_sync/private.blade.php deleted file mode 100644 index d924ff9..0000000 --- a/src/resources/views/notification/seatgroup_sync/private.blade.php +++ /dev/null @@ -1,43 +0,0 @@ -@inject('SeatGroupSyncController', 'Herpaderpaldent\Seat\SeatGroups\Http\Controllers\Notifications\SeatGroupSyncController') - -@if($SeatGroupSyncController->isAvailable()) - - @if( $SeatGroupSyncController->isDisabledButton('private', 'discord')) - - Discord - - @elseif(! $SeatGroupSyncController->isSubscribed('private', 'discord')) - - Discord - - @else - - - Discord - - @endif - - @if( $SeatGroupSyncController->isDisabledButton('private','slack')) - - Slack - - @elseif(! $SeatGroupSyncController->isSubscribed('private', 'slack')) - - Slack - - @else - - - Slack - - @endif - -@else - - @include('seatnotifications::seatnotifications.partials.missing-permissions') - -@endif