Unify Service/Host/UserGroup code for Objects and Forms

At least as far as possible.

For objects, moved some common parts to IcingaObjectGroup, where zone_id
is now in defaultProperties and thus those don't need to be overriden in
IcingaHostGroup and IcingaServiceGroup anymore. Similar for relations
property, which don't need to be specified in descendant classes
anymore.

For forms, created a intermediate class IcingaGroupForm (analog to the
already existing IcingaObjectGroup for objects) which extends
DirectorObjectForm, and made IcingaHostGroupForm,
IcingaServiceGroupForm and IcingaUserGroupForm extend this new class
instead. Moved the addZoneElements method to this new class (although
it's not used by IcingaUserGroupForm), thus removing it from the
descendant classes that had it repeated.
This commit is contained in:
Rodrigo Araujo 2024-04-09 15:38:01 +01:00
parent 1e9a40e82e
commit 190c921d82
8 changed files with 42 additions and 93 deletions

View File

@ -0,0 +1,28 @@
<?php
namespace Icinga\Module\Director\Forms;
use Icinga\Module\Director\Web\Form\DirectorObjectForm;
class IcingaGroupForm extends DirectorObjectForm
{
/**
* @return $this
* @throws \Zend_Form_Exception
*/
protected function addZoneElements()
{
$this->addZoneElement(true);
$this->addDisplayGroup(['zone_id'], 'clustering', [
'decorators' => [
'FormElements',
['HtmlTag', ['tag' => 'dl']],
'Fieldset',
],
'order' => self::GROUP_ORDER_CLUSTERING,
'legend' => $this->translate('Zone settings')
]);
return $this;
}
}

View File

@ -2,10 +2,11 @@
namespace Icinga\Module\Director\Forms;
use Icinga\Module\Director\Web\Form\DirectorObjectForm;
class IcingaHostGroupForm extends DirectorObjectForm
class IcingaHostGroupForm extends IcingaGroupForm
{
/**
* @throws \Zend_Form_Exception
*/
public function setup()
{
$this->addHidden('object_type', 'object');
@ -22,21 +23,6 @@ class IcingaHostGroupForm extends DirectorObjectForm
->setButtons();
}
protected function addZoneElements()
{
$this->addZoneElement(true);
$this->addDisplayGroup(['zone_id'], 'clustering', [
'decorators' => [
'FormElements',
['HtmlTag', ['tag' => 'dl']],
'Fieldset',
],
'order' => 80,
'legend' => $this->translate('Zone settings'),
]);
return $this;
}
protected function addAssignmentElements()
{
$this->addAssignFilter([

View File

@ -2,10 +2,11 @@
namespace Icinga\Module\Director\Forms;
use Icinga\Module\Director\Web\Form\DirectorObjectForm;
class IcingaServiceGroupForm extends DirectorObjectForm
class IcingaServiceGroupForm extends IcingaGroupForm
{
/**
* @throws \Zend_Form_Exception
*/
public function setup()
{
$this->addHidden('object_type', 'object');
@ -22,21 +23,6 @@ class IcingaServiceGroupForm extends DirectorObjectForm
->setButtons();
}
protected function addZoneElements()
{
$this->addZoneElement(true);
$this->addDisplayGroup(['zone_id'], 'clustering', [
'decorators' => [
'FormElements',
['HtmlTag', ['tag' => 'dl']],
'Fieldset',
],
'order' => 80,
'legend' => $this->translate('Zone settings'),
]);
return $this;
}
protected function addAssignmentElements()
{
$this->addAssignFilter([

View File

@ -2,9 +2,7 @@
namespace Icinga\Module\Director\Forms;
use Icinga\Module\Director\Web\Form\DirectorObjectForm;
class IcingaUserGroupForm extends DirectorObjectForm
class IcingaUserGroupForm extends IcingaGroupForm
{
/**
* @throws \Zend_Form_Exception
@ -24,24 +22,4 @@ class IcingaUserGroupForm extends DirectorObjectForm
->groupMainProperties()
->setButtons();
}
/**
* @return $this
* @throws \Zend_Form_Exception
*/
protected function addZoneElements()
{
$this->addZoneElement(true);
$this->addDisplayGroup(['zone_id'], 'clustering', [
'decorators' => [
'FormElements',
['HtmlTag', ['tag' => 'dl']],
'Fieldset',
],
'order' => self::GROUP_ORDER_CLUSTERING,
'legend' => $this->translate('Zone settings')
]);
return $this;
}
}

View File

@ -6,21 +6,6 @@ class IcingaHostGroup extends IcingaObjectGroup
{
protected $table = 'icinga_hostgroup';
protected $defaultProperties = [
'id' => null,
'uuid' => null,
'object_name' => null,
'object_type' => null,
'disabled' => 'n',
'display_name' => null,
'assign_filter' => null,
'zone_id' => null,
];
protected $relations = [
'zone' => 'IcingaZone',
];
/** @var HostGroupMembershipResolver */
protected $hostgroupMembershipResolver;

View File

@ -20,6 +20,11 @@ abstract class IcingaObjectGroup extends IcingaObject implements ExportInterface
'disabled' => 'n',
'display_name' => null,
'assign_filter' => null,
'zone_id' => null,
];
protected $relations = [
'zone' => 'IcingaZone',
];
protected $memberShipShouldBeRefreshed = false;

View File

@ -6,21 +6,6 @@ class IcingaServiceGroup extends IcingaObjectGroup
{
protected $table = 'icinga_servicegroup';
protected $defaultProperties = [
'id' => null,
'uuid' => null,
'object_name' => null,
'object_type' => null,
'disabled' => 'n',
'display_name' => null,
'assign_filter' => null,
'zone_id' => null,
];
protected $relations = [
'zone' => 'IcingaZone',
];
/** @var ServiceGroupMembershipResolver */
protected $servicegroupMembershipResolver;

View File

@ -18,10 +18,6 @@ class IcingaUserGroup extends IcingaObjectGroup
'zone_id' => null,
];
protected $relations = [
'zone' => 'IcingaZone',
];
protected function prefersGlobalZone()
{
return false;