From 014f9b9dbe89f1737875e6e6d2ae564d0513e5f5 Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Fri, 13 Jul 2018 10:35:28 +0200 Subject: [PATCH] UserGroups: allow to specify zones fixes #1163 --- application/forms/IcingaUserGroupForm.php | 24 ++++++++++++------- doc/82-Changelog.md | 1 + .../Director/Objects/IcingaObjectGroup.php | 6 ++--- library/Director/Objects/IcingaUserGroup.php | 10 ++++---- schema/mysql-migrations/upgrade_149.sql | 11 +++++++++ schema/mysql.sql | 8 ++++++- schema/pgsql-migrations/upgrade_149.sql | 14 +++++++++++ schema/pgsql.sql | 9 ++++++- 8 files changed, 62 insertions(+), 21 deletions(-) create mode 100644 schema/mysql-migrations/upgrade_149.sql create mode 100644 schema/pgsql-migrations/upgrade_149.sql diff --git a/application/forms/IcingaUserGroupForm.php b/application/forms/IcingaUserGroupForm.php index 91f47de0..d93cc56d 100644 --- a/application/forms/IcingaUserGroupForm.php +++ b/application/forms/IcingaUserGroupForm.php @@ -6,6 +6,9 @@ use Icinga\Module\Director\Web\Form\DirectorObjectForm; class IcingaUserGroupForm extends DirectorObjectForm { + /** + * @throws \Zend_Form_Exception + */ public function setup() { $this->addHidden('object_type', 'object'); @@ -17,24 +20,27 @@ class IcingaUserGroupForm extends DirectorObjectForm )); $this->addGroupDisplayNameElement() - // TODO: re-add this once we have zone_id in groups tables - // ->addZoneElements() + ->addZoneElements() ->groupMainProperties() ->setButtons(); } + /** + * @return $this + * @throws \Zend_Form_Exception + */ protected function addZoneElements() { - $this->addZoneElement(); - $this->addDisplayGroup(array('zone_id'), 'clustering', array( - 'decorators' => array( + $this->addZoneElement(true); + $this->addDisplayGroup(['zone_id'], 'clustering', [ + 'decorators' => [ 'FormElements', - array('HtmlTag', array('tag' => 'dl')), + ['HtmlTag', ['tag' => 'dl']], 'Fieldset', - ), - 'order' => 80, + ], + 'order' => 80, 'legend' => $this->translate('Zone settings') - )); + ]); return $this; } diff --git a/doc/82-Changelog.md b/doc/82-Changelog.md index 4946c283..7350bf05 100644 --- a/doc/82-Changelog.md +++ b/doc/82-Changelog.md @@ -25,6 +25,7 @@ before switching to a new version. single hosts (#907) * FEATURE: timestamped startup log rendering for upcoming Icinga v2.9.0 (#1478) * FEATURE: allow to switch between multiple Director databases (#1498) +* FEATURE: it's now possible to specify Zones for UserGroups (#1163) ### User Interface * FEATURE: Admins have now access to JSON download links in many places diff --git a/library/Director/Objects/IcingaObjectGroup.php b/library/Director/Objects/IcingaObjectGroup.php index 93a606cb..ef2486fe 100644 --- a/library/Director/Objects/IcingaObjectGroup.php +++ b/library/Director/Objects/IcingaObjectGroup.php @@ -2,8 +2,6 @@ namespace Icinga\Module\Director\Objects; -use Icinga\Module\Director\IcingaConfig\IcingaConfig; - abstract class IcingaObjectGroup extends IcingaObject { protected $supportsImports = true; @@ -19,8 +17,8 @@ abstract class IcingaObjectGroup extends IcingaObject 'assign_filter' => null, ]; - public function getRenderingZone(IcingaConfig $config = null) + protected function prefersGlobalZone() { - return $this->connection->getDefaultGlobalZoneName(); + return true; } } diff --git a/library/Director/Objects/IcingaUserGroup.php b/library/Director/Objects/IcingaUserGroup.php index 93428be6..b9440476 100644 --- a/library/Director/Objects/IcingaUserGroup.php +++ b/library/Director/Objects/IcingaUserGroup.php @@ -2,8 +2,6 @@ namespace Icinga\Module\Director\Objects; -use Icinga\Module\Director\IcingaConfig\IcingaConfig; - class IcingaUserGroup extends IcingaObjectGroup { protected $table = 'icinga_usergroup'; @@ -14,10 +12,10 @@ class IcingaUserGroup extends IcingaObjectGroup 'object_type' => null, 'disabled' => 'n', 'display_name' => null, + 'zone_id' => null, ]; - public function getRenderingZone(IcingaConfig $config = null) - { - return $this->connection->getMasterZoneName(); - } + protected $relations = [ + 'zone' => 'IcingaZone', + ]; } diff --git a/schema/mysql-migrations/upgrade_149.sql b/schema/mysql-migrations/upgrade_149.sql new file mode 100644 index 00000000..59403115 --- /dev/null +++ b/schema/mysql-migrations/upgrade_149.sql @@ -0,0 +1,11 @@ +ALTER TABLE icinga_usergroup + ADD COLUMN zone_id INT(10) UNSIGNED DEFAULT NULL, + ADD CONSTRAINT icinga_usergroup_zone + FOREIGN KEY zone (zone_id) + REFERENCES icinga_zone (id) + ON DELETE RESTRICT + ON UPDATE CASCADE; + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (149, NOW()); diff --git a/schema/mysql.sql b/schema/mysql.sql index 375a4e4a..dfb4f43c 100644 --- a/schema/mysql.sql +++ b/schema/mysql.sql @@ -1044,9 +1044,15 @@ CREATE TABLE icinga_usergroup ( object_type ENUM('object', 'template') NOT NULL, disabled ENUM('y', 'n') NOT NULL DEFAULT 'n', display_name VARCHAR(255) DEFAULT NULL, + zone_id INT(10) UNSIGNED DEFAULT NULL, PRIMARY KEY (id), UNIQUE INDEX object_name (object_name), - KEY search_idx (display_name) + KEY search_idx (display_name), + CONSTRAINT icinga_usergroup_zone + FOREIGN KEY zone (zone_id) + REFERENCES icinga_zone (id) + ON DELETE RESTRICT + ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8; CREATE TABLE icinga_usergroup_inheritance ( diff --git a/schema/pgsql-migrations/upgrade_149.sql b/schema/pgsql-migrations/upgrade_149.sql new file mode 100644 index 00000000..9fe8d5ed --- /dev/null +++ b/schema/pgsql-migrations/upgrade_149.sql @@ -0,0 +1,14 @@ +ALTER TABLE icinga_usergroup + ADD COLUMN zone_id integer DEFAULT NULL, + ADD CONSTRAINT icinga_usergroup_zone + FOREIGN KEY (zone_id) + REFERENCES icinga_zone (id) + ON DELETE RESTRICT + ON UPDATE CASCADE; + +CREATE INDEX usergroup_zone ON icinga_usergroup (zone_id); + + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (149, NOW()); diff --git a/schema/pgsql.sql b/schema/pgsql.sql index 83b1d71a..d195dc49 100644 --- a/schema/pgsql.sql +++ b/schema/pgsql.sql @@ -1267,11 +1267,18 @@ CREATE TABLE icinga_usergroup ( object_type enum_object_type_all NOT NULL, disabled enum_boolean NOT NULL DEFAULT 'n', display_name character varying(255) DEFAULT NULL, - PRIMARY KEY (id) + zone_id integer DEFAULT NULL, + PRIMARY KEY (id), + CONSTRAINT icinga_usergroup_zone + FOREIGN KEY (zone_id) + REFERENCES icinga_zone (id) + ON DELETE RESTRICT + ON UPDATE CASCADE ); CREATE UNIQUE INDEX usergroup_search_idx ON icinga_usergroup (display_name); CREATE INDEX usergroup_object_name ON icinga_usergroup (object_name); +CREATE INDEX usergroup_zone ON icinga_usergroup (zone_id); CREATE TABLE icinga_usergroup_inheritance (