summaryrefslogtreecommitdiffstats
path: root/library/Director/Web/Controller/Extension/ObjectRestrictions.php
blob: bedb3f187738e4445c542c036df04723cd603db6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
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;
    }
}