fix: 🔒️ Do not allow last admin deletion #762
This commit is contained in:
parent
307f3229d2
commit
18d4962ef9
|
@ -35,7 +35,7 @@ class UserController extends Controller
|
||||||
{
|
{
|
||||||
$this->pterodactyl = new PterodactylClient($ptero_settings);
|
$this->pterodactyl = new PterodactylClient($ptero_settings);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Display a listing of the resource.
|
* Display a listing of the resource.
|
||||||
*
|
*
|
||||||
|
@ -166,6 +166,10 @@ class UserController extends Controller
|
||||||
*/
|
*/
|
||||||
public function destroy(User $user)
|
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();
|
$user->delete();
|
||||||
|
|
||||||
return redirect()->back()->with('success', __('user has been removed!'));
|
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();
|
$users = $all ? User::all() : User::whereIn('id', $data['users'])->get();
|
||||||
try {
|
try {
|
||||||
Notification::send($users, new DynamicNotification($data['via'], $database, $mail));
|
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()));
|
return redirect()->route('admin.users.notifications')->with('error', __('The attempt to send the email failed with the error: ' . $e->getMessage()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue