This repository has been archived by the owner on Jul 12, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #76 from herpaderpaldent/development
Add SeatGroupApplicationNotification
- Loading branch information
Showing
14 changed files
with
512 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
/** | ||
* 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\Events; | ||
|
||
use Herpaderpaldent\Seat\SeatGroups\Models\Seatgroup; | ||
use Illuminate\Queue\SerializesModels; | ||
use Seat\Web\Models\Group; | ||
|
||
class GroupApplication | ||
{ | ||
use SerializesModels; | ||
|
||
public $group; | ||
|
||
public $seatgroup; | ||
|
||
public function __construct(Group $group, Seatgroup $seatgroup) | ||
{ | ||
$this->group = $group; | ||
$this->seatgroup = $seatgroup; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
src/Http/Controllers/Notifications/SeatGroupApplicationController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
<?php | ||
/** | ||
* 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\Http\Controllers\Notifications; | ||
|
||
use Herpaderpaldent\Seat\SeatNotifications\Http\Controllers\BaseNotificationController; | ||
|
||
class SeatGroupApplicationController extends BaseNotificationController | ||
{ | ||
public function getNotification() : string | ||
{ | ||
return 'seatgroups::notification.seatgroup_application.notification'; | ||
} | ||
|
||
public function getPrivateView() : string | ||
{ | ||
return 'seatgroups::notification.seatgroup_application.private'; | ||
} | ||
|
||
public function getChannelView() : string | ||
{ | ||
|
||
return 'seatgroups::notification.seatgroup_application.channel'; | ||
} | ||
|
||
public function subscribeDm($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->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'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<?php | ||
/** | ||
* 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\GroupApplication; | ||
use Herpaderpaldent\Seat\SeatGroups\Notifications\SeatGroupApplicationNotification; | ||
use Herpaderpaldent\Seat\SeatNotifications\Models\SeatNotificationRecipient; | ||
use Herpaderpaldent\Seat\SeatNotifications\Notifications\BaseNotification; | ||
use Illuminate\Support\Facades\Notification; | ||
|
||
class GroupApplicationNotification | ||
{ | ||
public function __construct() | ||
{ | ||
|
||
} | ||
|
||
public function handle(GroupApplication $event) | ||
{ | ||
$should_send = false; | ||
|
||
if (class_exists(BaseNotification::class)) | ||
$should_send = true; | ||
|
||
if ($should_send){ | ||
|
||
$recipients = SeatNotificationRecipient::all() | ||
->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))); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.