mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-21 07:03:49 +00:00
cs: Fix code style (safe rules only).
This commit is contained in:
@@ -1,21 +1,30 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Chill\ActivityBundle\Security\Authorization;
|
||||
|
||||
use Chill\ActivityBundle\Entity\Activity;
|
||||
use Chill\MainBundle\Entity\User;
|
||||
use Chill\MainBundle\Security\Authorization\AbstractChillVoter;
|
||||
use Chill\MainBundle\Security\Authorization\VoterHelperFactoryInterface;
|
||||
use Chill\MainBundle\Security\Authorization\VoterHelperInterface;
|
||||
use Chill\MainBundle\Security\ProvideRoleHierarchyInterface;
|
||||
use Chill\PersonBundle\Entity\AccompanyingPeriod;
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
use Chill\PersonBundle\Security\Authorization\AccompanyingPeriodVoter;
|
||||
use Chill\PersonBundle\Security\Authorization\PersonVoter;
|
||||
use RuntimeException;
|
||||
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
|
||||
use Chill\MainBundle\Security\Authorization\AbstractChillVoter;
|
||||
use Chill\MainBundle\Security\ProvideRoleHierarchyInterface;
|
||||
use Chill\MainBundle\Entity\User;
|
||||
use Chill\ActivityBundle\Entity\Activity;
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
use Symfony\Component\Security\Core\Security;
|
||||
use function in_array;
|
||||
|
||||
class ActivityVoter extends AbstractChillVoter implements ProvideRoleHierarchyInterface
|
||||
{
|
||||
@@ -30,40 +39,44 @@ class ActivityVoter extends AbstractChillVoter implements ProvideRoleHierarchyIn
|
||||
/**
|
||||
* role to allow to create an activity associated win an accompanying course.
|
||||
*
|
||||
* Before using this, check if @link{self::CREATE} is not sufficiant
|
||||
* Before using this, check if @see{self::CREATE} is not sufficiant
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
public const CREATE_ACCOMPANYING_COURSE = 'CHILL_ACTIVITY_CREATE_ACCOMPANYING_COURSE';
|
||||
|
||||
/**
|
||||
* role to allow to create an activity associated with a person
|
||||
* role to allow to create an activity associated with a person.
|
||||
*
|
||||
* Before using this, check if @link{self::CREATE} is not sufficiant
|
||||
* Before using this, check if @see{self::CREATE} is not sufficiant
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
public const CREATE_PERSON = 'CHILL_ACTIVITY_CREATE_PERSON';
|
||||
|
||||
public const SEE = 'CHILL_ACTIVITY_SEE';
|
||||
public const SEE_DETAILS = 'CHILL_ACTIVITY_SEE_DETAILS';
|
||||
public const UPDATE = 'CHILL_ACTIVITY_UPDATE';
|
||||
public const DELETE = 'CHILL_ACTIVITY_DELETE';
|
||||
|
||||
public const FULL = 'CHILL_ACTIVITY_FULL';
|
||||
|
||||
public const SEE = 'CHILL_ACTIVITY_SEE';
|
||||
|
||||
public const SEE_DETAILS = 'CHILL_ACTIVITY_SEE_DETAILS';
|
||||
|
||||
public const UPDATE = 'CHILL_ACTIVITY_UPDATE';
|
||||
|
||||
private const ALL = [
|
||||
self::CREATE,
|
||||
self::SEE,
|
||||
self::UPDATE,
|
||||
self::DELETE,
|
||||
self::SEE_DETAILS,
|
||||
self::FULL
|
||||
self::FULL,
|
||||
];
|
||||
|
||||
protected VoterHelperInterface $voterHelper;
|
||||
|
||||
protected Security $security;
|
||||
|
||||
protected VoterHelperInterface $voterHelper;
|
||||
|
||||
public function __construct(
|
||||
Security $security,
|
||||
VoterHelperFactoryInterface $voterHelperFactory
|
||||
@@ -76,6 +89,27 @@ class ActivityVoter extends AbstractChillVoter implements ProvideRoleHierarchyIn
|
||||
->build();
|
||||
}
|
||||
|
||||
public function getRoles(): array
|
||||
{
|
||||
return [
|
||||
self::CREATE_PERSON,
|
||||
self::CREATE_ACCOMPANYING_COURSE,
|
||||
self::UPDATE,
|
||||
self::DELETE,
|
||||
self::FULL,
|
||||
];
|
||||
}
|
||||
|
||||
public function getRolesWithHierarchy(): array
|
||||
{
|
||||
return ['Activity' => $this->getRoles()];
|
||||
}
|
||||
|
||||
public function getRolesWithoutScope(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
protected function supports($attribute, $subject): bool
|
||||
{
|
||||
return $this->voterHelper->supports($attribute, $subject);
|
||||
@@ -110,11 +144,11 @@ class ActivityVoter extends AbstractChillVoter implements ProvideRoleHierarchyIn
|
||||
$attribute = self::CREATE_ACCOMPANYING_COURSE;
|
||||
}
|
||||
} else {
|
||||
throw new \RuntimeException('Could not determine context of activity.');
|
||||
throw new RuntimeException('Could not determine context of activity.');
|
||||
}
|
||||
} elseif ($subject instanceof AccompanyingPeriod) {
|
||||
if (AccompanyingPeriod::STEP_CLOSED === $subject->getStep()) {
|
||||
if (\in_array($attribute, [self::UPDATE, self::CREATE, self::DELETE], true)) {
|
||||
if (in_array($attribute, [self::UPDATE, self::CREATE, self::DELETE], true)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -132,26 +166,4 @@ class ActivityVoter extends AbstractChillVoter implements ProvideRoleHierarchyIn
|
||||
|
||||
return $this->voterHelper->voteOnAttribute($attribute, $subject, $token);
|
||||
}
|
||||
|
||||
public function getRoles(): array
|
||||
{
|
||||
return [
|
||||
self::CREATE_PERSON,
|
||||
self::CREATE_ACCOMPANYING_COURSE,
|
||||
self::UPDATE,
|
||||
self::DELETE,
|
||||
self::FULL
|
||||
];
|
||||
}
|
||||
|
||||
public function getRolesWithoutScope(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function getRolesWithHierarchy(): array
|
||||
{
|
||||
return ['Activity' => $this->getRoles()];
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user