mirror of
https://github.com/Icinga/icingaweb2-module-director.git
synced 2025-07-28 16:24:05 +02:00
Icingadb (Host/Service)Actions: Fix permissions and code style
This commit is contained in:
parent
1048c33fa4
commit
26f8769d28
@ -4,6 +4,7 @@ namespace Icinga\Module\Director\ProvidedHook\Icingadb;
|
||||
|
||||
use Exception;
|
||||
use Icinga\Application\Config;
|
||||
use Icinga\Module\Director\Auth\Permission;
|
||||
use Icinga\Module\Director\Db;
|
||||
use Icinga\Module\Director\Integration\Icingadb\IcingadbBackend;
|
||||
use Icinga\Module\Director\Objects\IcingaHost;
|
||||
@ -20,30 +21,33 @@ class HostActions extends HostActionsHook
|
||||
try {
|
||||
return $this->getThem($host);
|
||||
} catch (Exception $e) {
|
||||
return array();
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
protected function getThem(Host $host): array
|
||||
{
|
||||
$actions = array();
|
||||
$actions = [];
|
||||
$db = $this->db();
|
||||
if (! $db) {
|
||||
return $actions;
|
||||
}
|
||||
$hostname = $host->name;
|
||||
if (Util::hasPermission('director/inspect')) {
|
||||
$actions[mt('director', 'Inspect')] = Url::fromPath(
|
||||
'director/inspect/object',
|
||||
array('type' => 'host', 'plural' => 'hosts', 'name' => $hostname)
|
||||
if (Util::hasPermission(Permission::INSPECT)) {
|
||||
$actions[] = new Link(
|
||||
mt('director', 'Inspect'),
|
||||
Url::fromPath(
|
||||
'director/inspect/object',
|
||||
['type' => 'host', 'plural' => 'hosts', 'name' => $hostname]
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
$allowEdit = false;
|
||||
if (Util::hasPermission('director/hosts') && IcingaHost::exists($hostname, $db)) {
|
||||
if (Util::hasPermission(Permission::HOSTS) && IcingaHost::exists($hostname, $db)) {
|
||||
$allowEdit = true;
|
||||
}
|
||||
if (Util::hasPermission('director/monitoring/hosts')) {
|
||||
if (Util::hasPermission(Permission::ICINGADB_HOSTS)) {
|
||||
if ((new IcingadbBackend())->canModifyHost($hostname)) {
|
||||
$allowEdit = IcingaHost::exists($hostname, $db);
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ namespace Icinga\Module\Director\ProvidedHook\Icingadb;
|
||||
|
||||
use Exception;
|
||||
use Icinga\Application\Config;
|
||||
use Icinga\Module\Director\Auth\Permission;
|
||||
use Icinga\Module\Director\Db;
|
||||
use Icinga\Module\Director\Integration\Icingadb\IcingadbBackend;
|
||||
use Icinga\Module\Director\Objects\IcingaHost;
|
||||
@ -20,7 +21,6 @@ class ServiceActions extends ServiceActionsHook
|
||||
try {
|
||||
return $this->getThem($service);
|
||||
} catch (Exception $e) {
|
||||
die($e);
|
||||
return [];
|
||||
}
|
||||
}
|
||||
@ -40,26 +40,25 @@ class ServiceActions extends ServiceActionsHook
|
||||
|
||||
$hostname = $service->host->name;
|
||||
$serviceName = $service->name;
|
||||
if (Util::hasPermission('director/inspect')) {
|
||||
$actions[mt('director', 'Inspect')] = Url::fromPath('director/inspect/object', [
|
||||
'type' => 'service',
|
||||
'plural' => 'services',
|
||||
'name' => sprintf(
|
||||
'%s!%s',
|
||||
$hostname,
|
||||
$serviceName
|
||||
)
|
||||
]);
|
||||
if (Util::hasPermission(Permission::INSPECT)) {
|
||||
$actions[] = new Link(
|
||||
mt('director', 'Inspect'),
|
||||
Url::fromPath('director/inspect/object', [
|
||||
'type' => 'service',
|
||||
'plural' => 'services',
|
||||
'name' => sprintf('%s!%s', $hostname, $serviceName)
|
||||
])
|
||||
);
|
||||
}
|
||||
|
||||
$title = null;
|
||||
if (Util::hasPermission('director/hosts')) {
|
||||
if (Util::hasPermission(Permission::HOSTS)) {
|
||||
$title = mt('director', 'Modify');
|
||||
} elseif (Util::hasPermission('director/monitoring/services')) {
|
||||
} elseif (Util::hasPermission(Permission::ICINGADB_SERVICES)) {
|
||||
if ((new IcingadbBackend())->canModifyService($hostname, $serviceName)) {
|
||||
$title = mt('director', 'Modify');
|
||||
}
|
||||
} elseif (Util::hasPermission('director/monitoring/services-ro')) {
|
||||
} elseif (Util::hasPermission(Permission::ICINGADB_SERVICES_RO)) {
|
||||
$title = mt('director', 'Configuration');
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user