diff --git a/application/forms/IcingaServiceForm.php b/application/forms/IcingaServiceForm.php index 1ee0d133..c2f95d31 100644 --- a/application/forms/IcingaServiceForm.php +++ b/application/forms/IcingaServiceForm.php @@ -10,6 +10,7 @@ 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 ipl\Html\Html; use ipl\Html\Link; @@ -73,7 +74,7 @@ class IcingaServiceForm extends DirectorObjectForm protected function providesOverrides() { - return $this->applyGenerated + return $this->applyGenerated || $this->inheritedFrom || ($this->host && $this->set) || ($this->object && $this->object->usesVarOverrides()); @@ -340,6 +341,15 @@ 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) + ); + } + } + return $this; } diff --git a/library/Director/Web/Form/Validate/NamePattern.php b/library/Director/Web/Form/Validate/NamePattern.php new file mode 100644 index 00000000..7b26eef5 --- /dev/null +++ b/library/Director/Web/Form/Validate/NamePattern.php @@ -0,0 +1,44 @@ +pattern = $pattern; + $this->_messageTemplates[self::INVALID] = sprintf( + 'Does not match %s', + $pattern + ); + } + + protected function matches($value) + { + if ($this->filter === null) { + $this->filter = new FilterMatch('prop', '=', $this->pattern); + } + + return $this->filter->matches($value); + } + + public function isValid($value) + { + if ($this->matches((object) ['prop' => $value])) { + return true; + } else { + $this->_error(self::INVALID, $value); + + return false; + } + } +}