parent
5d52eaefd0
commit
550959d858
|
@ -3,7 +3,6 @@
|
|||
namespace Icinga\Module\Director\Forms;
|
||||
|
||||
use Icinga\Module\Director\Web\Form\DirectorObjectForm;
|
||||
use Icinga\Module\Director\Web\Form\Validate\NamePattern;
|
||||
|
||||
class IcingaNotificationForm extends DirectorObjectForm
|
||||
{
|
||||
|
@ -28,12 +27,9 @@ class IcingaNotificationForm extends DirectorObjectForm
|
|||
'description' => $this->translate('Name for the Icinga notification you are going to create')
|
||||
));
|
||||
|
||||
$rName = 'director/notification/apply/filter-by-name';
|
||||
foreach ($this->getAuth()->getRestrictions($rName) as $restriction) {
|
||||
$this->getElement('object_name')->addValidator(
|
||||
new NamePattern($restriction)
|
||||
);
|
||||
}
|
||||
$this->eventuallyAddNameRestriction(
|
||||
'director/notification/apply/filter-by-name'
|
||||
);
|
||||
}
|
||||
|
||||
$this->addDisabledElement()
|
||||
|
|
|
@ -10,7 +10,6 @@ use Icinga\Module\Director\Web\Form\DirectorObjectForm;
|
|||
use Icinga\Module\Director\Objects\IcingaHost;
|
||||
use Icinga\Module\Director\Objects\IcingaService;
|
||||
use Icinga\Module\Director\Objects\IcingaServiceSet;
|
||||
use Icinga\Module\Director\Web\Form\Validate\NamePattern;
|
||||
use dipl\Html\Html;
|
||||
use dipl\Html\Link;
|
||||
|
||||
|
@ -345,12 +344,7 @@ class IcingaServiceForm extends DirectorObjectForm
|
|||
));
|
||||
|
||||
if ($this->object()->isApplyRule()) {
|
||||
$rName = 'director/service/apply/filter-by-name';
|
||||
foreach ($this->getAuth()->getRestrictions($rName) as $restriction) {
|
||||
$this->getElement('object_name')->addValidator(
|
||||
new NamePattern($restriction)
|
||||
);
|
||||
}
|
||||
$this->eventuallyAddNameRestriction('director/service/apply/filter-by-name');
|
||||
}
|
||||
|
||||
return $this;
|
||||
|
|
|
@ -4,7 +4,6 @@ namespace Icinga\Module\Director\Forms;
|
|||
|
||||
use Icinga\Module\Director\Objects\IcingaHost;
|
||||
use Icinga\Module\Director\Web\Form\DirectorObjectForm;
|
||||
use Icinga\Module\Director\Web\Form\Validate\NamePattern;
|
||||
|
||||
class IcingaServiceSetForm extends DirectorObjectForm
|
||||
{
|
||||
|
@ -25,24 +24,17 @@ class IcingaServiceSetForm extends DirectorObjectForm
|
|||
|
||||
protected function setupTemplate()
|
||||
{
|
||||
$this->addElement('text', 'object_name', array(
|
||||
$this->addElement('text', 'object_name', [
|
||||
'label' => $this->translate('Service set name'),
|
||||
'description' => $this->translate(
|
||||
'A short name identifying this set of services'
|
||||
),
|
||||
'required' => true,
|
||||
));
|
||||
|
||||
$rName = 'director/service_set/filter-by-name';
|
||||
foreach ($this->getAuth()->getRestrictions($rName) as $restriction) {
|
||||
$this->getElement('object_name')->addValidator(
|
||||
new NamePattern($restriction)
|
||||
);
|
||||
}
|
||||
|
||||
$this->addHidden('object_type', 'template');
|
||||
$this->addDescriptionElement()
|
||||
->addAssignmentElements();
|
||||
])
|
||||
->eventuallyAddNameRestriction('director/service_set/filter-by-name')
|
||||
->addHidden('object_type', 'template')
|
||||
->addDescriptionElement()
|
||||
->addAssignmentElements();
|
||||
}
|
||||
|
||||
protected function setObjectSuccessUrl()
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
namespace Icinga\Module\Director\Web\Form\Validate;
|
||||
|
||||
use Icinga\Data\Filter\FilterMatch;
|
||||
use Icinga\Data\Filter\FilterOr;
|
||||
use Zend_Validate_Abstract;
|
||||
|
||||
class NamePattern extends Zend_Validate_Abstract
|
||||
|
@ -15,7 +16,12 @@ class NamePattern extends Zend_Validate_Abstract
|
|||
|
||||
public function __construct($pattern)
|
||||
{
|
||||
$this->pattern = $pattern;
|
||||
if (is_array($pattern) && count($pattern) === 1) {
|
||||
$this->pattern = current($pattern);
|
||||
} else {
|
||||
$this->pattern = $pattern;
|
||||
}
|
||||
|
||||
$this->_messageTemplates[self::INVALID] = sprintf(
|
||||
'Does not match %s',
|
||||
$pattern
|
||||
|
@ -25,8 +31,17 @@ class NamePattern extends Zend_Validate_Abstract
|
|||
protected function matches($value)
|
||||
{
|
||||
if ($this->filter === null) {
|
||||
$this->filter = new FilterMatch('prop', '=', $this->pattern);
|
||||
$this->filter->setCaseSensitive(false);
|
||||
if (is_array($this->pattern)) {
|
||||
$this->filter = new FilterOr();
|
||||
foreach ($this->pattern as $pattern) {
|
||||
$filter = new FilterMatch('prop', '=', $pattern);
|
||||
$filter->setCaseSensitive(false);
|
||||
$this->filter->addFilter($filter);
|
||||
}
|
||||
} else {
|
||||
$this->filter = new FilterMatch('prop', '=', $this->pattern);
|
||||
$this->filter->setCaseSensitive(false);
|
||||
}
|
||||
}
|
||||
|
||||
return $this->filter->matches($value);
|
||||
|
|
Loading…
Reference in New Issue