Browse Source

ticket notify permission

1day2die 2 years ago
parent
commit
d41d0a6e2d

+ 11 - 12
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'));
     }

+ 0 - 13
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',
-                ],
-            ],
         ];
     }
 }

+ 1 - 0
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',