From 7c58880139fe0ffc035574fe1cd00dc655318ccb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Thu, 31 Aug 2023 17:08:18 +0200 Subject: [PATCH] Remove usage of deprecated Role class --- .../controller-secured-for-person.php | 2 +- .../widgets/ChillPersonAddAPersonWidget.php | 2 +- phpunit.xml.dist | 2 +- .../ChillActivityBundle/Form/ActivityType.php | 3 +-- .../Controller/ActivityControllerTest.php | 4 ++-- .../Tests/Form/ActivityTypeTest.php | 11 +++-------- .../Timeline/TimelineActivityProvider.php | 4 ++-- .../Controller/EventController.php | 12 ++++++------ .../ChillEventBundle/Form/EventType.php | 2 +- .../Form/Type/PickEventType.php | 2 +- .../Security/Authorization/EventVoter.php | 2 +- .../Authorization/ParticipationVoter.php | 2 +- .../CRUD/Controller/CRUDController.php | 2 +- .../ChillMainBundle/Form/NotificationType.php | 2 +- .../Form/Type/AppendScopeChoiceTypeTrait.php | 2 +- .../Form/Type/ScopePickerType.php | 4 ++-- .../Form/Type/UserPickerType.php | 8 ++------ .../ChillMainBundle/Form/WorkflowStepType.php | 2 +- .../Authorization/AuthorizationHelper.php | 19 +++---------------- .../Tests/Export/ExportManagerTest.php | 6 +++--- .../ChillPersonBundle/Entity/Person.php | 4 +--- .../Form/AccompanyingPeriodType.php | 2 +- .../Form/Type/PickPersonType.php | 2 +- .../Tests/Form/Type/PickPersonTypeTest.php | 2 +- .../Widget/PersonListWidget.php | 2 +- .../Controller/ReportController.php | 6 +++--- .../ChillReportBundle/Search/ReportSearch.php | 2 +- .../Form/SingleTaskListType.php | 8 ++++---- .../ChillTaskBundle/Form/SingleTaskType.php | 2 +- .../Repository/SingleTaskRepository.php | 2 +- .../TaskLifeCycleEventTimelineProvider.php | 6 +++--- .../Entity/ThirdParty.php | 2 +- .../Security/Voter/ThirdPartyVoter.php | 2 +- 33 files changed, 55 insertions(+), 80 deletions(-) diff --git a/docs/source/development/useful-snippets/controller-secured-for-person.php b/docs/source/development/useful-snippets/controller-secured-for-person.php index a46ac30e7..da2078a7a 100644 --- a/docs/source/development/useful-snippets/controller-secured-for-person.php +++ b/docs/source/development/useful-snippets/controller-secured-for-person.php @@ -43,7 +43,7 @@ class ConsultationController extends \Symfony\Bundle\FrameworkBundle\Controller\ $circles = $authorizationHelper->getReachableCircles( $this->getUser(), - new Role(ConsultationVoter::SEE), + ConsultationVoter::SEE, $person->getCenter() ); diff --git a/docs/source/development/user-interface/widgets/ChillPersonAddAPersonWidget.php b/docs/source/development/user-interface/widgets/ChillPersonAddAPersonWidget.php index 0c8ed3782..0c3f2c182 100644 --- a/docs/source/development/user-interface/widgets/ChillPersonAddAPersonWidget.php +++ b/docs/source/development/user-interface/widgets/ChillPersonAddAPersonWidget.php @@ -87,7 +87,7 @@ class ChillPersonAddAPersonWidget implements WidgetInterface // show only the person from the authorized centers $and = $qb->expr()->andX(); $centers = $this->authorizationHelper - ->getReachableCenters($this->getUser(), new Role(PersonVoter::SEE)); + ->getReachableCenters($this->getUser(), PersonVoter::SEE); $and->add($qb->expr()->in('person.center', ':centers')); $qb->setParameter('centers', $centers); diff --git a/phpunit.xml.dist b/phpunit.xml.dist index df8d74ab4..8c0df64b9 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -10,7 +10,7 @@ - + diff --git a/src/Bundle/ChillActivityBundle/Form/ActivityType.php b/src/Bundle/ChillActivityBundle/Form/ActivityType.php index 780e87db9..89167219e 100644 --- a/src/Bundle/ChillActivityBundle/Form/ActivityType.php +++ b/src/Bundle/ChillActivityBundle/Form/ActivityType.php @@ -53,7 +53,6 @@ use Symfony\Component\Form\FormEvents; use Symfony\Component\OptionsResolver\OptionsResolver; use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; -use Symfony\Component\Security\Core\Role\Role; use function in_array; class ActivityType extends AbstractType @@ -410,7 +409,7 @@ class ActivityType extends AbstractType $resolver ->setRequired(['center', 'role', 'activityType', 'accompanyingPeriod']) ->setAllowedTypes('center', ['null', Center::class]) - ->setAllowedTypes('role', [Role::class, 'string']) + ->setAllowedTypes('role', ['string']) ->setAllowedTypes('activityType', \Chill\ActivityBundle\Entity\ActivityType::class) ->setAllowedTypes('accompanyingPeriod', [\Chill\PersonBundle\Entity\AccompanyingPeriod::class, 'null']); } diff --git a/src/Bundle/ChillActivityBundle/Tests/Controller/ActivityControllerTest.php b/src/Bundle/ChillActivityBundle/Tests/Controller/ActivityControllerTest.php index 252bd88d2..4b5d25514 100644 --- a/src/Bundle/ChillActivityBundle/Tests/Controller/ActivityControllerTest.php +++ b/src/Bundle/ChillActivityBundle/Tests/Controller/ActivityControllerTest.php @@ -354,14 +354,14 @@ final class ActivityControllerTest extends WebTestCase ->get('chill.main.security.authorization.helper') ->getReachableScopes( $user, - new Role('CHILL_ACTIVITY_UPDATE'), + 'CHILL_ACTIVITY_UPDATE', $center ); $reachableScopesDelete = self::$kernel->getContainer() ->get('chill.main.security.authorization.helper') ->getReachableScopes( $user, - new Role('CHILL_ACTIVITY_DELETE'), + 'CHILL_ACTIVITY_DELETE', $center ); $reachableScopesId = array_intersect( diff --git a/src/Bundle/ChillActivityBundle/Tests/Form/ActivityTypeTest.php b/src/Bundle/ChillActivityBundle/Tests/Form/ActivityTypeTest.php index 3ed6b4409..bdaef0bbf 100644 --- a/src/Bundle/ChillActivityBundle/Tests/Form/ActivityTypeTest.php +++ b/src/Bundle/ChillActivityBundle/Tests/Form/ActivityTypeTest.php @@ -30,11 +30,6 @@ final class ActivityTypeTest extends KernelTestCase */ protected $center; - /** - * @var \Symfony\Component\DependencyInjection\ContainerInterface - */ - protected $container; - /** * @var \Symfony\Component\Form\FormBuilderInterface */ @@ -85,7 +80,7 @@ final class ActivityTypeTest extends KernelTestCase $form = $this->formBuilder ->add('activity', ActivityType::class, [ 'center' => $this->center, - 'role' => new Role('CHILL_ACTIVITY_CREATE'), + 'role' => 'CHILL_ACTIVITY_CREATE', ]) ->getForm(); @@ -101,7 +96,7 @@ final class ActivityTypeTest extends KernelTestCase $form = $this->formBuilder ->add('activity', ActivityType::class, [ 'center' => $this->center, - 'role' => new Role('CHILL_ACTIVITY_CREATE'), + 'role' => 'CHILL_ACTIVITY_CREATE', ]) ->getForm(); @@ -157,7 +152,7 @@ final class ActivityTypeTest extends KernelTestCase $form = $builder ->add('activity', ActivityType::class, [ 'center' => $this->center, - 'role' => new Role('CHILL_ACTIVITY_CREATE'), + 'role' => 'CHILL_ACTIVITY_CREATE', ]) ->getForm(); diff --git a/src/Bundle/ChillActivityBundle/Timeline/TimelineActivityProvider.php b/src/Bundle/ChillActivityBundle/Timeline/TimelineActivityProvider.php index 87fc24b74..5e1e84595 100644 --- a/src/Bundle/ChillActivityBundle/Timeline/TimelineActivityProvider.php +++ b/src/Bundle/ChillActivityBundle/Timeline/TimelineActivityProvider.php @@ -141,8 +141,8 @@ class TimelineActivityProvider implements TimelineProviderInterface $parameters = []; $metadataActivity = $this->em->getClassMetadata(Activity::class); $associationMapping = $metadataActivity->getAssociationMapping('person'); - $role = new Role('CHILL_ACTIVITY_SEE'); - $reachableScopes = $this->helper->getReachableScopes($this->user, $role->getRole(), $person->getCenter()); + $role = 'CHILL_ACTIVITY_SEE'; + $reachableScopes = $this->helper->getReachableScopes($this->user, $role, $person->getCenter()); $whereClause = ' {activity.person_id} = ? AND {activity.scope_id} IN ({scopes_ids}) '; $scopes_ids = []; diff --git a/src/Bundle/ChillEventBundle/Controller/EventController.php b/src/Bundle/ChillEventBundle/Controller/EventController.php index 681c18b40..23f2883ee 100644 --- a/src/Bundle/ChillEventBundle/Controller/EventController.php +++ b/src/Bundle/ChillEventBundle/Controller/EventController.php @@ -189,7 +189,7 @@ class EventController extends AbstractController $reachablesCircles = $this->authorizationHelper->getReachableCircles( $this->getUser(), - new Role(EventVoter::SEE), + EventVoter::SEE, $person->getCenter() ); @@ -274,7 +274,7 @@ class EventController extends AbstractController */ public function newPickCenterAction() { - $role = new Role('CHILL_EVENT_CREATE'); + $role = 'CHILL_EVENT_CREATE'; /** * @var Center $centers @@ -404,7 +404,7 @@ class EventController extends AbstractController ); $builder->add('event_id', PickEventType::class, [ - 'role' => new Role('CHILL_EVENT_CREATE'), + 'role' => 'CHILL_EVENT_CREATE', 'centers' => $person->getCenter(), ]); @@ -451,7 +451,7 @@ class EventController extends AbstractController ); $builder->add('person_id', PickPersonType::class, [ - 'role' => new Role('CHILL_EVENT_CREATE'), + 'role' => 'CHILL_EVENT_CREATE', 'centers' => $event->getCenter(), ]); @@ -630,7 +630,7 @@ class EventController extends AbstractController $form = $this->createForm(EventType::class, $entity, [ 'method' => 'POST', 'center' => $entity->getCenter(), - 'role' => new Role('CHILL_EVENT_CREATE'), + 'role' => 'CHILL_EVENT_CREATE', ]); $form->add('submit', SubmitType::class, ['label' => 'Create']); @@ -665,7 +665,7 @@ class EventController extends AbstractController 'action' => $this->generateUrl('chill_event__event_update', ['event_id' => $entity->getId()]), 'method' => 'PUT', 'center' => $entity->getCenter(), - 'role' => new Role('CHILL_EVENT_CREATE'), + 'role' => 'CHILL_EVENT_CREATE', ]); $form->remove('center'); diff --git a/src/Bundle/ChillEventBundle/Form/EventType.php b/src/Bundle/ChillEventBundle/Form/EventType.php index d31d4fa13..a4d101047 100644 --- a/src/Bundle/ChillEventBundle/Form/EventType.php +++ b/src/Bundle/ChillEventBundle/Form/EventType.php @@ -59,7 +59,7 @@ class EventType extends AbstractType $resolver ->setRequired(['center', 'role']) ->setAllowedTypes('center', Center::class) - ->setAllowedTypes('role', Role::class); + ->setAllowedTypes('role', 'string'); } /** diff --git a/src/Bundle/ChillEventBundle/Form/Type/PickEventType.php b/src/Bundle/ChillEventBundle/Form/Type/PickEventType.php index f844124ec..030a67951 100644 --- a/src/Bundle/ChillEventBundle/Form/Type/PickEventType.php +++ b/src/Bundle/ChillEventBundle/Form/Type/PickEventType.php @@ -74,7 +74,7 @@ final class PickEventType extends AbstractType ->setDefault('centers', null); $resolver ->setDefined('role') - ->addAllowedTypes('role', [Role::class, 'null']) + ->addAllowedTypes('role', ['string', 'null']) ->setDefault('role', null); // add the default options diff --git a/src/Bundle/ChillEventBundle/Security/Authorization/EventVoter.php b/src/Bundle/ChillEventBundle/Security/Authorization/EventVoter.php index 691939120..7d77bd279 100644 --- a/src/Bundle/ChillEventBundle/Security/Authorization/EventVoter.php +++ b/src/Bundle/ChillEventBundle/Security/Authorization/EventVoter.php @@ -119,7 +119,7 @@ class EventVoter extends AbstractChillVoter implements ProvideRoleHierarchyInter // subject is null. We check that at least one center is reachable $centers = $this->authorizationHelper - ->getReachableCenters($token->getUser(), new Role($attribute)); + ->getReachableCenters($token->getUser(), $attribute); return count($centers) > 0; diff --git a/src/Bundle/ChillEventBundle/Security/Authorization/ParticipationVoter.php b/src/Bundle/ChillEventBundle/Security/Authorization/ParticipationVoter.php index b0c588560..b6b8c7b3b 100644 --- a/src/Bundle/ChillEventBundle/Security/Authorization/ParticipationVoter.php +++ b/src/Bundle/ChillEventBundle/Security/Authorization/ParticipationVoter.php @@ -116,7 +116,7 @@ class ParticipationVoter extends AbstractChillVoter implements ProvideRoleHierar // subject is null. We check that at least one center is reachable $centers = $this->authorizationHelper - ->getReachableCenters($token->getUser(), new Role($attribute)); + ->getReachableCenters($token->getUser(), $attribute); return count($centers) > 0; diff --git a/src/Bundle/ChillMainBundle/CRUD/Controller/CRUDController.php b/src/Bundle/ChillMainBundle/CRUD/Controller/CRUDController.php index caa5a8297..d002abf6c 100644 --- a/src/Bundle/ChillMainBundle/CRUD/Controller/CRUDController.php +++ b/src/Bundle/ChillMainBundle/CRUD/Controller/CRUDController.php @@ -701,7 +701,7 @@ class CRUDController extends AbstractController /** * @return \Chill\MainBundle\Entity\Center[] */ - protected function getReachableCenters(Role $role, ?Scope $scope = null) + protected function getReachableCenters(string $role, ?Scope $scope = null) { return $this->getAuthorizationHelper() ->getReachableCenters($this->getUser(), $role, $scope); diff --git a/src/Bundle/ChillMainBundle/Form/NotificationType.php b/src/Bundle/ChillMainBundle/Form/NotificationType.php index 61f8e6695..2bd8ba820 100644 --- a/src/Bundle/ChillMainBundle/Form/NotificationType.php +++ b/src/Bundle/ChillMainBundle/Form/NotificationType.php @@ -52,7 +52,7 @@ class NotificationType extends AbstractType 'empty_collection_explain' => 'notification.Any email', 'entry_options' => [ 'constraints' => [ - new NotNull(), new NotBlank(), new Email(['checkMX' => true]), + new NotNull(), new NotBlank(), new Email(), ], 'label' => 'Email', ], diff --git a/src/Bundle/ChillMainBundle/Form/Type/AppendScopeChoiceTypeTrait.php b/src/Bundle/ChillMainBundle/Form/Type/AppendScopeChoiceTypeTrait.php index 8eda0d9d9..fcc4b4ec5 100644 --- a/src/Bundle/ChillMainBundle/Form/Type/AppendScopeChoiceTypeTrait.php +++ b/src/Bundle/ChillMainBundle/Form/Type/AppendScopeChoiceTypeTrait.php @@ -97,7 +97,7 @@ trait AppendScopeChoiceTypeTrait */ protected function appendScopeChoices( FormBuilderInterface $builder, - Role $role, + string $role, Center $center, User $user, AuthorizationHelper $authorizationHelper, diff --git a/src/Bundle/ChillMainBundle/Form/Type/ScopePickerType.php b/src/Bundle/ChillMainBundle/Form/Type/ScopePickerType.php index 8229d4074..41205df31 100644 --- a/src/Bundle/ChillMainBundle/Form/Type/ScopePickerType.php +++ b/src/Bundle/ChillMainBundle/Form/Type/ScopePickerType.php @@ -52,7 +52,7 @@ class ScopePickerType extends AbstractType array_filter( $this->authorizationHelper->getReachableScopes( $this->security->getUser(), - $options['role'] instanceof Role ? $options['role']->getRole() : $options['role'], + $options['role'], $options['center'] ), static fn (Scope $s) => $s->isActive() @@ -92,6 +92,6 @@ class ScopePickerType extends AbstractType ->setAllowedTypes('center', [Center::class, 'array', 'null']) // create ``role` option ->setRequired('role') - ->setAllowedTypes('role', ['string', Role::class]); + ->setAllowedTypes('role', ['string']); } } diff --git a/src/Bundle/ChillMainBundle/Form/Type/UserPickerType.php b/src/Bundle/ChillMainBundle/Form/Type/UserPickerType.php index 791063f0a..ebda0c34f 100644 --- a/src/Bundle/ChillMainBundle/Form/Type/UserPickerType.php +++ b/src/Bundle/ChillMainBundle/Form/Type/UserPickerType.php @@ -63,7 +63,7 @@ class UserPickerType extends AbstractType ->setAllowedTypes('center', [\Chill\MainBundle\Entity\Center::class, 'null', 'array']) // create ``role` option ->setRequired('role') - ->setAllowedTypes('role', ['string', \Symfony\Component\Security\Core\Role\Role::class]); + ->setAllowedTypes('role', ['string']); $resolver ->setDefault('having_permissions_group_flag', null) @@ -74,11 +74,7 @@ class UserPickerType extends AbstractType ->setDefault('scope', null) ->setAllowedTypes('scope', [Scope::class, 'array', 'null']) ->setNormalizer('choices', function (Options $options) { - if ($options['role'] instanceof Role) { - $role = $options['role']->getRole(); - } else { - $role = $options['role']; - } + $role = $options['role']; $users = $this->userACLAwareRepository ->findUsersByReachedACL($role, $options['center'], $options['scope'], true); diff --git a/src/Bundle/ChillMainBundle/Form/WorkflowStepType.php b/src/Bundle/ChillMainBundle/Form/WorkflowStepType.php index 54b1a9fd7..57c898345 100644 --- a/src/Bundle/ChillMainBundle/Form/WorkflowStepType.php +++ b/src/Bundle/ChillMainBundle/Form/WorkflowStepType.php @@ -159,7 +159,7 @@ class WorkflowStepType extends AbstractType 'empty_collection_explain' => 'workflow.Any email', 'entry_options' => [ 'constraints' => [ - new NotNull(), new NotBlank(), new Email(['checkMX' => true]), + new NotNull(), new NotBlank(), new Email(), ], 'label' => 'Email', ], diff --git a/src/Bundle/ChillMainBundle/Security/Authorization/AuthorizationHelper.php b/src/Bundle/ChillMainBundle/Security/Authorization/AuthorizationHelper.php index e0867d31d..9d080df07 100644 --- a/src/Bundle/ChillMainBundle/Security/Authorization/AuthorizationHelper.php +++ b/src/Bundle/ChillMainBundle/Security/Authorization/AuthorizationHelper.php @@ -19,7 +19,6 @@ use Chill\MainBundle\Security\ParentRoleHelper; use Chill\MainBundle\Security\Resolver\CenterResolverManagerInterface; use Chill\MainBundle\Security\Resolver\ScopeResolverDispatcher; use Psr\Log\LoggerInterface; -use Symfony\Component\Security\Core\Role\Role; use Symfony\Component\Security\Core\User\UserInterface; use Traversable; use UnexpectedValueException; @@ -48,10 +47,6 @@ class AuthorizationHelper implements AuthorizationHelperInterface { $results = []; - if ($role instanceof Role) { - $role = $role->getRole(); - } - foreach ($centers as $center) { if ($this->userCanReachCenter($user, $center)) { $results[] = $center; @@ -94,10 +89,6 @@ class AuthorizationHelper implements AuthorizationHelperInterface */ public function getReachableCenters(UserInterface $user, string $role, ?Scope $scope = null): array { - if ($role instanceof Role) { - $role = $role->getRole(); - } - if (!$user instanceof User) { return []; } @@ -135,7 +126,7 @@ class AuthorizationHelper implements AuthorizationHelperInterface * @param Center|Center[] $center * @return Scope[] */ - public function getReachableCircles(UserInterface $user, \Symfony\Component\Security\Core\Role\Role|string $role, \Chill\MainBundle\Entity\Center|array $center) + public function getReachableCircles(UserInterface $user, string $role, \Chill\MainBundle\Entity\Center|array $center) { $scopes = []; @@ -147,10 +138,6 @@ class AuthorizationHelper implements AuthorizationHelperInterface return $scopes; } - if ($role instanceof Role) { - $role = $role->getRole(); - } - foreach ($user->getGroupCenters() as $groupCenter) { if ($center->getId() === $groupCenter->getCenter()->getId()) { //iterate on permissionGroup @@ -219,11 +206,11 @@ class AuthorizationHelper implements AuthorizationHelperInterface * the scope is taken into account. * * @param mixed $entity the entity may also implement HasScopeInterface - * @param Role|string $attribute + * @param string $attribute * * @return bool true if the user has access */ - public function userHasAccess(User $user, mixed $entity, \Symfony\Component\Security\Core\Role\Role|string $attribute) + public function userHasAccess(User $user, mixed $entity, string $attribute) { $centers = $this->centerResolverManager->resolveCenters($entity); diff --git a/src/Bundle/ChillMainBundle/Tests/Export/ExportManagerTest.php b/src/Bundle/ChillMainBundle/Tests/Export/ExportManagerTest.php index 6b734fd9a..1a6143d8a 100644 --- a/src/Bundle/ChillMainBundle/Tests/Export/ExportManagerTest.php +++ b/src/Bundle/ChillMainBundle/Tests/Export/ExportManagerTest.php @@ -418,7 +418,7 @@ final class ExportManagerTest extends KernelTestCase $export = $this->prophet->prophesize(); $export->willImplement(ExportInterface::class); - $export->requiredRole()->willReturn(new Role('CHILL_STAT_DUMMY')); + $export->requiredRole()->willReturn('CHILL_STAT_DUMMY'); $result = $exportManager->isGrantedForElement($export->reveal(), null, [$center, $centerB]); @@ -439,7 +439,7 @@ final class ExportManagerTest extends KernelTestCase $export = $this->prophet->prophesize(); $export->willImplement(\Chill\MainBundle\Export\ExportInterface::class); - $export->requiredRole()->willReturn(new Role('CHILL_STAT_DUMMY')); + $export->requiredRole()->willReturn('CHILL_STAT_DUMMY'); $result = $exportManager->isGrantedForElement($export->reveal(), null, []); @@ -473,7 +473,7 @@ final class ExportManagerTest extends KernelTestCase $export = $this->prophet->prophesize(); $export->willImplement(ExportInterface::class); - $export->requiredRole()->willReturn(new Role('CHILL_STAT_DUMMY')); + $export->requiredRole()->willReturn('CHILL_STAT_DUMMY'); $result = $exportManager->isGrantedForElement( $modifier->reveal(), diff --git a/src/Bundle/ChillPersonBundle/Entity/Person.php b/src/Bundle/ChillPersonBundle/Entity/Person.php index 440f8ced7..fb307443c 100644 --- a/src/Bundle/ChillPersonBundle/Entity/Person.php +++ b/src/Bundle/ChillPersonBundle/Entity/Person.php @@ -294,9 +294,7 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI * * * @ORM\Column(type="text", nullable=true) - * @Assert\Email( - * checkMX=true - * ) + * @Assert\Email() */ private string $email = ''; diff --git a/src/Bundle/ChillPersonBundle/Form/AccompanyingPeriodType.php b/src/Bundle/ChillPersonBundle/Form/AccompanyingPeriodType.php index 25d380562..09b940a17 100644 --- a/src/Bundle/ChillPersonBundle/Form/AccompanyingPeriodType.php +++ b/src/Bundle/ChillPersonBundle/Form/AccompanyingPeriodType.php @@ -81,7 +81,7 @@ class AccompanyingPeriodType extends AbstractType if ('visible' === $this->config['user']) { $builder->add('user', UserPickerType::class, [ 'center' => $options['center'], - 'role' => new Role(PersonVoter::SEE), + 'role' => PersonVoter::SEE, ]); } diff --git a/src/Bundle/ChillPersonBundle/Form/Type/PickPersonType.php b/src/Bundle/ChillPersonBundle/Form/Type/PickPersonType.php index 026a24bb6..86f2a50ec 100644 --- a/src/Bundle/ChillPersonBundle/Form/Type/PickPersonType.php +++ b/src/Bundle/ChillPersonBundle/Form/Type/PickPersonType.php @@ -107,7 +107,7 @@ class PickPersonType extends AbstractType ->addAllowedTypes('centers', ['array', Center::class, 'null']) ->setDefault('centers', null) ->setDefined('role') - ->addAllowedTypes('role', [Role::class, 'null']) + ->addAllowedTypes('role', ['string', 'null']) ->setDefault('role', null); // add the default options diff --git a/src/Bundle/ChillPersonBundle/Tests/Form/Type/PickPersonTypeTest.php b/src/Bundle/ChillPersonBundle/Tests/Form/Type/PickPersonTypeTest.php index f5e4639c2..422467d2a 100644 --- a/src/Bundle/ChillPersonBundle/Tests/Form/Type/PickPersonTypeTest.php +++ b/src/Bundle/ChillPersonBundle/Tests/Form/Type/PickPersonTypeTest.php @@ -133,7 +133,7 @@ final class PickPersonTypeTest extends KernelTestCase $this->markTestSkipped('need to inject locale into url generator without request'); $form = $this->formFactory ->createBuilder(PickPersonType::class, null, [ - 'role' => new \Symfony\Component\Security\Core\Role\Role('INVALID'), + 'role' => 'INVALID', ]) ->getForm(); diff --git a/src/Bundle/ChillPersonBundle/Widget/PersonListWidget.php b/src/Bundle/ChillPersonBundle/Widget/PersonListWidget.php index bf0d3b1b2..c21d05547 100644 --- a/src/Bundle/ChillPersonBundle/Widget/PersonListWidget.php +++ b/src/Bundle/ChillPersonBundle/Widget/PersonListWidget.php @@ -58,7 +58,7 @@ class PersonListWidget implements WidgetInterface // show only the person from the authorized centers $and = $qb->expr()->andX(); $centers = $this->authorizationHelper - ->getReachableCenters($this->getUser(), new Role(PersonVoter::SEE)); + ->getReachableCenters($this->getUser(), PersonVoter::SEE); $and->add($qb->expr()->in('person.center', ':centers')); $qb->setParameter('centers', $centers); diff --git a/src/Bundle/ChillReportBundle/Controller/ReportController.php b/src/Bundle/ChillReportBundle/Controller/ReportController.php index 2762c5cbf..99016e485 100644 --- a/src/Bundle/ChillReportBundle/Controller/ReportController.php +++ b/src/Bundle/ChillReportBundle/Controller/ReportController.php @@ -216,7 +216,7 @@ class ReportController extends AbstractController $reachableScopes = $this->authorizationHelper ->getReachableScopes( $this->getUser(), - new Role('CHILL_REPORT_SEE'), + 'CHILL_REPORT_SEE', $person->getCenter() ); @@ -529,7 +529,7 @@ class ReportController extends AbstractController ), 'method' => 'POST', 'cFGroup' => $cFGroup, - 'role' => new Role('CHILL_REPORT_CREATE'), + 'role' => 'CHILL_REPORT_CREATE', 'center' => $person->getCenter(), ]); } @@ -551,7 +551,7 @@ class ReportController extends AbstractController ), 'method' => 'PUT', 'cFGroup' => $entity->getCFGroup(), - 'role' => new Role('CHILL_REPORT_UPDATE'), + 'role' => 'CHILL_REPORT_UPDATE', 'center' => $entity->getPerson()->getCenter(), ]); } diff --git a/src/Bundle/ChillReportBundle/Search/ReportSearch.php b/src/Bundle/ChillReportBundle/Search/ReportSearch.php index 70ba3282c..f8fec653f 100644 --- a/src/Bundle/ChillReportBundle/Search/ReportSearch.php +++ b/src/Bundle/ChillReportBundle/Search/ReportSearch.php @@ -73,7 +73,7 @@ class ReportSearch extends AbstractSearch implements ContainerAwareInterface //adding join $qb->join('r.person', 'p'); - $role = new Role('CHILL_REPORT_SEE'); + $role = 'CHILL_REPORT_SEE'; $reachableCenters = $this->helper->getReachableCenters($this->user, $role); $whereElement = $qb->expr()->orX(); diff --git a/src/Bundle/ChillTaskBundle/Form/SingleTaskListType.php b/src/Bundle/ChillTaskBundle/Form/SingleTaskListType.php index 1fb0dda1f..e76bf9c82 100644 --- a/src/Bundle/ChillTaskBundle/Form/SingleTaskListType.php +++ b/src/Bundle/ChillTaskBundle/Form/SingleTaskListType.php @@ -116,7 +116,7 @@ class SingleTaskListType extends AbstractType 'centers' => $this->authorizationHelper ->getReachableCenters( $this->tokenStorage->getToken()->getUser(), - new Role(TaskVoter::SHOW) + TaskVoter::SHOW ), 'required' => false, 'label' => 'Associated person', @@ -160,7 +160,7 @@ class SingleTaskListType extends AbstractType protected function getReachablesCenters() { $user = $this->tokenStorage->getToken()->getUser(); - $role = new Role(TaskVoter::SHOW); + $role = TaskVoter::SHOW; return $this->authorizationHelper->getReachableCenters($user, $role); } @@ -169,7 +169,7 @@ class SingleTaskListType extends AbstractType { $qb = $this->em->createQueryBuilder(); $user = $this->tokenStorage->getToken()->getUser(); - $role = new Role(TaskVoter::SHOW); + $role = TaskVoter::SHOW; $centers = $this->authorizationHelper->getReachableCenters($user, $role); $qb->select('DISTINCT task.type AS type') @@ -237,7 +237,7 @@ class SingleTaskListType extends AbstractType { $qb = $this->em->createQueryBuilder(); $user = $this->tokenStorage->getToken()->getUser(); - $role = new Role(TaskVoter::SHOW); + $role = TaskVoter::SHOW; $centers = $this->authorizationHelper->getReachableCenters($user, $role); $qb->select('DISTINCT user') diff --git a/src/Bundle/ChillTaskBundle/Form/SingleTaskType.php b/src/Bundle/ChillTaskBundle/Form/SingleTaskType.php index 65417f21e..6ef66cec9 100644 --- a/src/Bundle/ChillTaskBundle/Form/SingleTaskType.php +++ b/src/Bundle/ChillTaskBundle/Form/SingleTaskType.php @@ -78,6 +78,6 @@ class SingleTaskType extends AbstractType { $resolver ->setRequired('role') - ->setAllowedTypes('role', [Role::class, 'string']); + ->setAllowedTypes('role', ['string']); } } diff --git a/src/Bundle/ChillTaskBundle/Repository/SingleTaskRepository.php b/src/Bundle/ChillTaskBundle/Repository/SingleTaskRepository.php index 0a95e3b25..636203a9e 100644 --- a/src/Bundle/ChillTaskBundle/Repository/SingleTaskRepository.php +++ b/src/Bundle/ChillTaskBundle/Repository/SingleTaskRepository.php @@ -159,7 +159,7 @@ class SingleTaskRepository extends EntityRepository . '`setAuthorizationHelper`'); } - $role = new Role(TaskVoter::SHOW); + $role = TaskVoter::SHOW; $qb->join('st.person', 'p'); $centers = $this->authorizationHelper diff --git a/src/Bundle/ChillTaskBundle/Timeline/TaskLifeCycleEventTimelineProvider.php b/src/Bundle/ChillTaskBundle/Timeline/TaskLifeCycleEventTimelineProvider.php index d1f3990af..b7210e3d5 100644 --- a/src/Bundle/ChillTaskBundle/Timeline/TaskLifeCycleEventTimelineProvider.php +++ b/src/Bundle/ChillTaskBundle/Timeline/TaskLifeCycleEventTimelineProvider.php @@ -168,7 +168,7 @@ class TaskLifeCycleEventTimelineProvider implements TimelineProviderInterface foreach ( $this->authorizationHelper->getReachableCenters( $this->security->getUser(), - new Role(ActivityVoter::SEE_DETAILS) + ActivityVoter::SEE_DETAILS ) as $center ) { if (false === in_array($center, $centers, true)) { @@ -181,7 +181,7 @@ class TaskLifeCycleEventTimelineProvider implements TimelineProviderInterface // we loop over circles $circles = $this->authorizationHelper->getReachableCircles( $this->security->getUser(), - new Role(ActivityVoter::SEE_DETAILS), + ActivityVoter::SEE_DETAILS, $center ); $circleIds = []; @@ -234,7 +234,7 @@ class TaskLifeCycleEventTimelineProvider implements TimelineProviderInterface // we loop over circles $circles = $this->authorizationHelper->getReachableCircles( $this->security->getUser(), - new Role(ActivityVoter::SEE_DETAILS), + ActivityVoter::SEE_DETAILS, $personArg->getCenter() ); diff --git a/src/Bundle/ChillThirdPartyBundle/Entity/ThirdParty.php b/src/Bundle/ChillThirdPartyBundle/Entity/ThirdParty.php index 69631ae35..16ef60530 100644 --- a/src/Bundle/ChillThirdPartyBundle/Entity/ThirdParty.php +++ b/src/Bundle/ChillThirdPartyBundle/Entity/ThirdParty.php @@ -194,7 +194,7 @@ class ThirdParty implements TrackCreationInterface, TrackUpdateInterface, \Strin /** * @ORM\Column(name="email", type="string", length=255, nullable=true) - * @Assert\Email(checkMX=false) + * @Assert\Email() * @Groups({"read", "write", "docgen:read", "docgen:read:3party:parent"}) */ private ?string $email = null; diff --git a/src/Bundle/ChillThirdPartyBundle/Security/Voter/ThirdPartyVoter.php b/src/Bundle/ChillThirdPartyBundle/Security/Voter/ThirdPartyVoter.php index 9e346ebf5..a5fa41b41 100644 --- a/src/Bundle/ChillThirdPartyBundle/Security/Voter/ThirdPartyVoter.php +++ b/src/Bundle/ChillThirdPartyBundle/Security/Voter/ThirdPartyVoter.php @@ -91,7 +91,7 @@ class ThirdPartyVoter extends AbstractChillVoter implements ProvideRoleHierarchy return true; $centers = $this->authorizationHelper - ->getReachableCenters($user, new Role($attribute)); + ->getReachableCenters($user, $attribute); if (null === $subject) { return count($centers) > 0;