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,41 +1,27 @@
<?php
/*
* Copyright (C) 2016 Champs-Libres <info@champs-libres.coop>
/**
* Chill is a software for social workers
*
* 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/>.
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace Chill\ActivityBundle\Security\Authorization;
use Chill\MainBundle\Entity\Center;
use Chill\MainBundle\Security\Authorization\AbstractChillVoter;
use Chill\MainBundle\Security\Authorization\AuthorizationHelper;
use Chill\MainBundle\Security\ProvideRoleHierarchyInterface;
use Chill\MainBundle\Entity\Center;
use function in_array;
/**
*
*
* @author Julien Fastré <julien.fastre@champs-libres.coop>
*/
class ActivityStatsVoter extends AbstractChillVoter implements ProvideRoleHierarchyInterface
{
const STATS = 'CHILL_ACTIVITY_STATS';
const LISTS = 'CHILL_ACTIVITY_LIST';
public const LISTS = 'CHILL_ACTIVITY_LIST';
public const STATS = 'CHILL_ACTIVITY_STATS';
/**
*
* @var AuthorizationHelper
*/
protected $helper;
@@ -45,25 +31,24 @@ class ActivityStatsVoter extends AbstractChillVoter implements ProvideRoleHierar
$this->helper = $helper;
}
private function getAttributes()
public function getRoles(): array
{
return array(self::STATS, self::LISTS);
return $this->getAttributes();
}
public function getRolesWithHierarchy(): array
{
return ['Activity' => $this->getRoles()];
}
public function getRolesWithoutScope(): array
{
return $this->getAttributes();
}
protected function getSupportedClasses()
{
return array(Center::class);
}
protected function supports($attribute, $subject)
{
if ($subject instanceof Center
&& \in_array($attribute, $this->getAttributes())) {
return true;
}
return false;
return [Center::class];
}
protected function isGranted($attribute, $object, $user = null)
@@ -75,18 +60,18 @@ class ActivityStatsVoter extends AbstractChillVoter implements ProvideRoleHierar
return $this->helper->userHasAccess($user, $object, $attribute);
}
public function getRoles(): array
protected function supports($attribute, $subject)
{
return $this->getAttributes();
if ($subject instanceof Center
&& in_array($attribute, $this->getAttributes())) {
return true;
}
return false;
}
public function getRolesWithoutScope(): array
private function getAttributes()
{
return $this->getAttributes();
}
public function getRolesWithHierarchy(): array
{
return ['Activity' => $this->getRoles()];
return [self::STATS, self::LISTS];
}
}

View File

@@ -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()];
}
}