icingaweb2-module-director/library/Director/Web/Tabs/ObjectsTabs.php

86 lines
3.0 KiB
PHP
Raw Normal View History

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;
use gipfl\Translation\TranslationHelper;
use gipfl\IcingaWeb2\Widget\Tabs;
2017-06-19 01:07:57 +02:00
class ObjectsTabs extends Tabs
{
use TranslationHelper;
public function __construct($type, Auth $auth, $typeUrl)
2017-06-19 01:07:57 +02:00
{
$object = IcingaObject::createByType($type);
if ($object->isGroup()) {
$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'));
$plType = str_replace('_', '-', $plType);
if ($auth->hasPermission("director/${plType}")) {
$this->add('index', array(
'url' => sprintf('director/%s', $plType),
'label' => $this->translate(ucfirst($plType)),
));
}
2017-06-19 01:07:57 +02:00
if ($object->getShortTableName() === 'command') {
$this->add('external', array(
'url' => sprintf('director/%s', strtolower($plType)),
'urlParams' => ['type' => 'external_object'],
'label' => $this->translate('External'),
));
}
if ($auth->hasPermission('director/admin') || (
$object->getShortTableName() === 'notification'
&& $auth->hasPermission('director/notifications')
) || (
$object->getShortTableName() === 'scheduled_downtime'
&& $auth->hasPermission('director/scheduled-downtimes')
)) {
if ($object->supportsApplyRules()) {
$this->add('applyrules', array(
'url' => sprintf('director/%s/applyrules', $plType),
'label' => $this->translate('Apply')
));
}
}
if ($auth->hasPermission('director/admin') && $type !== 'zone') {
2017-06-19 01:07:57 +02:00
if ($object->supportsImports()) {
$this->add('templates', array(
'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(
'url' => sprintf('director/%sgroups', $typeUrl),
2017-06-19 01:07:57 +02:00
'label' => $this->translate('Groups')
));
}
}
2017-06-19 01:07:57 +02:00
if ($auth->hasPermission('director/admin')) {
if ($object->supportsChoices()) {
$this->add('choices', array(
2019-04-12 11:58:09 +02:00
'url' => sprintf('director/templatechoices/%s', $shortName),
'label' => $this->translate('Choices')
));
}
}
if ($object->supportsSets() && $auth->hasPermission("director/${typeUrl}sets")) {
$this->add('sets', array(
'url' => sprintf('director/%s/sets', $plType),
'label' => $this->translate('Sets')
));
2017-06-19 01:07:57 +02:00
}
}
}