diff --git a/CHANGELOG.md b/CHANGELOG.md index 8d71088..865e089 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +# Version 1.6.8 +This update adds application notification about candidates which are applying to a managed group. Works only for private channel notification to managers and superusers only. + +![Application Notification](https://i.imgur.com/K6D0Mos.png) + +This feature was suggested by @aaronmallen. Thank you all for providing me with all this valuable feedback and ideas on how to make SeAT Group great. + # Version 1.6.7 This version replaces `SeATGroupNotification` models in: * `GroupSyncFailedNotification` listener diff --git a/src/Events/GroupApplication.php b/src/Events/GroupApplication.php new file mode 100644 index 0000000..6016fdf --- /dev/null +++ b/src/Events/GroupApplication.php @@ -0,0 +1,45 @@ +group = $group; + $this->seatgroup = $seatgroup; + } +} diff --git a/src/GroupsServiceProvider.php b/src/GroupsServiceProvider.php index 45026da..785b222 100644 --- a/src/GroupsServiceProvider.php +++ b/src/GroupsServiceProvider.php @@ -1,12 +1,37 @@ app->events->listen(MissingRefreshToken::class, MissingRefreshTokenLogsEntry::class); $this->app->events->listen(MissingRefreshToken::class, MissingRefreshTokenNotification::class); + + $this->app->events->listen(GroupApplication::class, GroupApplicationNotification::class); } /** diff --git a/src/Http/Controllers/Notifications/SeatGroupApplicationController.php b/src/Http/Controllers/Notifications/SeatGroupApplicationController.php new file mode 100644 index 0000000..293515a --- /dev/null +++ b/src/Http/Controllers/Notifications/SeatGroupApplicationController.php @@ -0,0 +1,88 @@ +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_application')) + return redirect()->back()->with('success', 'You are going to be notified if someone applies to a SeAT Group you are managing.'); + + 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_application')) + return redirect()->back()->with('success', 'You are no longer going to be notified about SeAT Group Application events.'); + + return redirect()->back()->with('error', 'Something went wrong, please assure you have setup your personal delivery channel correctly.'); + } + + public function isSubscribed($view, $channel) + { + return $this->getSubscribtionStatus($channel, $view, 'seatgroup_application'); + } + + 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/SeatGroupUserController.php b/src/Http/Controllers/SeatGroupUserController.php index e61c614..bbe4dd7 100644 --- a/src/Http/Controllers/SeatGroupUserController.php +++ b/src/Http/Controllers/SeatGroupUserController.php @@ -1,9 +1,33 @@ 1, ]); + event(new GroupApplication(auth()->user()->group, $seatgroup)); + return redirect()->back()->with([ 'info' => 'you successfully applied to ' . $seatgroup->name, 'activeTab' => 'managed_group', diff --git a/src/Http/routes.php b/src/Http/routes.php index add51c1..c4bc5b2 100644 --- a/src/Http/routes.php +++ b/src/Http/routes.php @@ -1,4 +1,28 @@ '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 () { diff --git a/src/Listeners/GroupApplicationNotification.php b/src/Listeners/GroupApplicationNotification.php new file mode 100644 index 0000000..52cfafe --- /dev/null +++ b/src/Listeners/GroupApplicationNotification.php @@ -0,0 +1,72 @@ +filter(function ($recipient) { + return $recipient->shouldReceive('seatgroup_application'); + }) + ->filter(function ($recipient) use ($event) { + + // Check if recipient is superuser + foreach ($event->group->roles as $role) { + foreach ($role->permissions as $permission) { + if ($permission->title === 'superuser') + return true; + } + } + + // Check if recipient is manager + return $event->seatgroup->isManager($recipient->notification_user->group); + }); + + if($recipients->isNotEmpty()) + Notification::send($recipients, (new SeatGroupApplicationNotification($event->seatgroup, $event->group))); + } + } +} diff --git a/src/Listeners/GroupSyncFailedNotification.php b/src/Listeners/GroupSyncFailedNotification.php index 71803ce..0e87632 100644 --- a/src/Listeners/GroupSyncFailedNotification.php +++ b/src/Listeners/GroupSyncFailedNotification.php @@ -23,13 +23,6 @@ * SOFTWARE. */ -/** - * Created by PhpStorm. - * User: felix - * Date: 08.01.2019 - * Time: 20:38. - */ - namespace Herpaderpaldent\Seat\SeatGroups\Listeners; use Herpaderpaldent\Seat\SeatGroups\Events\GroupSyncFailed; diff --git a/src/Notifications/SeatGroupApplicationNotification.php b/src/Notifications/SeatGroupApplicationNotification.php new file mode 100644 index 0000000..fad2475 --- /dev/null +++ b/src/Notifications/SeatGroupApplicationNotification.php @@ -0,0 +1,138 @@ +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'; + } + + /** + * 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->name, 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) + { + + 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->name, + 'User group' => $this->group->users->map(function ($user) {return $user->name; })->implode(', '), + ]); + }); + } +} diff --git a/src/config/seatgroups.config.php b/src/config/seatgroups.config.php index 771d508..2b8dd79 100644 --- a/src/config/seatgroups.config.php +++ b/src/config/seatgroups.config.php @@ -24,7 +24,7 @@ */ return [ - 'version' => '1.6.7', + 'version' => '1.6.8', ]; //TODO: Update Version diff --git a/src/config/seatgroups.services.php b/src/config/seatgroups.services.php index b622106..50f1cc3 100644 --- a/src/config/seatgroups.services.php +++ b/src/config/seatgroups.services.php @@ -1,4 +1,27 @@ 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, ], ]; diff --git a/src/resources/views/notification/seatgroup_application/channel.blade.php b/src/resources/views/notification/seatgroup_application/channel.blade.php new file mode 100644 index 0000000..5db49ba --- /dev/null +++ b/src/resources/views/notification/seatgroup_application/channel.blade.php @@ -0,0 +1,4 @@ +
+

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 new file mode 100644 index 0000000..759a12d --- /dev/null +++ b/src/resources/views/notification/seatgroup_application/notification.blade.php @@ -0,0 +1,2 @@ +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 new file mode 100644 index 0000000..b70719f --- /dev/null +++ b/src/resources/views/notification/seatgroup_application/private.blade.php @@ -0,0 +1,43 @@ +@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