Added permissions to label system.

This commit is contained in:
Jan Böhmer 2020-05-04 23:21:58 +02:00
parent fde1d7be4f
commit 5a9be023b1
6 changed files with 62 additions and 27 deletions

View file

@ -27,12 +27,19 @@ use App\Entity\UserSystem\User;
class LabelProfileVoter extends ExtendedVoter
{
protected const MAPPING = [
'read' => 'read_profiles',
'create' => 'create_profiles',
'edit' => 'edit_profiles',
'delete' => 'delete_profiles',
];
/**
* @inheritDoc
*/
protected function voteOnUser($attribute, $subject, User $user): bool
{
return true;
return $this->resolver->inherit($user, 'labels', self::MAPPING[$attribute]) ?? false;
}
/**
@ -41,7 +48,11 @@ class LabelProfileVoter extends ExtendedVoter
protected function supports($attribute, $subject)
{
if ($subject instanceof LabelProfile) {
return true;
if (!isset(self::MAPPING[$attribute])) {
return false;
}
return $this->resolver->isValidOperation('labels', self::MAPPING[$attribute]);
}
return false;