Commit 7b5cf283 authored by Jean-Philippe Metivier's avatar Jean-Philippe Metivier
Browse files

Ajout de checkPrivilege

parent 26a3010e
Loading
Loading
Loading
Loading
Loading
+13 −0
Original line number Diff line number Diff line
@@ -241,5 +241,18 @@ class PrivilegeService extends CommonService implements PrivilegeProviderInterfa

        return $qb->getQuery()->getSingleScalarResult();
    }

    /** FACADE ********************************************************************************************************/

    public function checkPrivilege(string $privilege, RoleInterface $role) : bool
    {
        [$catCode, $priCode] = explode('-', $privilege);
        $categorie = $this->getPrivilegeCategorieService()->findByCode($catCode);
        $pprivilege = $this->findByCode($priCode, $categorie->getId());
        if ($pprivilege === null) return false;
        $listings = $pprivilege->getRoles()->toArray();
        if (!in_array($role, $listings)) return false;
        return true;
    }
}