IcingaHostForm: logic belongs here

refs #1451
This commit is contained in:
Thomas Gelf 2018-03-28 18:38:36 +02:00
parent 8c7897ee46
commit 5dab1d3bb8
2 changed files with 16 additions and 13 deletions

View File

@ -2,8 +2,9 @@
namespace Icinga\Module\Director\Forms;
use Icinga\Module\Director\Objects\IcingaHost;
use Icinga\Exception\AuthenticationException;
use Icinga\Module\Director\Repository\IcingaTemplateRepository;
use Icinga\Module\Director\Restriction\HostgroupRestriction;
use Icinga\Module\Director\Web\Form\DirectorObjectForm;
use dipl\Html\BaseElement;
use dipl\Html\Html;
@ -366,4 +367,18 @@ class IcingaHostForm extends DirectorObjectForm
return $db->fetchPairs($select);
}
public function onSuccess()
{
if ($this->hasHostGroupRestriction()) {
$restriction = new HostgroupRestriction($this->getDb(), $this->getAuth());
if (! $restriction->allowsHost($this->object())) {
throw new AuthenticationException($this->translate(
'Unable to store a host with the given properties because of insufficient permissions'
));
}
}
return parent::onSuccess();
}
}

View File

@ -4,17 +4,14 @@ namespace Icinga\Module\Director\Web\Form;
use Exception;
use Icinga\Authentication\Auth;
use Icinga\Exception\AuthenticationException;
use Icinga\Module\Director\Db;
use Icinga\Module\Director\Data\Db\DbObject;
use Icinga\Module\Director\Data\Db\DbObjectWithSettings;
use Icinga\Module\Director\Exception\NestingError;
use Icinga\Module\Director\IcingaConfig\StateFilterSet;
use Icinga\Module\Director\IcingaConfig\TypeFilterSet;
use Icinga\Module\Director\Objects\IcingaHost;
use Icinga\Module\Director\Objects\IcingaTemplateChoice;
use Icinga\Module\Director\Objects\IcingaObject;
use Icinga\Module\Director\Restriction\HostgroupRestriction;
use Icinga\Module\Director\Util;
use Icinga\Module\Director\Web\Form\Validate\NamePattern;
use Zend_Form_Element as ZfElement;
@ -633,15 +630,6 @@ abstract class DirectorObjectForm extends DirectorForm
{
$object = $this->object();
if ($object->hasBeenModified()) {
if ($object instanceof IcingaHost && $this->hasHostGroupRestriction()) {
$restriction = new HostgroupRestriction($this->db, $this->auth);
if (! $restriction->allowsHost($object)) {
throw new AuthenticationException($this->translate(
'Unable to store a host with the given properties because of insufficient permissions'
));
}
}
if (! $object->hasBeenLoadedFromDb()) {
$this->setHttpResponseCode(201);
}