mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-20 14:43:49 +00:00
cs: Fix code style (safe rules only).
This commit is contained in:
@@ -1,37 +1,41 @@
|
||||
<?php
|
||||
/*
|
||||
*/
|
||||
namespace Chill\AMLI\FamilyMembersBundle\Security\Voter;
|
||||
|
||||
use Chill\MainBundle\Security\Authorization\AbstractChillVoter;
|
||||
use Chill\MainBundle\Security\ProvideRoleHierarchyInterface;
|
||||
use Chill\AMLI\FamilyMembersBundle\Entity\FamilyMember;
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
use Chill\MainBundle\Security\Authorization\AuthorizationHelper;
|
||||
use Chill\MainBundle\Entity\User;
|
||||
use Symfony\Component\Security\Core\Role\Role;
|
||||
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
*
|
||||
* @author Julien Fastré <julien.fastre@champs-libres.coop>
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\AMLI\FamilyMembersBundle\Security\Voter;
|
||||
|
||||
use Chill\AMLI\FamilyMembersBundle\Entity\FamilyMember;
|
||||
use Chill\MainBundle\Entity\User;
|
||||
use Chill\MainBundle\Security\Authorization\AbstractChillVoter;
|
||||
use Chill\MainBundle\Security\Authorization\AuthorizationHelper;
|
||||
use Chill\MainBundle\Security\ProvideRoleHierarchyInterface;
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
use Symfony\Component\Security\Core\Role\Role;
|
||||
use function in_array;
|
||||
|
||||
class FamilyMemberVoter extends AbstractChillVoter implements ProvideRoleHierarchyInterface
|
||||
{
|
||||
const CREATE = 'CHILL_FAMILY_MEMBERS_FAMILY_MEMBERS_CREATE';
|
||||
const DELETE = 'CHILL_FAMILY_MEMBERS_FAMILY_MEMBERS_DELETE';
|
||||
const UPDATE = 'CHILL_FAMILY_MEMBERS_FAMILY_MEMBERS_UPDATE';
|
||||
const SHOW = 'CHILL_FAMILY_MEMBERS_FAMILY_MEMBERS_SHOW';
|
||||
public const CREATE = 'CHILL_FAMILY_MEMBERS_FAMILY_MEMBERS_CREATE';
|
||||
|
||||
const ROLES = [
|
||||
public const DELETE = 'CHILL_FAMILY_MEMBERS_FAMILY_MEMBERS_DELETE';
|
||||
|
||||
public const ROLES = [
|
||||
self::CREATE,
|
||||
self::DELETE,
|
||||
self::SHOW,
|
||||
self::UPDATE
|
||||
self::UPDATE,
|
||||
];
|
||||
|
||||
public const SHOW = 'CHILL_FAMILY_MEMBERS_FAMILY_MEMBERS_SHOW';
|
||||
|
||||
public const UPDATE = 'CHILL_FAMILY_MEMBERS_FAMILY_MEMBERS_UPDATE';
|
||||
|
||||
/**
|
||||
*
|
||||
* @var AuthorizationHelper
|
||||
*/
|
||||
protected $authorizationHelper;
|
||||
@@ -41,26 +45,6 @@ class FamilyMemberVoter extends AbstractChillVoter implements ProvideRoleHierarc
|
||||
$this->authorizationHelper = $authorizationHelper;
|
||||
}
|
||||
|
||||
|
||||
protected function supports($attribute, $subject)
|
||||
{
|
||||
return (\in_array($attribute, self::ROLES) && $subject instanceof FamilyMember)
|
||||
or
|
||||
($subject instanceof Person && \in_array($attribute, [ self::SHOW, self::CREATE ]));
|
||||
}
|
||||
|
||||
protected function voteOnAttribute($attribute, $subject, \Symfony\Component\Security\Core\Authentication\Token\TokenInterface $token)
|
||||
{
|
||||
$user = $token->getUser();
|
||||
|
||||
if (FALSE === $user instanceof User) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $this->authorizationHelper
|
||||
->userHasAccess($user, $subject, new Role($attribute));
|
||||
}
|
||||
|
||||
public function getRoles(): array
|
||||
{
|
||||
return self::ROLES;
|
||||
@@ -76,4 +60,21 @@ class FamilyMemberVoter extends AbstractChillVoter implements ProvideRoleHierarc
|
||||
return self::ROLES;
|
||||
}
|
||||
|
||||
protected function supports($attribute, $subject)
|
||||
{
|
||||
return (in_array($attribute, self::ROLES) && $subject instanceof FamilyMember)
|
||||
or ($subject instanceof Person && in_array($attribute, [self::SHOW, self::CREATE]));
|
||||
}
|
||||
|
||||
protected function voteOnAttribute($attribute, $subject, \Symfony\Component\Security\Core\Authentication\Token\TokenInterface $token)
|
||||
{
|
||||
$user = $token->getUser();
|
||||
|
||||
if (false === $user instanceof User) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $this->authorizationHelper
|
||||
->userHasAccess($user, $subject, new Role($attribute));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user