Ver Fonte

fix: 🔒️ Do not allow last admin deletion #762

IceToast há 2 anos atrás
pai
commit
18d4962ef9
1 ficheiros alterados com 6 adições e 3 exclusões
  1. 6 3
      app/Http/Controllers/Admin/UserController.php

+ 6 - 3
app/Http/Controllers/Admin/UserController.php

@@ -35,7 +35,7 @@ class UserController extends Controller
     {
         $this->pterodactyl = new PterodactylClient($ptero_settings);
     }
-    
+
     /**
      * Display a listing of the resource.
      *
@@ -166,6 +166,10 @@ class UserController extends Controller
      */
     public function destroy(User $user)
     {
+        if ($user->role === 'admin' && User::query()->where('role', 'admin')->count() === 1) {
+            return redirect()->back()->with('error', __('You can not delete the last admin!'));
+        }
+
         $user->delete();
 
         return redirect()->back()->with('success', __('user has been removed!'));
@@ -258,8 +262,7 @@ class UserController extends Controller
         $users = $all ? User::all() : User::whereIn('id', $data['users'])->get();
         try {
             Notification::send($users, new DynamicNotification($data['via'], $database, $mail));
-        }
-        catch (Exception $e) {
+        } catch (Exception $e) {
             return redirect()->route('admin.users.notifications')->with('error', __('The attempt to send the email failed with the error: ' . $e->getMessage()));
         }