cs: Fix code style (safe rules only).

This commit is contained in:
Pol Dellaiera
2021-11-23 14:06:38 +01:00
parent 149d7ce991
commit 8f96a1121d
1223 changed files with 65199 additions and 64625 deletions

View File

@@ -1,93 +1,56 @@
<?php
/*
*/
namespace Chill\ThirdPartyBundle\Security\Voter;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Chill\MainBundle\Security\Authorization\AbstractChillVoter;
use Chill\MainBundle\Security\Authorization\AuthorizationHelper;
use Chill\ThirdPartyBundle\Entity\ThirdParty;
use Chill\MainBundle\Security\ProvideRoleHierarchyInterface;
use Chill\MainBundle\Entity\User;
use Symfony\Component\Security\Core\Role\Role;
/**
* Voter for Third Party
*
*
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace Chill\ThirdPartyBundle\Security\Voter;
use Chill\MainBundle\Entity\User;
use Chill\MainBundle\Security\Authorization\AbstractChillVoter;
use Chill\MainBundle\Security\Authorization\AuthorizationHelper;
use Chill\MainBundle\Security\ProvideRoleHierarchyInterface;
use Chill\ThirdPartyBundle\Entity\ThirdParty;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Role\Role;
use function array_intersect;
use function in_array;
/**
* Voter for Third Party.
*/
class ThirdPartyVoter extends AbstractChillVoter implements ProvideRoleHierarchyInterface
{
public const CREATE = 'CHILL_3PARTY_3PARTY_CREATE';
public const SHOW = 'CHILL_3PARTY_3PARTY_SHOW';
public const UPDATE = 'CHILL_3PARTY_3PARTY_UPDATE';
/**
*
* @var AuthorizationHelper
*/
protected $authorizationHelper;
public const CREATE = 'CHILL_3PARTY_3PARTY_CREATE';
public const UPDATE = 'CHILL_3PARTY_3PARTY_UPDATE';
public const SHOW = 'CHILL_3PARTY_3PARTY_SHOW';
public function __construct(AuthorizationHelper $authorizationHelper)
{
$this->authorizationHelper = $authorizationHelper;
}
protected function supports($attribute, $subject)
{
if ($subject instanceof ThirdParty) {
return \in_array($attribute, $this->getRoles());
} elseif ($subject === NULL) {
return $attribute === self::CREATE || $attribute === self::SHOW ;
}
return false;
}
/**
*
* @param string $attribute
* @param ThirdParty|null $subject
* @param TokenInterface $token
*/
protected function voteOnAttribute($attribute, $subject, TokenInterface $token): bool
{
return true;
$user = $token->getUser();
if (!$user instanceof User) {
return false;
}
return true;
$centers = $this->authorizationHelper
->getReachableCenters($user, new Role($attribute));
if ($subject === NULL) {
return count($centers) > 0;
} elseif ($subject instanceof ThirdParty) {
return count(\array_intersect($centers, $subject->getCenters()->toArray())) > 0;
}
return false;
}
public function getRoles(): array
{
return [
self::CREATE, self::UPDATE, self::SHOW
self::CREATE, self::UPDATE, self::SHOW,
];
}
public function getRolesWithHierarchy(): array
{
return [
'Third Party' => $this->getRoles()
'Third Party' => $this->getRoles(),
];
}
@@ -95,4 +58,45 @@ class ThirdPartyVoter extends AbstractChillVoter implements ProvideRoleHierarchy
{
return $this->getRoles();
}
protected function supports($attribute, $subject)
{
if ($subject instanceof ThirdParty) {
return in_array($attribute, $this->getRoles());
}
if (null === $subject) {
return self::CREATE === $attribute || self::SHOW === $attribute;
}
return false;
}
/**
* @param string $attribute
* @param ThirdParty|null $subject
*/
protected function voteOnAttribute($attribute, $subject, TokenInterface $token): bool
{
return true;
$user = $token->getUser();
if (!$user instanceof User) {
return false;
}
return true;
$centers = $this->authorizationHelper
->getReachableCenters($user, new Role($attribute));
if (null === $subject) {
return count($centers) > 0;
}
if ($subject instanceof ThirdParty) {
return count(array_intersect($centers, $subject->getCenters()->toArray())) > 0;
}
return false;
}
}