Dashboard stats now scoped to user's accessible servers; super_admin sees all
This commit is contained in:
@@ -25,15 +25,22 @@ class DashboardController
|
||||
|
||||
public function index(): void
|
||||
{
|
||||
$stats = $this->monitoringService->getDashboardStats();
|
||||
$recentActivity = $this->auditService->getRecentActivity(10);
|
||||
|
||||
$role = Session::get('user_role');
|
||||
$serverModel = new Server();
|
||||
$userId = (int) Session::get('user_id');
|
||||
$accessibleIds = $serverModel->getAccessibleServerIds($userId);
|
||||
$servers = !empty($accessibleIds) ? array_values(array_filter($serverModel->findAll(true), function ($s) use ($accessibleIds) {
|
||||
return in_array((int) $s['id'], $accessibleIds, true);
|
||||
})) : [];
|
||||
|
||||
if ($role === 'super_admin') {
|
||||
$stats = $this->monitoringService->getDashboardStats();
|
||||
$servers = $serverModel->findAll(true);
|
||||
} else {
|
||||
$accessibleIds = $serverModel->getAccessibleServerIds($userId);
|
||||
$stats = $this->monitoringService->getDashboardStats($accessibleIds);
|
||||
$servers = !empty($accessibleIds) ? array_values(array_filter($serverModel->findAll(true), function ($s) use ($accessibleIds) {
|
||||
return in_array((int) $s['id'], $accessibleIds, true);
|
||||
})) : [];
|
||||
}
|
||||
|
||||
$recentActivity = $this->auditService->getRecentActivity(10);
|
||||
|
||||
$this->view->display('dashboard.index', [
|
||||
'title' => 'Dashboard - ServerManager',
|
||||
@@ -45,7 +52,15 @@ class DashboardController
|
||||
|
||||
public function stats(): void
|
||||
{
|
||||
$stats = $this->monitoringService->getDashboardStats();
|
||||
$role = Session::get('user_role');
|
||||
|
||||
if ($role === 'super_admin') {
|
||||
$stats = $this->monitoringService->getDashboardStats();
|
||||
} else {
|
||||
$serverModel = new Server();
|
||||
$accessibleIds = $serverModel->getAccessibleServerIds((int) Session::get('user_id'));
|
||||
$stats = $this->monitoringService->getDashboardStats($accessibleIds);
|
||||
}
|
||||
|
||||
$this->view->json([
|
||||
'success' => true,
|
||||
|
||||
Reference in New Issue
Block a user