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

This commit is contained in:
IceToast 2023-04-04 01:26:34 +02:00
parent 307f3229d2
commit 18d4962ef9
No known key found for this signature in database
GPG key ID: 1464353E063A5B97

View file

@ -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()));
}