fix: Strict types interfaces: VoterHelperInterface, ProvideRoleHierarchyInterface and ProvideRoleInterface.

This commit is contained in:
Pol Dellaiera
2021-11-23 10:40:34 +01:00
parent 05dda33a7a
commit 328b4c4596
21 changed files with 187 additions and 255 deletions

View File

@@ -25,7 +25,7 @@ use Chill\MainBundle\Security\ProvideRoleHierarchyInterface;
use Chill\MainBundle\Entity\Center;
/**
*
*
*
* @author Julien Fastré <julien.fastre@champs-libres.coop>
*/
@@ -33,13 +33,13 @@ class ActivityStatsVoter extends AbstractChillVoter implements ProvideRoleHierar
{
const STATS = 'CHILL_ACTIVITY_STATS';
const LISTS = 'CHILL_ACTIVITY_LIST';
/**
*
* @var AuthorizationHelper
*/
protected $helper;
public function __construct(AuthorizationHelper $helper)
{
$this->helper = $helper;
@@ -54,15 +54,15 @@ class ActivityStatsVoter extends AbstractChillVoter implements ProvideRoleHierar
{
return array(Center::class);
}
protected function supports($attribute, $subject)
{
if ($subject instanceof Center
if ($subject instanceof Center
&& \in_array($attribute, $this->getAttributes())) {
return true;
}
return false;
}
@@ -71,22 +71,22 @@ class ActivityStatsVoter extends AbstractChillVoter implements ProvideRoleHierar
if (!$user instanceof \Symfony\Component\Security\Core\User\UserInterface) {
return false;
}
return $this->helper->userHasAccess($user, $object, $attribute);
}
public function getRoles()
public function getRoles(): array
{
return $this->getAttributes();
}
public function getRolesWithoutScope()
public function getRolesWithoutScope(): array
{
return $this->getAttributes();
}
public function getRolesWithHierarchy()
public function getRolesWithHierarchy(): array
{
return [ 'Activity' => $this->getRoles() ];
return ['Activity' => $this->getRoles()];
}
}

View File

@@ -1,21 +1,6 @@
<?php
/*
* Copyright (C) 2015 Julien Fastré <julien.fastre@champs-libres.coop>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace Chill\ActivityBundle\Security\Authorization;
@@ -25,9 +10,7 @@ use Chill\PersonBundle\Entity\AccompanyingPeriod;
use Chill\PersonBundle\Security\Authorization\AccompanyingPeriodVoter;
use Chill\PersonBundle\Security\Authorization\PersonVoter;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Chill\MainBundle\Security\Authorization\AbstractChillVoter;
use Chill\MainBundle\Security\Authorization\AuthorizationHelper;
use Chill\MainBundle\Security\ProvideRoleHierarchyInterface;
use Chill\MainBundle\Entity\User;
use Chill\ActivityBundle\Entity\Activity;
@@ -35,9 +18,6 @@ use Chill\PersonBundle\Entity\Person;
use Symfony\Component\Security\Core\Role\Role;
use Symfony\Component\Security\Core\Security;
/**
* Voter for Activity class
*/
class ActivityVoter extends AbstractChillVoter implements ProvideRoleHierarchyInterface
{
/**
@@ -46,7 +26,7 @@ class ActivityVoter extends AbstractChillVoter implements ProvideRoleHierarchyIn
*
* It is safe for usage in template and controller
*/
const CREATE = 'CHILL_ACTIVITY_CREATE';
public const CREATE = 'CHILL_ACTIVITY_CREATE';
/**
* role to allow to create an activity associated win an accompanying course.
@@ -55,7 +35,7 @@ class ActivityVoter extends AbstractChillVoter implements ProvideRoleHierarchyIn
*
* @internal
*/
const CREATE_ACCOMPANYING_COURSE = 'CHILL_ACTIVITY_CREATE_ACCOMPANYING_COURSE';
public const CREATE_ACCOMPANYING_COURSE = 'CHILL_ACTIVITY_CREATE_ACCOMPANYING_COURSE';
/**
* role to allow to create an activity associated with a person
@@ -64,13 +44,13 @@ class ActivityVoter extends AbstractChillVoter implements ProvideRoleHierarchyIn
*
* @internal
*/
const CREATE_PERSON = 'CHILL_ACTIVITY_CREATE_PERSON';
public const CREATE_PERSON = 'CHILL_ACTIVITY_CREATE_PERSON';
const SEE = 'CHILL_ACTIVITY_SEE';
const SEE_DETAILS = 'CHILL_ACTIVITY_SEE_DETAILS';
const UPDATE = 'CHILL_ACTIVITY_UPDATE';
const DELETE = 'CHILL_ACTIVITY_DELETE';
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';
public const DELETE = 'CHILL_ACTIVITY_DELETE';
public const FULL = 'CHILL_ACTIVITY_FULL';
private const ALL = [
self::CREATE,
@@ -97,13 +77,12 @@ class ActivityVoter extends AbstractChillVoter implements ProvideRoleHierarchyIn
->build();
}
protected function supports($attribute, $subject)
protected function supports($attribute, $subject): bool
{
return $this->voterHelper->supports($attribute, $subject);
}
protected function voteOnAttribute($attribute, $subject, TokenInterface $token)
protected function voteOnAttribute($attribute, $subject, TokenInterface $token): bool
{
if (!$token->getUser() instanceof User) {
return false;
@@ -132,7 +111,7 @@ 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()) {
@@ -155,8 +134,7 @@ class ActivityVoter extends AbstractChillVoter implements ProvideRoleHierarchyIn
return $this->voterHelper->voteOnAttribute($attribute, $subject, $token);
}
public function getRoles()
public function getRoles(): array
{
return [
self::CREATE_PERSON,
@@ -167,16 +145,14 @@ class ActivityVoter extends AbstractChillVoter implements ProvideRoleHierarchyIn
];
}
public function getRolesWithoutScope()
public function getRolesWithoutScope(): array
{
return [];
}
public function getRolesWithHierarchy()
public function getRolesWithHierarchy(): array
{
return [ 'Activity' => $this->getRoles() ];
return ['Activity' => $this->getRoles()];
}
}