load dashboard based on rolename(s)

We link the icingaweb (icingadb) to a Microsoft AD and there will be more than 500 possible users.
In order not to have to create a dashboard for every user, I propose these modifications.

If the user does not have his own dashboard, and the user is linked to a role(s) that has a dashboard folder based on the role name, he will load it.

If there is no user or role dashboard and a default folder with a dashboard exists, it will use it.
This commit is contained in:
gbin2265 2023-08-06 22:07:39 +02:00 committed by GitHub
parent 4ccebb78b5
commit aaf95c1083
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 47 additions and 16 deletions

View File

@ -71,6 +71,37 @@ class DashboardConfig extends Config
} }
closedir($handle); closedir($handle);
} }
if (empty($files)) {
$roles = $user->getRoles();
if (! empty($roles)) {
foreach($roles as $role) {
if ($handle = @opendir($dashboards)) {
while (false !== ($entry = readdir($handle))) {
if ($entry[0] === '.' || ! is_dir($dashboards . '/' . $entry)) {
continue;
}
if (strtolower($entry) === strtolower($role->getName())) {
$files[] = $dashboards . '/' . $entry . '/dashboard.ini';
}
}
closedir($handle);
}
}
}
}
if (empty($files)) {
if ($handle = @opendir($dashboards)) {
while (false !== ($entry = readdir($handle))) {
if ($entry[0] === '.' || ! is_dir($dashboards . '/' . $entry)) {
continue;
}
if (strtolower($entry) === 'default') {
$files[] = $dashboards . '/default/dashboard.ini';
}
}
closedir($handle);
}
}
return $files; return $files;
} }