mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-31 12:03:48 +00:00
DX: apply rector rules up to php8.0
This commit is contained in:
@@ -34,28 +34,8 @@ use function get_class;
|
||||
*/
|
||||
class AuthorizationHelper implements AuthorizationHelperInterface
|
||||
{
|
||||
private CenterResolverManagerInterface $centerResolverManager;
|
||||
|
||||
private LoggerInterface $logger;
|
||||
|
||||
private ParentRoleHelper $parentRoleHelper;
|
||||
|
||||
private ScopeResolverDispatcher $scopeResolverDispatcher;
|
||||
|
||||
private UserACLAwareRepositoryInterface $userACLAwareRepository;
|
||||
|
||||
public function __construct(
|
||||
CenterResolverManagerInterface $centerResolverManager,
|
||||
LoggerInterface $logger,
|
||||
ScopeResolverDispatcher $scopeResolverDispatcher,
|
||||
UserACLAwareRepositoryInterface $userACLAwareRepository,
|
||||
ParentRoleHelper $parentRoleHelper
|
||||
) {
|
||||
$this->centerResolverManager = $centerResolverManager;
|
||||
$this->logger = $logger;
|
||||
$this->scopeResolverDispatcher = $scopeResolverDispatcher;
|
||||
$this->userACLAwareRepository = $userACLAwareRepository;
|
||||
$this->parentRoleHelper = $parentRoleHelper;
|
||||
public function __construct(private CenterResolverManagerInterface $centerResolverManager, private LoggerInterface $logger, private ScopeResolverDispatcher $scopeResolverDispatcher, private UserACLAwareRepositoryInterface $userACLAwareRepository, private ParentRoleHelper $parentRoleHelper)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -63,9 +43,8 @@ class AuthorizationHelper implements AuthorizationHelperInterface
|
||||
*
|
||||
* @param User $user The user
|
||||
* @param array $centers a list of centers which are going to be filtered
|
||||
* @param mixed $role
|
||||
*/
|
||||
public function filterReachableCenters(User $user, array $centers, $role): array
|
||||
public function filterReachableCenters(User $user, array $centers, mixed $role): array
|
||||
{
|
||||
$results = [];
|
||||
|
||||
@@ -85,12 +64,10 @@ class AuthorizationHelper implements AuthorizationHelperInterface
|
||||
/**
|
||||
* @deprecated use UserACLAwareRepositoryInterface::findUsersByReachedACL instead
|
||||
*
|
||||
* @param array|Center|Center[] $center
|
||||
* @param array|Scope|Scope[]|null $scope
|
||||
*
|
||||
* @return User[]
|
||||
*/
|
||||
public function findUsersReaching(string $role, $center, $scope = null, bool $onlyEnabled = true): array
|
||||
public function findUsersReaching(string $role, array|\Chill\MainBundle\Entity\Center $center, array|\Chill\MainBundle\Entity\Scope|null $scope = null, bool $onlyEnabled = true): array
|
||||
{
|
||||
return $this->userACLAwareRepository
|
||||
->findUsersByReachedACL($role, $center, $scope, $onlyEnabled);
|
||||
@@ -155,12 +132,10 @@ class AuthorizationHelper implements AuthorizationHelperInterface
|
||||
/**
|
||||
* Return all reachable circle for a given user, center and role.
|
||||
*
|
||||
* @param Role|string $role
|
||||
* @param Center|Center[] $center
|
||||
*
|
||||
* @return Scope[]
|
||||
*/
|
||||
public function getReachableCircles(UserInterface $user, $role, $center)
|
||||
public function getReachableCircles(UserInterface $user, \Symfony\Component\Security\Core\Role\Role|string $role, \Chill\MainBundle\Entity\Center|array $center)
|
||||
{
|
||||
$scopes = [];
|
||||
|
||||
@@ -210,7 +185,7 @@ class AuthorizationHelper implements AuthorizationHelperInterface
|
||||
*
|
||||
* @param Center|Center[] $center May be an array of center
|
||||
*/
|
||||
public function userCanReachCenter(User $user, $center): bool
|
||||
public function userCanReachCenter(User $user, \Chill\MainBundle\Entity\Center|array $center): bool
|
||||
{
|
||||
if ($center instanceof Traversable) {
|
||||
foreach ($center as $c) {
|
||||
@@ -236,7 +211,7 @@ class AuthorizationHelper implements AuthorizationHelperInterface
|
||||
sprintf(
|
||||
'The entity given is not an instance of %s, %s given',
|
||||
Center::class,
|
||||
get_class($center)
|
||||
$center::class
|
||||
)
|
||||
);
|
||||
}
|
||||
@@ -252,7 +227,7 @@ class AuthorizationHelper implements AuthorizationHelperInterface
|
||||
*
|
||||
* @return bool true if the user has access
|
||||
*/
|
||||
public function userHasAccess(User $user, $entity, $attribute)
|
||||
public function userHasAccess(User $user, mixed $entity, \Symfony\Component\Security\Core\Role\Role|string $attribute)
|
||||
{
|
||||
$centers = $this->centerResolverManager->resolveCenters($entity);
|
||||
|
||||
|
@@ -17,14 +17,8 @@ use Symfony\Component\Security\Core\Security;
|
||||
|
||||
class AuthorizationHelperForCurrentUser implements AuthorizationHelperForCurrentUserInterface
|
||||
{
|
||||
private AuthorizationHelperInterface $authorizationHelper;
|
||||
|
||||
private Security $security;
|
||||
|
||||
public function __construct(AuthorizationHelperInterface $authorizationHelper, Security $security)
|
||||
public function __construct(private AuthorizationHelperInterface $authorizationHelper, private Security $security)
|
||||
{
|
||||
$this->authorizationHelper = $authorizationHelper;
|
||||
$this->security = $security;
|
||||
}
|
||||
|
||||
public function getReachableCenters(string $role, ?Scope $scope = null): array
|
||||
|
@@ -18,20 +18,8 @@ use function in_array;
|
||||
|
||||
final class DefaultVoterHelper implements VoterHelperInterface
|
||||
{
|
||||
private AuthorizationHelper $authorizationHelper;
|
||||
|
||||
private CenterResolverDispatcherInterface $centerResolverDispatcher;
|
||||
|
||||
private array $configuration = [];
|
||||
|
||||
public function __construct(
|
||||
AuthorizationHelper $authorizationHelper,
|
||||
CenterResolverDispatcherInterface $centerResolverDispatcher,
|
||||
array $configuration
|
||||
) {
|
||||
$this->authorizationHelper = $authorizationHelper;
|
||||
$this->centerResolverDispatcher = $centerResolverDispatcher;
|
||||
$this->configuration = $configuration;
|
||||
public function __construct(private AuthorizationHelper $authorizationHelper, private CenterResolverDispatcherInterface $centerResolverDispatcher, private array $configuration)
|
||||
{
|
||||
}
|
||||
|
||||
public function supports($attribute, $subject): bool
|
||||
|
@@ -15,16 +15,8 @@ use Chill\MainBundle\Security\Resolver\CenterResolverDispatcherInterface;
|
||||
|
||||
class DefaultVoterHelperFactory implements VoterHelperFactoryInterface
|
||||
{
|
||||
protected AuthorizationHelper $authorizationHelper;
|
||||
|
||||
protected CenterResolverDispatcherInterface $centerResolverDispatcher;
|
||||
|
||||
public function __construct(
|
||||
AuthorizationHelper $authorizationHelper,
|
||||
CenterResolverDispatcherInterface $centerResolverDispatcher
|
||||
) {
|
||||
$this->authorizationHelper = $authorizationHelper;
|
||||
$this->centerResolverDispatcher = $centerResolverDispatcher;
|
||||
public function __construct(protected AuthorizationHelper $authorizationHelper, protected CenterResolverDispatcherInterface $centerResolverDispatcher)
|
||||
{
|
||||
}
|
||||
|
||||
public function generate($context): VoterGeneratorInterface
|
||||
|
@@ -15,18 +15,10 @@ use Chill\MainBundle\Security\Resolver\CenterResolverDispatcherInterface;
|
||||
|
||||
final class DefaultVoterHelperGenerator implements VoterGeneratorInterface
|
||||
{
|
||||
private AuthorizationHelper $authorizationHelper;
|
||||
|
||||
private CenterResolverDispatcherInterface $centerResolverDispatcher;
|
||||
|
||||
private array $configuration = [];
|
||||
|
||||
public function __construct(
|
||||
AuthorizationHelper $authorizationHelper,
|
||||
CenterResolverDispatcherInterface $centerResolverDispatcher
|
||||
) {
|
||||
$this->authorizationHelper = $authorizationHelper;
|
||||
$this->centerResolverDispatcher = $centerResolverDispatcher;
|
||||
public function __construct(private AuthorizationHelper $authorizationHelper, private CenterResolverDispatcherInterface $centerResolverDispatcher)
|
||||
{
|
||||
}
|
||||
|
||||
public function addCheckFor(?string $subject, array $attributes): self
|
||||
|
@@ -29,14 +29,8 @@ class EntityWorkflowVoter extends Voter
|
||||
|
||||
public const SHOW_ENTITY_LINK = 'CHILL_MAIN_WORKFLOW_LINK_SHOW';
|
||||
|
||||
private EntityWorkflowManager $manager;
|
||||
|
||||
private Security $security;
|
||||
|
||||
public function __construct(EntityWorkflowManager $manager, Security $security)
|
||||
public function __construct(private EntityWorkflowManager $manager, private Security $security)
|
||||
{
|
||||
$this->manager = $manager;
|
||||
$this->security = $security;
|
||||
}
|
||||
|
||||
protected function supports($attribute, $subject)
|
||||
|
@@ -53,35 +53,22 @@ final class NotificationVoter extends Voter
|
||||
}
|
||||
|
||||
if ($subject instanceof Notification) {
|
||||
switch ($attribute) {
|
||||
case self::COMMENT_ADD:
|
||||
return false === $subject->isSystem() && (
|
||||
$subject->getAddressees()->contains($user) || $subject->getSender() === $user
|
||||
);
|
||||
|
||||
case self::NOTIFICATION_SEE:
|
||||
case self::NOTIFICATION_TOGGLE_READ_STATUS:
|
||||
return $subject->getSender() === $user || $subject->getAddressees()->contains($user);
|
||||
|
||||
case self::NOTIFICATION_UPDATE:
|
||||
return $subject->getSender() === $user && false === $subject->isSystem();
|
||||
|
||||
default:
|
||||
throw new UnexpectedValueException("this subject {$attribute} is not implemented");
|
||||
}
|
||||
return match ($attribute) {
|
||||
self::COMMENT_ADD => false === $subject->isSystem() && (
|
||||
$subject->getAddressees()->contains($user) || $subject->getSender() === $user
|
||||
),
|
||||
self::NOTIFICATION_SEE, self::NOTIFICATION_TOGGLE_READ_STATUS => $subject->getSender() === $user || $subject->getAddressees()->contains($user),
|
||||
self::NOTIFICATION_UPDATE => $subject->getSender() === $user && false === $subject->isSystem(),
|
||||
default => throw new UnexpectedValueException("this subject {$attribute} is not implemented"),
|
||||
};
|
||||
} elseif ($subject instanceof NotificationComment) {
|
||||
switch ($attribute) {
|
||||
case self::COMMENT_ADD:
|
||||
return false === $subject->getNotification()->isSystem() && (
|
||||
$subject->getNotification()->getAddressees()->contains($user) || $subject->getNotification()->getSender() === $user
|
||||
);
|
||||
|
||||
case self::COMMENT_EDIT:
|
||||
return $subject->getCreatedBy() === $user && false === $subject->getNotification()->isSystem();
|
||||
|
||||
default:
|
||||
throw new UnexpectedValueException("this subject {$attribute} is not implemented");
|
||||
}
|
||||
return match ($attribute) {
|
||||
self::COMMENT_ADD => false === $subject->getNotification()->isSystem() && (
|
||||
$subject->getNotification()->getAddressees()->contains($user) || $subject->getNotification()->getSender() === $user
|
||||
),
|
||||
self::COMMENT_EDIT => $subject->getCreatedBy() === $user && false === $subject->getNotification()->isSystem(),
|
||||
default => throw new UnexpectedValueException("this subject {$attribute} is not implemented"),
|
||||
};
|
||||
}
|
||||
|
||||
throw new UnexpectedValueException();
|
||||
|
@@ -38,15 +38,9 @@ class SavedExportVoter extends Voter
|
||||
|
||||
protected function voteOnAttribute($attribute, $subject, TokenInterface $token): bool
|
||||
{
|
||||
/** @var SavedExport $subject */
|
||||
switch ($attribute) {
|
||||
case self::DELETE:
|
||||
case self::EDIT:
|
||||
case self::GENERATE:
|
||||
return $subject->getUser() === $token->getUser();
|
||||
|
||||
default:
|
||||
throw new UnexpectedValueException('attribute not supported: ' . $attribute);
|
||||
}
|
||||
return match ($attribute) {
|
||||
self::DELETE, self::EDIT, self::GENERATE => $subject->getUser() === $token->getUser(),
|
||||
default => throw new UnexpectedValueException('attribute not supported: ' . $attribute),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@@ -21,17 +21,11 @@ use function is_object;
|
||||
|
||||
class WorkflowEntityDeletionVoter extends Voter
|
||||
{
|
||||
private EntityWorkflowRepository $entityWorkflowRepository;
|
||||
|
||||
/**
|
||||
* @var iterable|EntityWorkflowHandlerInterface[]
|
||||
* @param \Chill\MainBundle\Workflow\EntityWorkflowHandlerInterface[] $handlers
|
||||
*/
|
||||
private iterable $handlers;
|
||||
|
||||
public function __construct($handlers, EntityWorkflowRepository $entityWorkflowRepository)
|
||||
public function __construct(private $handlers, private EntityWorkflowRepository $entityWorkflowRepository)
|
||||
{
|
||||
$this->handlers = $handlers;
|
||||
$this->entityWorkflowRepository = $entityWorkflowRepository;
|
||||
}
|
||||
|
||||
protected function supports($attribute, $subject)
|
||||
|
Reference in New Issue
Block a user