2017-06-19 01:07:57 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Icinga\Module\Director\Web\Tabs;
|
|
|
|
|
|
|
|
use Icinga\Authentication\Auth;
|
|
|
|
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);
|
2017-08-25 22:42:38 +02:00
|
|
|
if ($auth->hasPermission("director/${plType}")) {
|
2017-08-07 11:00:59 +02:00
|
|
|
$this->add('index', array(
|
2017-08-25 22:42:38 +02:00
|
|
|
'url' => sprintf('director/%s', $plType),
|
|
|
|
'label' => $this->translate(ucfirst($plType)),
|
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') {
|
|
|
|
$this->add('external', array(
|
2017-08-25 22:42:38 +02:00
|
|
|
'url' => sprintf('director/%s', strtolower($plType)),
|
2017-07-31 10:37:08 +02:00
|
|
|
'urlParams' => ['type' => 'external_object'],
|
|
|
|
'label' => $this->translate('External'),
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
2017-07-28 22:42:16 +02:00
|
|
|
if ($auth->hasPermission('director/admin') || (
|
2017-08-25 22:42:38 +02:00
|
|
|
$object->getShortTableName() === 'notification'
|
|
|
|
&& $auth->hasPermission('director/notifications')
|
2021-04-23 12:33:42 +02:00
|
|
|
) || (
|
|
|
|
$object->getShortTableName() === 'scheduled_downtime'
|
|
|
|
&& $auth->hasPermission('director/scheduled-downtimes')
|
2017-08-25 22:42:38 +02:00
|
|
|
)) {
|
2017-07-28 22:42:16 +02:00
|
|
|
if ($object->supportsApplyRules()) {
|
|
|
|
$this->add('applyrules', array(
|
2017-08-25 22:42:38 +02:00
|
|
|
'url' => sprintf('director/%s/applyrules', $plType),
|
2017-07-28 22:42:16 +02:00
|
|
|
'label' => $this->translate('Apply')
|
|
|
|
));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-28 09:06:21 +02:00
|
|
|
if ($auth->hasPermission('director/admin') && $type !== 'zone') {
|
2017-06-19 01:07:57 +02:00
|
|
|
if ($object->supportsImports()) {
|
|
|
|
$this->add('templates', array(
|
2017-08-25 22:42:38 +02:00
|
|
|
'url' => sprintf('director/%s/templates', $plType),
|
2017-06-19 01:07:57 +02:00
|
|
|
'label' => $this->translate('Templates'),
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($object->supportsGroups()) {
|
|
|
|
$this->add('groups', array(
|
2018-06-15 02:08:06 +02:00
|
|
|
'url' => sprintf('director/%sgroups', $typeUrl),
|
2017-06-19 01:07:57 +02:00
|
|
|
'label' => $this->translate('Groups')
|
|
|
|
));
|
|
|
|
}
|
2017-07-14 11:26:59 +02:00
|
|
|
}
|
2017-06-19 01:07:57 +02:00
|
|
|
|
2017-07-14 11:26:59 +02:00
|
|
|
if ($auth->hasPermission('director/admin')) {
|
2017-06-29 14:06:32 +02:00
|
|
|
if ($object->supportsChoices()) {
|
|
|
|
$this->add('choices', array(
|
2019-04-12 11:58:09 +02:00
|
|
|
'url' => sprintf('director/templatechoices/%s', $shortName),
|
2017-06-29 14:06:32 +02:00
|
|
|
'label' => $this->translate('Choices')
|
|
|
|
));
|
|
|
|
}
|
2017-08-07 11:00:59 +02:00
|
|
|
}
|
2018-06-15 02:08:06 +02:00
|
|
|
if ($object->supportsSets() && $auth->hasPermission("director/${typeUrl}sets")) {
|
2017-08-07 11:00:59 +02:00
|
|
|
$this->add('sets', array(
|
2017-08-25 22:42:38 +02:00
|
|
|
'url' => sprintf('director/%s/sets', $plType),
|
2017-08-07 11:00:59 +02:00
|
|
|
'label' => $this->translate('Sets')
|
|
|
|
));
|
2017-06-19 01:07:57 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|