Remove usage of deprecated Role class

This commit is contained in:
2023-08-31 17:08:18 +02:00
parent 76142c1264
commit 7c58880139
33 changed files with 55 additions and 80 deletions

View File

@@ -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);

View File

@@ -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',
],

View File

@@ -97,7 +97,7 @@ trait AppendScopeChoiceTypeTrait
*/
protected function appendScopeChoices(
FormBuilderInterface $builder,
Role $role,
string $role,
Center $center,
User $user,
AuthorizationHelper $authorizationHelper,

View File

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

View File

@@ -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);

View File

@@ -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',
],

View File

@@ -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);

View File

@@ -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(),