From 18d4962ef983053a1830a5ce8e3b859535d1c14a Mon Sep 17 00:00:00 2001 From: IceToast Date: Tue, 4 Apr 2023 01:26:34 +0200 Subject: [PATCH] =?UTF-8?q?fix:=20=F0=9F=94=92=EF=B8=8F=20Do=20not=20allow?= =?UTF-8?q?=20last=20admin=20deletion=20#762?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Http/Controllers/Admin/UserController.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/app/Http/Controllers/Admin/UserController.php b/app/Http/Controllers/Admin/UserController.php index eafc351d..4dfcb219 100644 --- a/app/Http/Controllers/Admin/UserController.php +++ b/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())); }