2017-06-19 01:07:57 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Icinga\Module\Director\Web\Tabs;
|
|
|
|
|
|
|
|
use Icinga\Authentication\Auth;
|
2023-02-22 11:46:24 +01:00
|
|
|
use Icinga\Module\Director\Auth\Permission;
|
2017-06-19 01:07:57 +02:00
|
|
|
use Icinga\Module\Director\Objects\IcingaObject;
|
2019-05-02 13:23:06 +02:00
|
|
|
use gipfl\Translation\TranslationHelper;
|
|
|
|
use gipfl\IcingaWeb2\Widget\Tabs;
|
2017-06-19 01:07:57 +02:00
|
|
|
|
|
|
|
class ObjectsTabs extends Tabs
|
|
|
|
{
|
|
|
|
use TranslationHelper;
|
|
|
|
|
2018-06-15 02:08:06 +02:00
|
|
|
public function __construct($type, Auth $auth, $typeUrl)
|
2017-06-19 01:07:57 +02:00
|
|
|
{
|
|
|
|
$object = IcingaObject::createByType($type);
|
|
|
|
if ($object->isGroup()) {
|
2018-06-15 02:08:06 +02:00
|
|
|
$object = IcingaObject::createByType(substr($typeUrl, 0, -5));
|
2017-06-19 01:07:57 +02:00
|
|
|
}
|
2019-04-12 11:58:09 +02:00
|
|
|
$shortName = $object->getShortTableName();
|
2017-06-19 01:07:57 +02:00
|
|
|
|
2019-04-12 11:58:09 +02:00
|
|
|
$plType = strtolower(preg_replace('/cys$/', 'cies', $shortName . 's'));
|
2021-04-23 12:33:42 +02:00
|
|
|
$plType = str_replace('_', '-', $plType);
|
2023-02-22 11:46:24 +01:00
|
|
|
if ($auth->hasPermission("director/{$plType}")) {
|
|
|
|
$this->add('index', [
|
2017-08-25 22:42:38 +02:00
|
|
|
'url' => sprintf('director/%s', $plType),
|
|
|
|
'label' => $this->translate(ucfirst($plType)),
|
2023-02-22 11:46:24 +01:00
|
|
|
]);
|
2017-08-07 11:00:59 +02:00
|
|
|
}
|
2017-06-19 01:07:57 +02:00
|
|
|
|
2017-07-31 10:37:08 +02:00
|
|
|
if ($object->getShortTableName() === 'command') {
|
2023-02-22 11:46:24 +01:00
|
|
|
$this->add('external', [
|
|
|
|
'url' => sprintf('director/%s', strtolower($plType)),
|
2017-07-31 10:37:08 +02:00
|
|
|
'urlParams' => ['type' => 'external_object'],
|
2023-02-22 11:46:24 +01:00
|
|
|
'label' => $this->translate('External'),
|
|
|
|
]);
|
2017-07-31 10:37:08 +02:00
|
|
|
}
|
|
|
|
|
2024-10-22 14:31:14 +02:00
|
|
|
if (
|
|
|
|
$auth->hasPermission(Permission::ADMIN)
|
2023-02-22 11:46:24 +01:00
|
|
|
|| (
|
2017-08-25 22:42:38 +02:00
|
|
|
$object->getShortTableName() === 'notification'
|
2023-02-22 11:46:24 +01:00
|
|
|
&& $auth->hasPermission(Permission::NOTIFICATIONS)
|
2024-10-22 14:31:14 +02:00
|
|
|
) || (
|
2021-04-23 12:33:42 +02:00
|
|
|
$object->getShortTableName() === 'scheduled_downtime'
|
2023-02-22 11:46:24 +01:00
|
|
|
&& $auth->hasPermission(Permission::SCHEDULED_DOWNTIMES)
|
2024-10-22 14:31:14 +02:00
|
|
|
)
|
|
|
|
) {
|
2017-07-28 22:42:16 +02:00
|
|
|
if ($object->supportsApplyRules()) {
|
2023-02-22 11:46:24 +01:00
|
|
|
$this->add('applyrules', [
|
|
|
|
'url' => sprintf('director/%s/applyrules', $plType),
|
2017-07-28 22:42:16 +02:00
|
|
|
'label' => $this->translate('Apply')
|
2023-02-22 11:46:24 +01:00
|
|
|
]);
|
2017-07-28 22:42:16 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-22 11:46:24 +01:00
|
|
|
if ($auth->hasPermission(Permission::ADMIN) && $type !== 'zone') {
|
2017-06-19 01:07:57 +02:00
|
|
|
if ($object->supportsImports()) {
|
2023-02-22 11:46:24 +01:00
|
|
|
$this->add('templates', [
|
|
|
|
'url' => sprintf('director/%s/templates', $plType),
|
2017-06-19 01:07:57 +02:00
|
|
|
'label' => $this->translate('Templates'),
|
2023-02-22 11:46:24 +01:00
|
|
|
]);
|
2017-06-19 01:07:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($object->supportsGroups()) {
|
2023-02-22 11:46:24 +01:00
|
|
|
$this->add('groups', [
|
|
|
|
'url' => sprintf('director/%sgroups', $typeUrl),
|
2017-06-19 01:07:57 +02:00
|
|
|
'label' => $this->translate('Groups')
|
2023-02-22 11:46:24 +01:00
|
|
|
]);
|
2017-06-19 01:07:57 +02:00
|
|
|
}
|
2017-07-14 11:26:59 +02:00
|
|
|
}
|
2017-06-19 01:07:57 +02:00
|
|
|
|
2023-02-22 11:46:24 +01:00
|
|
|
if ($auth->hasPermission(Permission::ADMIN)) {
|
2017-06-29 14:06:32 +02:00
|
|
|
if ($object->supportsChoices()) {
|
2023-02-22 11:46:24 +01:00
|
|
|
$this->add('choices', [
|
|
|
|
'url' => sprintf('director/templatechoices/%s', $shortName),
|
2017-06-29 14:06:32 +02:00
|
|
|
'label' => $this->translate('Choices')
|
2023-02-22 11:46:24 +01:00
|
|
|
]);
|
2017-06-29 14:06:32 +02:00
|
|
|
}
|
2017-08-07 11:00:59 +02:00
|
|
|
}
|
2023-07-19 10:30:13 +02:00
|
|
|
if ($object->supportsSets() && $auth->hasPermission("director/{$typeUrl}sets")) {
|
2023-02-22 11:46:24 +01:00
|
|
|
$this->add('sets', [
|
|
|
|
'url' => sprintf('director/%s/sets', $plType),
|
2017-08-07 11:00:59 +02:00
|
|
|
'label' => $this->translate('Sets')
|
2023-02-22 11:46:24 +01:00
|
|
|
]);
|
2017-06-19 01:07:57 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|