Skip to content
This repository has been archived by the owner on Jul 12, 2022. It is now read-only.

Commit

Permalink
Release/1.7.0 (#100)
Browse files Browse the repository at this point in the history
* 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: #91

* Add fix changelog note
  • Loading branch information
herpaderpaldent authored Mar 31, 2019
1 parent 678a2f3 commit 8b16527
Show file tree
Hide file tree
Showing 44 changed files with 1,444 additions and 1,367 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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:

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"phpunit/phpunit": "~6.0"
},
"conflict": {
"herpaderpaldent/seat-notifications": "^2.0.0"
"herpaderpaldent/seat-notifications": "<2.0.0"
},
"license": "MIT",
"authors": [
Expand Down
91 changes: 0 additions & 91 deletions src/Http/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand Down
39 changes: 29 additions & 10 deletions src/Listeners/GroupApplicationNotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -42,31 +43,49 @@ 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;
}
}

// 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)));
});
}
}
}
34 changes: 23 additions & 11 deletions src/Listeners/GroupSyncFailedNotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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)));
});
}
}
}
51 changes: 40 additions & 11 deletions src/Listeners/GroupSyncedNotification.php
Original file line number Diff line number Diff line change
@@ -1,17 +1,34 @@
<?php
/**
* Created by PhpStorm.
* User: felix
* Date: 08.01.2019
* Time: 20:38.
* MIT License.
*
* Copyright (c) 2019. Felix Huber
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

namespace Herpaderpaldent\Seat\SeatGroups\Listeners;

use Herpaderpaldent\Seat\SeatGroups\Events\GroupSynced;
use Herpaderpaldent\Seat\SeatGroups\Notifications\SeatGroupSyncNotification;
use Herpaderpaldent\Seat\SeatNotifications\Models\SeatNotificationRecipient;
use Herpaderpaldent\Seat\SeatNotifications\Notifications\BaseNotification;
use Herpaderpaldent\Seat\SeatGroups\Notifications\SeatGroupSync\AbstractSeatGroupSyncNotification;
use Herpaderpaldent\Seat\SeatNotifications\Models\NotificationRecipient;
use Herpaderpaldent\Seat\SeatNotifications\SeatNotificationsServiceProvider;
use Illuminate\Support\Facades\Notification;

class GroupSyncedNotification
Expand All @@ -31,17 +48,29 @@ public function handle(GroupSynced $event)
if (! empty($event->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)));
});
}
}
}
26 changes: 19 additions & 7 deletions src/Listeners/MissingRefreshTokenNotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)));
});
}
}
}
Loading

0 comments on commit 8b16527

Please sign in to comment.