[icinga-checkins] icinga.org: icingaweb2-module-director/feature/service-sets-12891: ObjectsController: Unify feature detection and setAction

git at icinga.org git at icinga.org
Fri Nov 11 10:44:28 CET 2016


Module: icingaweb2-module-director
Branch: feature/service-sets-12891
Commit: b051b2da17838674afa472feae32d400c1fb8d05
URL:    https://git.icinga.org/?p=icingaweb2-module-director.git;a=commit;h=b051b2da17838674afa472feae32d400c1fb8d05

Author: Markus Frosch <markus.frosch at icinga.com>
Date:   Mon Nov  7 17:27:01 2016 +0100

ObjectsController: Unify feature detection and setAction

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

refs #12891

---

 .../Director/Web/Controller/ObjectsController.php  |   33 +++++++++++++++-----
 1 file changed, 26 insertions(+), 7 deletions(-)

diff --git a/library/Director/Web/Controller/ObjectsController.php b/library/Director/Web/Controller/ObjectsController.php
index bc80e24..2feb738 100644
--- a/library/Director/Web/Controller/ObjectsController.php
+++ b/library/Director/Web/Controller/ObjectsController.php
@@ -51,6 +51,12 @@ abstract class ObjectsController extends ActionController
         $object = $this->dummyObject();
         if ($object->isGroup()) {
             $type = substr($type, 0, -5);
+            /** @var IcingaObject $baseType */
+            $baseType = $this->getObjectClassname($type);
+            $baseObject = $baseType::create(array());
+        }
+        else {
+            $baseObject = $object;
         }
 
         $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(
                     'url'   => sprintf('director/%sgroups', $type),
                     'label' => $this->translate('Groups')
                 ));
             }
 
-            if ($object->supportsSets() || $object->isGroup() /** Bullshit, need base object, wrong on users */) {
+            if ($baseObject->supportsSets()) {
                  $tabs->add('sets', array(
                       'url'    => sprintf('director/%ss/sets', $type),
                       'label' => $this->translate('Sets')
@@ -202,14 +208,23 @@ abstract class ObjectsController extends ActionController
     public function setsAction()
     {
         $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
-            ->loadTable('IcingaServiceSet')
+            ->loadTable('Icinga' . $Type . 'Set')
             ->setConnection($this->db());
 
         $this->view->addLink = $this->view->qlink(
             $this->translate('Add'),
-            'director/serviceset/add',
+            'director/' . $type . 'set/add',
             null,
             array(
                 'class'            => 'icon-plus',
@@ -227,6 +242,7 @@ abstract class ObjectsController extends ActionController
     protected function dummyObject()
     {
         if ($this->dummy === null) {
+            /** @var IcingaObject $class */
             $class = $this->getObjectClassname();
             $this->dummy = $class::create(array());
             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'
-            . ucfirst($this->getType());
+            . ucfirst($type);
     }
 }



More information about the icinga-checkins mailing list