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 (#96)
Browse files Browse the repository at this point in the history
* Apply fixes from StyleCI (#94)

* correctly assert recipients group instead of the applicant ones.

* Implement `dontSend()` for Sync, Error

* Apply fixes from StyleCI (#97)
  • Loading branch information
herpaderpaldent authored Mar 28, 2019
1 parent 7c56397 commit a9b3bd5
Show file tree
Hide file tree
Showing 9 changed files with 81 additions and 3 deletions.
12 changes: 10 additions & 2 deletions src/Listeners/GroupApplicationNotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
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 @@ -51,18 +52,25 @@ public function handle(GroupApplication $event)
->filter(function ($recipient) {
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->isEmpty()){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public static function hasPersonalNotification() : bool
* @param $notifiable
*
* @return mixed
* @throws \Exception
*/
public function via($notifiable)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public static function getTitle(): string
*/
public static function getDescription(): string
{
return 'Receive a notification about new SeAT Group candidates which are on the wait list.';
return 'Receive a notification about new SeAT Group candidates which are on the waitlist of a SeAT group you are managing.';
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,4 +121,29 @@ public static function getPermission(): string
* @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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,15 @@ public static function hasPersonalNotification() : bool

/**
* @param $notifiable
*
* @return array
* @throws \Exception
*/
public function via($notifiable)
{
if($this->dontSend($notifiable))
return [];

array_push($this->tags, is_null($notifiable->group_id) ? 'to channel' : 'private to: '
. $this->getMainCharacter(Group::find($notifiable->group_id))->name);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,13 @@ public static function hasPersonalNotification() : bool
* @param $notifiable
*
* @return mixed
* @throws \Exception
*/
public function via($notifiable)
{
if($this->dontSend($notifiable))
return [];

array_push($this->tags, is_null($notifiable->group_id) ? 'to channel' : 'private to: '
. $this->getMainCharacter(Group::find($notifiable->group_id))->name);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,4 +134,29 @@ public static function getPermission(): string
* @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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,15 @@ public static function hasPersonalNotification() : bool

/**
* @param $notifiable
*
* @return array
* @throws \Exception
*/
public function via($notifiable)
{
if($this->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];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,15 @@ public static function hasPersonalNotification() : bool

/**
* @param $notifiable
*
* @return array
* @throws \Exception
*/
public function via($notifiable)
{
if($this->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];
Expand Down

0 comments on commit a9b3bd5

Please sign in to comment.