ObjectsController: Unify feature detection and setAction

Groups, Assign and Sets will be checked on the base Object for a group.

refs #12891
This commit is contained in:
Markus Frosch 2016-11-07 17:27:01 +01:00
parent 67411c3a4a
commit b051b2da17

View File

@ -51,6 +51,12 @@ abstract class ObjectsController extends ActionController
$object = $this->dummyObject(); $object = $this->dummyObject();
if ($object->isGroup()) { if ($object->isGroup()) {
$type = substr($type, 0, -5); $type = substr($type, 0, -5);
/** @var IcingaObject $baseType */
$baseType = $this->getObjectClassname($type);
$baseObject = $baseType::create(array());
}
else {
$baseObject = $object;
} }
$tabs->add('objects', array( $tabs->add('objects', array(
@ -66,14 +72,14 @@ abstract class ObjectsController extends ActionController
)); ));
} }
if ($object->supportsGroups() || $object->isGroup()) { if ($baseObject->supportsGroups()) {
$tabs->add('objectgroups', array( $tabs->add('objectgroups', array(
'url' => sprintf('director/%sgroups', $type), 'url' => sprintf('director/%sgroups', $type),
'label' => $this->translate('Groups') 'label' => $this->translate('Groups')
)); ));
} }
if ($object->supportsSets() || $object->isGroup() /** Bullshit, need base object, wrong on users */) { if ($baseObject->supportsSets()) {
$tabs->add('sets', array( $tabs->add('sets', array(
'url' => sprintf('director/%ss/sets', $type), 'url' => sprintf('director/%ss/sets', $type),
'label' => $this->translate('Sets') 'label' => $this->translate('Sets')
@ -202,14 +208,23 @@ abstract class ObjectsController extends ActionController
public function setsAction() public function setsAction()
{ {
$this->assertPermission('director/admin'); $this->assertPermission('director/admin');
$this->view->title = $this->translate('Service sets');
$dummy = $this->dummyObject();
$type = $this->getType();
$Type = ucfirst($type);
if ($dummy->supportsSets() !== true) {
throw new NotFoundError('Sets are not available for %s', $type);
}
$this->view->title = $this->translate('Icinga ' . $Type . ' Sets');
$this->view->table = $this $this->view->table = $this
->loadTable('IcingaServiceSet') ->loadTable('Icinga' . $Type . 'Set')
->setConnection($this->db()); ->setConnection($this->db());
$this->view->addLink = $this->view->qlink( $this->view->addLink = $this->view->qlink(
$this->translate('Add'), $this->translate('Add'),
'director/serviceset/add', 'director/' . $type . 'set/add',
null, null,
array( array(
'class' => 'icon-plus', 'class' => 'icon-plus',
@ -227,6 +242,7 @@ abstract class ObjectsController extends ActionController
protected function dummyObject() protected function dummyObject()
{ {
if ($this->dummy === null) { if ($this->dummy === null) {
/** @var IcingaObject $class */
$class = $this->getObjectClassname(); $class = $this->getObjectClassname();
$this->dummy = $class::create(array()); $this->dummy = $class::create(array());
if ($this->dummy->hasProperty('object_type')) { if ($this->dummy->hasProperty('object_type')) {
@ -257,9 +273,12 @@ abstract class ObjectsController extends ActionController
); );
} }
protected function getObjectClassname() protected function getObjectClassname($type = null)
{ {
if ($type === null) {
$type = $this->getType();
}
return 'Icinga\\Module\\Director\\Objects\\Icinga' return 'Icinga\\Module\\Director\\Objects\\Icinga'
. ucfirst($this->getType()); . ucfirst($type);
} }
} }