From d41d0a6e2dcf8d26a27b2bfef9ea2c2cc60969aa Mon Sep 17 00:00:00 2001 From: 1day2die Date: Fri, 5 May 2023 12:29:28 +0200 Subject: [PATCH] ticket notify permission --- app/Http/Controllers/TicketsController.php | 23 +++++++++++----------- app/Settings/TicketSettings.php | 13 ------------ config/permissions_web.php | 1 + 3 files changed, 12 insertions(+), 25 deletions(-) diff --git a/app/Http/Controllers/TicketsController.php b/app/Http/Controllers/TicketsController.php index d5912e43..591c8d85 100644 --- a/app/Http/Controllers/TicketsController.php +++ b/app/Http/Controllers/TicketsController.php @@ -58,17 +58,13 @@ class TicketsController extends Controller ); $ticket->save(); $user = Auth::user(); - switch ($ticket_settings->notify) { - case 'all': - $admin = User::where('role', 'admin')->orWhere('role', 'mod')->get(); - Notification::send($admin, new AdminCreateNotification($ticket, $user)); - case 'admin': - $admin = User::where('role', 'admin')->get(); - Notification::send($admin, new AdminCreateNotification($ticket, $user)); - case 'moderator': - $admin = User::where('role', 'mod')->get(); - Notification::send($admin, new AdminCreateNotification($ticket, $user)); + + $staffNotify = User::permission('admin.tickets.get_notification')->get(); + foreach($staffNotify as $staff){ + Notification::send($staff, new AdminCreateNotification($ticket, $user)); } + + $user->notify(new CreateNotification($ticket)); return redirect()->route('ticket.index')->with('success', __('A ticket has been opened, ID: #') . $ticket->ticket_id); @@ -112,9 +108,12 @@ class TicketsController extends Controller 'message' => $request->input('message'), ]); $user = Auth::user(); - $admin = User::where('role', 'admin')->orWhere('role', 'mod')->get(); $newmessage = $request->input('ticketcomment'); - Notification::send($admin, new AdminReplyNotification($ticket, $user, $newmessage)); + + $staffNotify = User::permission('admin.tickets.get_notification')->get(); + foreach($staffNotify as $staff){ + Notification::send($staff, new AdminReplyNotification($ticket, $user, $newmessage)); + } return redirect()->back()->with('success', __('Your comment has been submitted')); } diff --git a/app/Settings/TicketSettings.php b/app/Settings/TicketSettings.php index 10ac16b1..34fde789 100644 --- a/app/Settings/TicketSettings.php +++ b/app/Settings/TicketSettings.php @@ -7,7 +7,6 @@ use Spatie\LaravelSettings\Settings; class TicketSettings extends Settings { public bool $enabled; - public string $notify; public static function group(): string { @@ -22,7 +21,6 @@ class TicketSettings extends Settings { return [ 'enabled' => 'nullable|boolean', - 'notify' => 'nullable|string', ]; } @@ -40,17 +38,6 @@ class TicketSettings extends Settings 'type' => 'boolean', 'description' => 'Enable or disable the ticket system.', ], - 'notify' => [ - 'label' => 'Notify', - 'type' => 'select', - 'description' => 'Who will receive an E-Mail when a new Ticket is created.', - 'options' => [ - 'admin' => 'Admins', - 'moderator' => 'Moderators', - 'all' => 'Admins and Moderators', - 'none' => 'Nobody', - ], - ], ]; } } diff --git a/config/permissions_web.php b/config/permissions_web.php index 0de10271..71c1cd1e 100644 --- a/config/permissions_web.php +++ b/config/permissions_web.php @@ -15,6 +15,7 @@ return [ 'admin.ticket.read', 'admin.tickets.write', + 'admin.tickets.get_notification', 'admin.ticket_blacklist.read', 'admin.ticket_blacklist.write',