UserGroups: allow to specify zones

fixes #1163
This commit is contained in:
Thomas Gelf 2018-07-13 10:35:28 +02:00
parent 137a21b7e2
commit 014f9b9dbe
8 changed files with 62 additions and 21 deletions

View File

@ -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;
}

View File

@ -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

View File

@ -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;
}
}

View File

@ -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',
];
}

View File

@ -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());

View File

@ -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 (

View File

@ -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());

View File

@ -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 (