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:
Hosteroid
2025-10-20 17:25:02 +03:00
parent 6fbed15c7d
commit 0d4a38aae8
10 changed files with 163 additions and 126 deletions

View File

@@ -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
}