mirror of
https://github.com/Icinga/icingaweb2-module-director.git
synced 2025-07-29 08:44:11 +02:00
ObjectRestrictions: new controller extension
This commit is contained in:
parent
186147a73a
commit
0b8d67a3ff
@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace Icinga\Module\Director\Web\Controller\Extension;
|
||||
|
||||
use Icinga\Authentication\Auth;
|
||||
use Icinga\Module\Director\Db;
|
||||
use Icinga\Module\Director\Objects\IcingaObject;
|
||||
use Icinga\Module\Director\Restriction\HostgroupRestriction;
|
||||
use Icinga\Module\Director\Restriction\ObjectRestriction;
|
||||
|
||||
trait ObjectRestrictions
|
||||
{
|
||||
/** @var ObjectRestriction[] */
|
||||
private $objectRestrictions;
|
||||
|
||||
/**
|
||||
* @return ObjectRestriction[]
|
||||
*/
|
||||
public function getObjectRestrictions()
|
||||
{
|
||||
if ($this->objectRestrictions === null) {
|
||||
$this->objectRestrictions = $this->loadObjectRestrictions($this->db(), $this->Auth());
|
||||
}
|
||||
|
||||
return $this->objectRestrictions;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return ObjectRestriction[]
|
||||
*/
|
||||
protected function loadObjectRestrictions(Db $db, Auth $auth)
|
||||
{
|
||||
return [
|
||||
new HostgroupRestriction($db, $auth)
|
||||
];
|
||||
}
|
||||
|
||||
public function allowsObject(IcingaObject $object)
|
||||
{
|
||||
foreach ($this->getObjectRestrictions() as $restriction) {
|
||||
if (! $restriction->allows($object)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user