IcingaNotificationForm: enforce & render apply to

fixes #11895
This commit is contained in:
Thomas Gelf 2016-06-09 23:49:02 +02:00
parent 85cda6da9b
commit cc9f5037f4
3 changed files with 56 additions and 0 deletions

View File

@ -41,6 +41,24 @@ class IcingaNotificationForm extends DirectorObjectForm
return $this;
}
$this->addElement(
'select',
'apply_to',
array(
'label' => $this->translate('Apply to'),
'description' => $this->translate(
'Whether this notification should affect hosts or services'
),
'required' => true,
'multiOptions' => $this->optionalEnum(
array(
'host' => $this->translate('Hosts'),
'service' => $this->translate('Services'),
)
)
)
);
$sub = new AssignListSubForm();
$sub->setObject($this->getObject());
$sub->setup();

View File

@ -111,6 +111,43 @@ class IcingaNotification extends IcingaObject
);
}
/**
* Do not render internal property apply_to
*
* Avoid complaints for method names with underscore:
* @codingStandardsIgnoreStart
*
* @return string
*/
public function renderApply_to()
{
// @codingStandardsIgnoreEnd
return '';
}
protected function renderObjectHeader()
{
if ($this->isApplyRule()) {
if (($to = $this->get('apply_to')) === null) {
throw new ConfigurationError(
'Applied notification "%s" has no valid object type',
$this->getObjectName()
);
}
return sprintf(
"%s %s to %s %s {\n",
$this->getObjectTypeName(),
$this->getType(),
ucfirst($to),
c::renderString($this->getObjectName())
);
} else {
return parent::renderObjectHeader();
}
}
protected function setKey($key)
{
if (is_int($key)) {

View File

@ -493,6 +493,7 @@ abstract class DirectorObjectForm extends QuickForm
'groups',
'users',
'user_groups',
'apply_to',
'command_id', // Notification
'notification_interval',
'period_id',