Refactor admin/user isolation logic and model methods
Moved admin/user isolation checks and related methods from Domain and NotificationGroup models to User model for better separation of concerns. Replaced direct database queries in controllers and services with new model methods. Added methods for assigning unassigned domains/groups, searching domains, and clearing old notification logs. Updated views for improved UI consistency.
This commit is contained in:
@@ -320,7 +320,7 @@ class UserController extends Controller
|
||||
|
||||
// Prevent deleting the last admin
|
||||
if ($user['role'] === 'admin') {
|
||||
$allAdmins = $this->userModel->where('role', 'admin');
|
||||
$allAdmins = $this->userModel->getAllAdmins();
|
||||
if (count($allAdmins) <= 1) {
|
||||
$_SESSION['error'] = 'Cannot delete the last admin user';
|
||||
$this->redirect('/users');
|
||||
@@ -457,7 +457,7 @@ class UserController extends Controller
|
||||
// Prevent deleting if this is the last admin
|
||||
$user = $this->userModel->find((int)$userId);
|
||||
if ($user && $user['role'] === 'admin') {
|
||||
$allAdmins = $this->userModel->where('role', 'admin');
|
||||
$allAdmins = $this->userModel->getAllAdmins();
|
||||
if (count($allAdmins) <= 1) {
|
||||
continue; // Skip - can't delete last admin
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user