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

Commit

Permalink
Merge pull request #76 from herpaderpaldent/development
Browse files Browse the repository at this point in the history
Add SeatGroupApplicationNotification
  • Loading branch information
herpaderpaldent authored Feb 10, 2019
2 parents 39c7237 + c61a2ba commit 7a11d53
Show file tree
Hide file tree
Showing 14 changed files with 512 additions and 8 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
45 changes: 45 additions & 0 deletions src/Events/GroupApplication.php
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;
}
}
27 changes: 27 additions & 0 deletions src/GroupsServiceProvider.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,37 @@
<?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;

use Herpaderpaldent\Seat\SeatGroups\Events\GroupApplication;
use Herpaderpaldent\Seat\SeatGroups\Events\GroupSynced;
use Herpaderpaldent\Seat\SeatGroups\Events\GroupSyncFailed;
use Herpaderpaldent\Seat\SeatGroups\Events\MissingRefreshToken;
use Herpaderpaldent\Seat\SeatGroups\Listeners\CreateSyncedSeatLogsEntry;
use Herpaderpaldent\Seat\SeatGroups\Listeners\CreateSyncFailedLogsEntry;
use Herpaderpaldent\Seat\SeatGroups\Listeners\GroupApplicationNotification;
use Herpaderpaldent\Seat\SeatGroups\Listeners\GroupSyncedNotification;
use Herpaderpaldent\Seat\SeatGroups\Listeners\GroupSyncFailedNotification;
use Herpaderpaldent\Seat\SeatGroups\Listeners\MissingRefreshTokenLogsEntry;
Expand Down Expand Up @@ -93,6 +118,8 @@ private function add_events()

$this->app->events->listen(MissingRefreshToken::class, MissingRefreshTokenLogsEntry::class);
$this->app->events->listen(MissingRefreshToken::class, MissingRefreshTokenNotification::class);

$this->app->events->listen(GroupApplication::class, GroupApplicationNotification::class);
}

/**
Expand Down
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');
}
}
26 changes: 26 additions & 0 deletions src/Http/Controllers/SeatGroupUserController.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,33 @@
<?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;

use Herpaderpaldent\Seat\SeatGroups\Actions\Managers\AddManagerAction;
use Herpaderpaldent\Seat\SeatGroups\Actions\Managers\RemoveManagerAction;
use Herpaderpaldent\Seat\SeatGroups\Events\GroupApplication;
use Herpaderpaldent\Seat\SeatGroups\Http\Validation\Manager\AddManagerRequest;
use Herpaderpaldent\Seat\SeatGroups\Http\Validation\Manager\RemoveManagerRequest;
use Herpaderpaldent\Seat\SeatGroups\Jobs\GroupSync;
Expand Down Expand Up @@ -155,6 +179,8 @@ public function update(Request $request, $id)
'on_waitlist' => 1,
]);

event(new GroupApplication(auth()->user()->group, $seatgroup));

return redirect()->back()->with([
'info' => 'you successfully applied to ' . $seatgroup->name,
'activeTab' => 'managed_group',
Expand Down
35 changes: 35 additions & 0 deletions src/Http/routes.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,28 @@
<?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.
*/

/**
* Created by PhpStorm.
* User: Mutterschiff
Expand Down Expand Up @@ -167,6 +191,17 @@
'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 () {
Expand Down
72 changes: 72 additions & 0 deletions src/Listeners/GroupApplicationNotification.php
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)));
}
}
}
7 changes: 0 additions & 7 deletions src/Listeners/GroupSyncFailedNotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading

0 comments on commit 7a11d53

Please sign in to comment.