WIP: remove deprecations

This commit is contained in:
Julien Fastré 2023-05-06 21:26:53 +02:00
parent 958e2b5cf2
commit 13bc9683fb
Signed by: julienfastre
GPG Key ID: BDE2190974723FCB
35 changed files with 117 additions and 110 deletions

View File

@ -67,7 +67,7 @@ class LoadActivity extends AbstractFixture implements OrderedFixtureInterface
->setPerson($person) ->setPerson($person)
->setDate($this->faker->dateTimeThisYear()) ->setDate($this->faker->dateTimeThisYear())
->setDurationTime($this->faker->dateTime(36000)) ->setDurationTime($this->faker->dateTime(36000))
->setType($this->getRandomActivityType()) ->setActivityType($this->getRandomActivityType())
->setScope($this->getRandomScope()); ->setScope($this->getRandomScope());
// ->setAttendee($this->faker->boolean()) // ->setAttendee($this->faker->boolean())

View File

@ -672,7 +672,7 @@ class Activity implements AccompanyingPeriodLinkedWithSocialIssuesEntityInterfac
} }
/** /**
* @deprecated * @deprecated use @link{self::setActivityType} instead
*/ */
public function setType(ActivityType $activityType): self public function setType(ActivityType $activityType): self
{ {

View File

@ -16,6 +16,7 @@ use Doctrine\ORM\EntityManager;
use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Intl\Countries;
use Symfony\Component\Intl\Intl; use Symfony\Component\Intl\Intl;
class LoadCountriesCommand extends Command class LoadCountriesCommand extends Command
@ -32,11 +33,10 @@ class LoadCountriesCommand extends Command
public static function prepareCountryList($languages) public static function prepareCountryList($languages)
{ {
$regionBundle = Intl::getRegionBundle();
$countries = []; $countries = [];
foreach ($languages as $language) { foreach ($languages as $language) {
$countries[$language] = $regionBundle->getCountryNames($language); $countries[$language] = Countries::getNames([$language]);
} }
$countryEntities = []; $countryEntities = [];
@ -90,6 +90,7 @@ class LoadCountriesCommand extends Command
} }
$em->flush(); $em->flush();
return 0; return 0;
} }
} }

View File

@ -529,7 +529,7 @@ class PermissionsGroupController extends AbstractController
static fn (Role $role) => $role->getRole(), static fn (Role $role) => $role->getRole(),
$this->roleHierarchy $this->roleHierarchy
->getReachableRoles( ->getReachableRoles(
[new Role($roleScope->getRole())] [$roleScope->getRole()]
) )
); );
} }

View File

@ -19,6 +19,7 @@ use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\Intl\Intl; use Symfony\Component\Intl\Intl;
use Symfony\Component\Intl\Languages;
use function in_array; use function in_array;
/** /**
@ -46,9 +47,7 @@ class LoadLanguages extends AbstractFixture implements ContainerAwareInterface,
public function load(ObjectManager $manager) public function load(ObjectManager $manager)
{ {
echo "loading languages... \n"; foreach (Languages::getLanguageCodes() as $code) {
foreach (Intl::getLanguageBundle()->getLanguageNames() as $code => $language) {
if ( if (
!in_array($code, $this->regionalVersionToInclude, true) !in_array($code, $this->regionalVersionToInclude, true)
&& !in_array($code, $this->ancientToExclude, true) && !in_array($code, $this->ancientToExclude, true)
@ -78,7 +77,7 @@ class LoadLanguages extends AbstractFixture implements ContainerAwareInterface,
$names = []; $names = [];
foreach ($this->container->getParameter('chill_main.available_languages') as $lang) { foreach ($this->container->getParameter('chill_main.available_languages') as $lang) {
$names[$lang] = Intl::getLanguageBundle()->getLanguageName($languageCode); $names[$lang] = Languages::getName($languageCode);
} }
return $names; return $names;

View File

@ -12,8 +12,9 @@ declare(strict_types=1);
namespace Chill\MainBundle\Form\Event; namespace Chill\MainBundle\Form\Event;
use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Contracts\EventDispatcher\Event;
class CustomizeFormEvent extends \Symfony\Component\EventDispatcher\Event class CustomizeFormEvent extends Event
{ {
final public const NAME = 'chill_main.customize_form'; final public const NAME = 'chill_main.customize_form';

View File

@ -69,6 +69,8 @@ use Symfony\Component\Security\Core\Role\Role;
* *
* } * }
* ``` * ```
*
* @deprecated use @link{\Chill\MainBundle\Form\Type\ScopePickerType:class} instead
*/ */
trait AppendScopeChoiceTypeTrait trait AppendScopeChoiceTypeTrait
{ {
@ -97,7 +99,7 @@ trait AppendScopeChoiceTypeTrait
*/ */
protected function appendScopeChoices( protected function appendScopeChoices(
FormBuilderInterface $builder, FormBuilderInterface $builder,
Role $role, string $role,
Center $center, Center $center,
User $user, User $user,
AuthorizationHelper $authorizationHelper, AuthorizationHelper $authorizationHelper,

View File

@ -52,7 +52,7 @@ class ScopePickerType extends AbstractType
array_filter( array_filter(
$this->authorizationHelper->getReachableScopes( $this->authorizationHelper->getReachableScopes(
$this->security->getUser(), $this->security->getUser(),
$options['role'] instanceof Role ? $options['role']->getRole() : $options['role'], $options['role'],
$options['center'] $options['center']
), ),
static fn (Scope $s) => $s->isActive() static fn (Scope $s) => $s->isActive()
@ -92,6 +92,6 @@ class ScopePickerType extends AbstractType
->setAllowedTypes('center', [Center::class, 'array', 'null']) ->setAllowedTypes('center', [Center::class, 'array', 'null'])
// create ``role` option // create ``role` option
->setRequired('role') ->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']) ->setAllowedTypes('center', [\Chill\MainBundle\Entity\Center::class, 'null', 'array'])
// create ``role` option // create ``role` option
->setRequired('role') ->setRequired('role')
->setAllowedTypes('role', ['string', \Symfony\Component\Security\Core\Role\Role::class]); ->setAllowedTypes('role', ['string']);
$resolver $resolver
->setDefault('having_permissions_group_flag', null) ->setDefault('having_permissions_group_flag', null)

View File

@ -133,11 +133,11 @@ final class NotificationRepository implements ObjectRepository
{ {
$query = $this->queryByAddressee($addressee)->select('n'); $query = $this->queryByAddressee($addressee)->select('n');
if ($limit) { if (null !== $limit) {
$query = $query->setMaxResults($limit); $query = $query->setMaxResults($limit);
} }
if ($offset) { if (null !== $offset) {
$query = $query->setFirstResult($offset); $query = $query->setFirstResult($offset);
} }

View File

@ -34,8 +34,13 @@ use function get_class;
*/ */
class AuthorizationHelper implements AuthorizationHelperInterface class AuthorizationHelper implements AuthorizationHelperInterface
{ {
public function __construct(private readonly CenterResolverManagerInterface $centerResolverManager, private readonly LoggerInterface $logger, private readonly ScopeResolverDispatcher $scopeResolverDispatcher, private readonly UserACLAwareRepositoryInterface $userACLAwareRepository, private readonly ParentRoleHelper $parentRoleHelper) public function __construct(
{ private readonly CenterResolverManagerInterface $centerResolverManager,
private readonly LoggerInterface $logger,
private readonly ScopeResolverDispatcher $scopeResolverDispatcher,
private readonly UserACLAwareRepositoryInterface $userACLAwareRepository,
private readonly ParentRoleHelper $parentRoleHelper
) {
} }
/** /**
@ -94,10 +99,6 @@ class AuthorizationHelper implements AuthorizationHelperInterface
*/ */
public function getReachableCenters(UserInterface $user, string $role, ?Scope $scope = null): array public function getReachableCenters(UserInterface $user, string $role, ?Scope $scope = null): array
{ {
if ($role instanceof Role) {
$role = $role->getRole();
}
if (!$user instanceof User) { if (!$user instanceof User) {
return []; return [];
} }
@ -132,10 +133,10 @@ class AuthorizationHelper implements AuthorizationHelperInterface
/** /**
* Return all reachable circle for a given user, center and role. * Return all reachable circle for a given user, center and role.
* *
* @param Center|Center[] $center * @param Center|array<Center> $center
* @return Scope[] * @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): array
{ {
$scopes = []; $scopes = [];
@ -223,11 +224,8 @@ class AuthorizationHelper implements AuthorizationHelperInterface
* the scope is taken into account. * the scope is taken into account.
* *
* @param mixed $entity the entity may also implement HasScopeInterface * @param mixed $entity the entity may also implement HasScopeInterface
* @param Role|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): bool
{ {
$centers = $this->centerResolverManager->resolveCenters($entity); $centers = $this->centerResolverManager->resolveCenters($entity);
@ -248,7 +246,7 @@ class AuthorizationHelper implements AuthorizationHelperInterface
* *
* @return bool true if the child role is granted by parent role * @return bool true if the child role is granted by parent role
*/ */
private function isRoleReached(string $childRole, string $parentRole) private function isRoleReached(string $childRole, string $parentRole): bool
{ {
return $this->parentRoleHelper->isRoleReached($childRole, $parentRole); return $this->parentRoleHelper->isRoleReached($childRole, $parentRole);
} }

View File

@ -14,12 +14,16 @@ namespace Chill\MainBundle\Security\Authorization;
use Chill\MainBundle\Entity\User; use Chill\MainBundle\Entity\User;
use Chill\MainBundle\Security\Resolver\CenterResolverDispatcherInterface; use Chill\MainBundle\Security\Resolver\CenterResolverDispatcherInterface;
use Chill\MainBundle\Security\Resolver\CenterResolverManagerInterface;
use function in_array; use function in_array;
final readonly class DefaultVoterHelper implements VoterHelperInterface final readonly class DefaultVoterHelper implements VoterHelperInterface
{ {
public function __construct(private AuthorizationHelper $authorizationHelper, private CenterResolverDispatcherInterface $centerResolverDispatcher, private array $configuration) public function __construct(
{ private AuthorizationHelper $authorizationHelper,
private CenterResolverManagerInterface $centerResolverDispatcher,
private array $configuration
) {
} }
public function supports($attribute, $subject): bool public function supports($attribute, $subject): bool

View File

@ -12,11 +12,14 @@ declare(strict_types=1);
namespace Chill\MainBundle\Security\Authorization; namespace Chill\MainBundle\Security\Authorization;
use Chill\MainBundle\Security\Resolver\CenterResolverDispatcherInterface; use Chill\MainBundle\Security\Resolver\CenterResolverDispatcherInterface;
use Chill\MainBundle\Security\Resolver\CenterResolverManagerInterface;
class DefaultVoterHelperFactory implements VoterHelperFactoryInterface class DefaultVoterHelperFactory implements VoterHelperFactoryInterface
{ {
public function __construct(protected AuthorizationHelper $authorizationHelper, protected CenterResolverDispatcherInterface $centerResolverDispatcher) public function __construct(
{ protected AuthorizationHelper $authorizationHelper,
protected CenterResolverManagerInterface $centerResolverDispatcher
) {
} }
public function generate($context): VoterGeneratorInterface public function generate($context): VoterGeneratorInterface

View File

@ -12,13 +12,16 @@ declare(strict_types=1);
namespace Chill\MainBundle\Security\Authorization; namespace Chill\MainBundle\Security\Authorization;
use Chill\MainBundle\Security\Resolver\CenterResolverDispatcherInterface; use Chill\MainBundle\Security\Resolver\CenterResolverDispatcherInterface;
use Chill\MainBundle\Security\Resolver\CenterResolverManagerInterface;
final class DefaultVoterHelperGenerator implements VoterGeneratorInterface final class DefaultVoterHelperGenerator implements VoterGeneratorInterface
{ {
private array $configuration = []; private array $configuration = [];
public function __construct(private readonly AuthorizationHelper $authorizationHelper, private readonly CenterResolverDispatcherInterface $centerResolverDispatcher) public function __construct(
{ private readonly AuthorizationHelper $authorizationHelper,
private readonly CenterResolverManagerInterface $centerResolverDispatcher
) {
} }
public function addCheckFor(?string $subject, array $attributes): self public function addCheckFor(?string $subject, array $attributes): self

View File

@ -12,7 +12,7 @@ declare(strict_types=1);
namespace Chill\MainBundle\Security\PasswordRecover; namespace Chill\MainBundle\Security\PasswordRecover;
use Chill\MainBundle\Entity\User; use Chill\MainBundle\Entity\User;
use Symfony\Component\EventDispatcher\Event; use Symfony\Contracts\EventDispatcher\Event;
class PasswordRecoverEvent extends Event class PasswordRecoverEvent extends Event
{ {

View File

@ -59,7 +59,7 @@ class ChillTwigRoutingHelper extends AbstractExtension
]; ];
} }
public function getLabelReturnPath($default) public function getLabelReturnPath(?string $default = null): string|null
{ {
$request = $this->requestStack->getCurrentRequest(); $request = $this->requestStack->getCurrentRequest();
@ -68,21 +68,14 @@ class ChillTwigRoutingHelper extends AbstractExtension
/** /**
* Build an url with a returnPath parameter to current page. * Build an url with a returnPath parameter to current page.
*
* @param string $name
* @param array $parameters
* @param bool $relative
* @param mixed|null $label
*
* @return string
*/ */
public function getPathAddReturnPath($name, $parameters = [], $relative = false, $label = null) public function getPathAddReturnPath(string $name, array $parameters = [], bool $relative = false, ?string $label = null): string
{ {
$request = $this->requestStack->getCurrentRequest(); $request = $this->requestStack->getCurrentRequest();
$parameters['returnPath'] = $request->getRequestUri(); $parameters['returnPath'] = $request->getRequestUri();
if ($label) { if (null !== $label) {
$parameters['returnPathLabel'] = $label; $parameters['returnPathLabel'] = $label;
} }
@ -91,14 +84,8 @@ class ChillTwigRoutingHelper extends AbstractExtension
/** /**
* Build an url with a returnPath parameter to current page. * Build an url with a returnPath parameter to current page.
*
* @param string $name
* @param array $parameters
* @param bool $relative
*
* @return string
*/ */
public function getPathForwardReturnPath($name, $parameters = [], $relative = false) public function getPathForwardReturnPath(string $name, array $parameters = [], bool $relative = false): string
{ {
$request = $this->requestStack->getCurrentRequest(); $request = $this->requestStack->getCurrentRequest();
@ -116,14 +103,8 @@ class ChillTwigRoutingHelper extends AbstractExtension
/** /**
* Return the return path if it exists, or generate the path if not. * Return the return path if it exists, or generate the path if not.
*
* @param string $name
* @param array $parameters
* @param bool $relative
*
* @return string
*/ */
public function getReturnPathOr($name, $parameters = [], $relative = false) public function getReturnPathOr(string $name, array $parameters = [], bool $relative = false): string
{ {
$request = $this->requestStack->getCurrentRequest(); $request = $this->requestStack->getCurrentRequest();
@ -134,7 +115,7 @@ class ChillTwigRoutingHelper extends AbstractExtension
return $this->originalExtension->getPath($name, $parameters, $relative); return $this->originalExtension->getPath($name, $parameters, $relative);
} }
public function isUrlGenerationSafe(Node $argsNode) public function isUrlGenerationSafe(Node $argsNode): array|string
{ {
return $this->originalExtension->isUrlGenerationSafe($argsNode); return $this->originalExtension->isUrlGenerationSafe($argsNode);
} }

View File

@ -13,7 +13,7 @@ namespace Chill\MainBundle\Templating\Events;
use ArrayAccess; use ArrayAccess;
use RuntimeException; use RuntimeException;
use Symfony\Component\EventDispatcher\Event; use Symfony\Contracts\EventDispatcher\Event;
/** /**
* This event is transmitted on event chill_block.*. * This event is transmitted on event chill_block.*.

View File

@ -11,7 +11,7 @@ declare(strict_types=1);
namespace Chill\PersonBundle\Actions; namespace Chill\PersonBundle\Actions;
use Symfony\Component\EventDispatcher\Event; use Symfony\Contracts\EventDispatcher\Event;
/** /**
* Event triggered when an entity attached to a person is removed. * Event triggered when an entity attached to a person is removed.

View File

@ -19,7 +19,7 @@ use Chill\PersonBundle\Form\AccompanyingCourseType;
use Chill\PersonBundle\Repository\AccompanyingPeriod\AccompanyingPeriodWorkRepository; use Chill\PersonBundle\Repository\AccompanyingPeriod\AccompanyingPeriodWorkRepository;
use Chill\PersonBundle\Security\Authorization\AccompanyingPeriodVoter; use Chill\PersonBundle\Security\Authorization\AccompanyingPeriodVoter;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter; use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
use Symfony\Bundle\FrameworkBundle\Controller\Controller; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Form\Extension\Core\Type\SubmitType; use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Response;
@ -39,7 +39,7 @@ use function is_array;
/** /**
* Class AccompanyingCourseController. * Class AccompanyingCourseController.
*/ */
class AccompanyingCourseController extends Controller class AccompanyingCourseController extends AbstractController
{ {
public function __construct(protected SerializerInterface $serializer, protected EventDispatcherInterface $dispatcher, protected ValidatorInterface $validator, private readonly AccompanyingPeriodWorkRepository $workRepository, private readonly Registry $registry, private readonly TranslatorInterface $translator) public function __construct(protected SerializerInterface $serializer, protected EventDispatcherInterface $dispatcher, protected ValidatorInterface $validator, private readonly AccompanyingPeriodWorkRepository $workRepository, private readonly Registry $registry, private readonly TranslatorInterface $translator)
{ {

View File

@ -25,6 +25,7 @@ use Chill\PersonBundle\Repository\PersonRepository;
use Chill\PersonBundle\Search\SimilarPersonMatcher; use Chill\PersonBundle\Search\SimilarPersonMatcher;
use Chill\TaskBundle\Entity\SingleTask; use Chill\TaskBundle\Entity\SingleTask;
use http\Exception\InvalidArgumentException; use http\Exception\InvalidArgumentException;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Bundle\FrameworkBundle\Controller\Controller; use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
@ -32,10 +33,15 @@ use Symfony\Contracts\Translation\TranslatorInterface;
use function count; use function count;
class PersonDuplicateController extends Controller class PersonDuplicateController extends AbstractController
{
public function __construct(private readonly SimilarPersonMatcher $similarPersonMatcher, private readonly TranslatorInterface $translator, private readonly PersonRepository $personRepository, private readonly PersonMove $personMove, private readonly EventDispatcherInterface $eventDispatcher)
{ {
public function __construct(
private readonly SimilarPersonMatcher $similarPersonMatcher,
private readonly TranslatorInterface $translator,
private readonly PersonRepository $personRepository,
private readonly PersonMove $personMove,
private readonly EventDispatcherInterface $eventDispatcher
) {
} }
public function confirmAction($person1_id, $person2_id, Request $request) public function confirmAction($person1_id, $person2_id, Request $request)

View File

@ -26,6 +26,8 @@ use Symfony\Component\Security\Core\Role\Role;
/** /**
* Class AccompanyingPeriodType. * Class AccompanyingPeriodType.
*
* @deprecated to be removed
*/ */
class AccompanyingPeriodType extends AbstractType class AccompanyingPeriodType extends AbstractType
{ {
@ -81,7 +83,7 @@ class AccompanyingPeriodType extends AbstractType
if ('visible' === $this->config['user']) { if ('visible' === $this->config['user']) {
$builder->add('user', UserPickerType::class, [ $builder->add('user', UserPickerType::class, [
'center' => $options['center'], 'center' => $options['center'],
'role' => new Role(PersonVoter::SEE), 'role' => PersonVoter::SEE,
]); ]);
} }

View File

@ -213,7 +213,7 @@ class PersonType extends AbstractType
]); ]);
} }
if ($options['cFGroup']) { if (null !== $options['cFGroup']) {
$builder $builder
->add( ->add(
'cFData', 'cFData',

View File

@ -44,6 +44,8 @@ use function is_array;
* `Chill\MainBundle\Entity\Center`. By default, all the reachable centers as selected. * `Chill\MainBundle\Entity\Center`. By default, all the reachable centers as selected.
* - with the `role` option, only the people belonging to the reachable center for the * - with the `role` option, only the people belonging to the reachable center for the
* given role are displayed. * given role are displayed.
*
* @deprecated use @link{\Chill\PersonBundle\Form\Type\PickPersonDynamicType::class} instead
*/ */
class PickPersonType extends AbstractType class PickPersonType extends AbstractType
{ {
@ -107,7 +109,7 @@ class PickPersonType extends AbstractType
->addAllowedTypes('centers', ['array', Center::class, 'null']) ->addAllowedTypes('centers', ['array', Center::class, 'null'])
->setDefault('centers', null) ->setDefault('centers', null)
->setDefined('role') ->setDefined('role')
->addAllowedTypes('role', [Role::class, 'null']) ->addAllowedTypes('role', ['string', 'null'])
->setDefault('role', null); ->setDefault('role', null);
// add the default options // add the default options

View File

@ -32,7 +32,7 @@ namespace Chill\PersonBundle\Privacy;
*/ */
use Chill\PersonBundle\Entity\AccompanyingPeriod; use Chill\PersonBundle\Entity\AccompanyingPeriod;
use Symfony\Component\EventDispatcher\Event; use Symfony\Contracts\EventDispatcher\Event;
class AccompanyingPeriodPrivacyEvent extends Event class AccompanyingPeriodPrivacyEvent extends Event
{ {

View File

@ -32,8 +32,8 @@ namespace Chill\PersonBundle\Privacy;
*/ */
use Chill\PersonBundle\Entity\Person; use Chill\PersonBundle\Entity\Person;
use Symfony\Component\EventDispatcher\Event;
use Symfony\Contracts\EventDispatcher\Event;
use function count; use function count;
/** /**

View File

@ -18,7 +18,7 @@ use Chill\MainBundle\Entity\Scope;
use Chill\MainBundle\Entity\User; use Chill\MainBundle\Entity\User;
use Chill\MainBundle\Entity\UserJob; use Chill\MainBundle\Entity\UserJob;
use Chill\MainBundle\Security\Authorization\AuthorizationHelper; use Chill\MainBundle\Security\Authorization\AuthorizationHelper;
use Chill\MainBundle\Security\Resolver\CenterResolverDispatcherInterface; use Chill\MainBundle\Security\Resolver\CenterResolverManagerInterface;
use Chill\PersonBundle\Entity\AccompanyingPeriod; use Chill\PersonBundle\Entity\AccompanyingPeriod;
use Chill\PersonBundle\Entity\AccompanyingPeriodParticipation; use Chill\PersonBundle\Entity\AccompanyingPeriodParticipation;
use Chill\PersonBundle\Entity\Household\PersonHouseholdAddress; use Chill\PersonBundle\Entity\Household\PersonHouseholdAddress;
@ -35,16 +35,18 @@ use function count;
final readonly class AccompanyingPeriodACLAwareRepository implements AccompanyingPeriodACLAwareRepositoryInterface final readonly class AccompanyingPeriodACLAwareRepository implements AccompanyingPeriodACLAwareRepositoryInterface
{ {
public function __construct(private AccompanyingPeriodRepository $accompanyingPeriodRepository, private Security $security, private AuthorizationHelper $authorizationHelper, private CenterResolverDispatcherInterface $centerResolverDispatcher) public function __construct(
{ private AccompanyingPeriodRepository $accompanyingPeriodRepository,
private Security $security,
private AuthorizationHelper $authorizationHelper,
private CenterResolverManagerInterface $centerResolverDispatcher
) {
} }
/** /**
* @param array|PostalCode[] * @param array<PostalCode> $postalCodes
*
* @return QueryBuilder
*/ */
public function buildQueryOpenedAccompanyingCourseByUser(?User $user, array $postalCodes = []) public function buildQueryOpenedAccompanyingCourseByUser(?User $user, array $postalCodes = []): QueryBuilder
{ {
$qb = $this->accompanyingPeriodRepository->createQueryBuilder('ap'); $qb = $this->accompanyingPeriodRepository->createQueryBuilder('ap');
@ -139,7 +141,7 @@ final readonly class AccompanyingPeriodACLAwareRepository implements Accompanyin
->getReachableCircles( ->getReachableCircles(
$this->security->getUser(), $this->security->getUser(),
$role, $role,
$this->centerResolverDispatcher->resolveCenter($person) $this->centerResolverDispatcher->resolveCenters($person)
); );
if (0 === count($scopes)) { if (0 === count($scopes)) {

View File

@ -58,7 +58,7 @@ class PersonListWidget implements WidgetInterface
// show only the person from the authorized centers // show only the person from the authorized centers
$and = $qb->expr()->andX(); $and = $qb->expr()->andX();
$centers = $this->authorizationHelper $centers = $this->authorizationHelper
->getReachableCenters($this->getUser(), new Role(PersonVoter::SEE)); ->getReachableCenters($this->getUser(), PersonVoter::SEE);
$and->add($qb->expr()->in('person.center', ':centers')); $and->add($qb->expr()->in('person.center', ':centers'));
$qb->setParameter('centers', $centers); $qb->setParameter('centers', $centers);

View File

@ -219,7 +219,7 @@ class ReportController extends AbstractController
$reachableScopes = $this->authorizationHelper $reachableScopes = $this->authorizationHelper
->getReachableScopes( ->getReachableScopes(
$this->getUser(), $this->getUser(),
new Role('CHILL_REPORT_SEE'), 'CHILL_REPORT_SEE',
$person->getCenter() $person->getCenter()
); );
@ -555,7 +555,7 @@ class ReportController extends AbstractController
), ),
'method' => 'POST', 'method' => 'POST',
'cFGroup' => $cFGroup, 'cFGroup' => $cFGroup,
'role' => new Role('CHILL_REPORT_CREATE'), 'role' => 'CHILL_REPORT_CREATE',
'center' => $person->getCenter(), 'center' => $person->getCenter(),
]); ]);
} }
@ -577,7 +577,7 @@ class ReportController extends AbstractController
), ),
'method' => 'PUT', 'method' => 'PUT',
'cFGroup' => $entity->getCFGroup(), 'cFGroup' => $entity->getCFGroup(),
'role' => new Role('CHILL_REPORT_UPDATE'), 'role' => 'CHILL_REPORT_UPDATE',
'center' => $entity->getPerson()->getCenter(), 'center' => $entity->getPerson()->getCenter(),
]); ]);
} }

View File

@ -12,7 +12,7 @@ declare(strict_types=1);
namespace Chill\TaskBundle\Controller; namespace Chill\TaskBundle\Controller;
use Chill\MainBundle\Pagination\PaginatorFactory; use Chill\MainBundle\Pagination\PaginatorFactory;
use Chill\MainBundle\Security\Resolver\CenterResolverDispatcherInterface; use Chill\MainBundle\Security\Resolver\CenterResolverManagerInterface;
use Chill\MainBundle\Serializer\Model\Collection; use Chill\MainBundle\Serializer\Model\Collection;
use Chill\MainBundle\Serializer\Model\Counter; use Chill\MainBundle\Serializer\Model\Counter;
use Chill\MainBundle\Templating\Listing\FilterOrderHelper; use Chill\MainBundle\Templating\Listing\FilterOrderHelper;
@ -39,7 +39,6 @@ use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException; use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
use Symfony\Component\Routing\Annotation\Route; use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Security\Core\Role\Role;
use Symfony\Contracts\Translation\TranslatorInterface; use Symfony\Contracts\Translation\TranslatorInterface;
use function array_map; use function array_map;
@ -47,8 +46,15 @@ use function array_merge;
final class SingleTaskController extends AbstractController final class SingleTaskController extends AbstractController
{ {
public function __construct(private readonly CenterResolverDispatcherInterface $centerResolverDispatcher, private readonly PaginatorFactory $paginatorFactory, private readonly SingleTaskAclAwareRepositoryInterface $singleTaskAclAwareRepository, private readonly TranslatorInterface $translator, private readonly EventDispatcherInterface $eventDispatcher, private readonly TimelineBuilder $timelineBuilder, private readonly LoggerInterface $logger, private readonly FilterOrderHelperFactoryInterface $filterOrderHelperFactory) public function __construct(
{ private readonly PaginatorFactory $paginatorFactory,
private readonly SingleTaskAclAwareRepositoryInterface $singleTaskAclAwareRepository,
private readonly TranslatorInterface $translator,
private readonly EventDispatcherInterface $eventDispatcher,
private readonly TimelineBuilder $timelineBuilder,
private readonly LoggerInterface $logger,
private readonly FilterOrderHelperFactoryInterface $filterOrderHelperFactory
) {
} }
/** /**
@ -259,9 +265,8 @@ final class SingleTaskController extends AbstractController
* name="chill_task_singletask_list" * name="chill_task_singletask_list"
* ) * )
*/ */
public function listAction( public function listAction()
Request $request {
) {
$this->denyAccessUnlessGranted(TaskVoter::SHOW, null); $this->denyAccessUnlessGranted(TaskVoter::SHOW, null);
$filterOrder = $this->buildFilterOrder(); $filterOrder = $this->buildFilterOrder();
@ -303,9 +308,7 @@ final class SingleTaskController extends AbstractController
* name="chill_task_singletask_by-course_list") * name="chill_task_singletask_by-course_list")
*/ */
public function listCourseTasks( public function listCourseTasks(
AccompanyingPeriod $course, AccompanyingPeriod $course
FormFactoryInterface $formFactory,
Request $request
): Response { ): Response {
$this->denyAccessUnlessGranted(TaskVoter::SHOW, $course); $this->denyAccessUnlessGranted(TaskVoter::SHOW, $course);
@ -398,7 +401,6 @@ final class SingleTaskController extends AbstractController
} }
/** /**
* @return Response
* @Route( * @Route(
* "/{_locale}/task/single-task/list/my", * "/{_locale}/task/single-task/list/my",
* name="chill_task_singletask_my_tasks", * name="chill_task_singletask_my_tasks",
@ -409,7 +411,7 @@ final class SingleTaskController extends AbstractController
* defaults={"_format": "json"} * defaults={"_format": "json"}
* ) * )
*/ */
public function myTasksAction(string $_format, Request $request) public function myTasksAction(string $_format, Request $request): Response
{ {
$this->denyAccessUnlessGranted('ROLE_USER'); $this->denyAccessUnlessGranted('ROLE_USER');

View File

@ -12,7 +12,7 @@ declare(strict_types=1);
namespace Chill\TaskBundle\Event; namespace Chill\TaskBundle\Event;
use Chill\TaskBundle\Entity\AbstractTask; use Chill\TaskBundle\Entity\AbstractTask;
use Symfony\Component\EventDispatcher\Event; use Symfony\Contracts\EventDispatcher\Event;
class TaskEvent extends Event class TaskEvent extends Event
{ {

View File

@ -12,10 +12,10 @@ declare(strict_types=1);
namespace Chill\TaskBundle\Event\UI; namespace Chill\TaskBundle\Event\UI;
use Chill\TaskBundle\Entity\AbstractTask; use Chill\TaskBundle\Entity\AbstractTask;
use Symfony\Component\EventDispatcher\Event;
use Symfony\Component\Form\FormInterface; use Symfony\Component\Form\FormInterface;
use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Workflow\Transition; use Symfony\Component\Workflow\Transition;
use Symfony\Contracts\EventDispatcher\Event;
class UIEvent extends Event class UIEvent extends Event
{ {

View File

@ -17,6 +17,7 @@ use Chill\MainBundle\Form\Type\DateIntervalType;
use Chill\MainBundle\Form\Type\ScopePickerType; use Chill\MainBundle\Form\Type\ScopePickerType;
use Chill\MainBundle\Form\Type\UserPickerType; use Chill\MainBundle\Form\Type\UserPickerType;
use Chill\MainBundle\Security\Resolver\CenterResolverDispatcherInterface; use Chill\MainBundle\Security\Resolver\CenterResolverDispatcherInterface;
use Chill\MainBundle\Security\Resolver\CenterResolverManagerInterface;
use Chill\MainBundle\Security\Resolver\ScopeResolverDispatcher; use Chill\MainBundle\Security\Resolver\ScopeResolverDispatcher;
use Chill\TaskBundle\Security\Authorization\TaskVoter; use Chill\TaskBundle\Security\Authorization\TaskVoter;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
@ -28,17 +29,17 @@ use Symfony\Component\Security\Core\Role\Role;
class SingleTaskType extends AbstractType class SingleTaskType extends AbstractType
{ {
public function __construct(private readonly ParameterBagInterface $parameterBag, private readonly CenterResolverDispatcherInterface $centerResolverDispatcher, private readonly ScopeResolverDispatcher $scopeResolverDispatcher) public function __construct(private readonly ParameterBagInterface $parameterBag, private readonly CenterResolverManagerInterface $centerResolverDispatcher, private readonly ScopeResolverDispatcher $scopeResolverDispatcher)
{ {
} }
public function buildForm(FormBuilderInterface $builder, array $options) public function buildForm(FormBuilderInterface $builder, array $options)
{ {
$center = null; $centers = null;
$isScopeConcerned = false; $isScopeConcerned = false;
if (null !== $task = $options['data']) { if (null !== $task = $options['data']) {
$center = $this->centerResolverDispatcher->resolveCenter($task); $centers = $this->centerResolverDispatcher->resolveCenters($task);
$isScopeConcerned = $this->scopeResolverDispatcher->isConcerned($task); $isScopeConcerned = $this->scopeResolverDispatcher->isConcerned($task);
} }
@ -49,7 +50,7 @@ class SingleTaskType extends AbstractType
]) ])
->add('assignee', UserPickerType::class, [ ->add('assignee', UserPickerType::class, [
'required' => false, 'required' => false,
'center' => $center, 'center' => $centers,
'role' => TaskVoter::SHOW, 'role' => TaskVoter::SHOW,
'placeholder' => 'Not assigned', 'placeholder' => 'Not assigned',
'attr' => ['class' => ' select2 '], 'attr' => ['class' => ' select2 '],
@ -67,7 +68,7 @@ class SingleTaskType extends AbstractType
if ($isScopeConcerned && $this->parameterBag->get('chill_main')['acl']['form_show_scopes']) { if ($isScopeConcerned && $this->parameterBag->get('chill_main')['acl']['form_show_scopes']) {
$builder $builder
->add('circle', ScopePickerType::class, [ ->add('circle', ScopePickerType::class, [
'center' => $center, 'center' => $centers,
'role' => $options['role'], 'role' => $options['role'],
'required' => true, 'required' => true,
]); ]);
@ -78,6 +79,6 @@ class SingleTaskType extends AbstractType
{ {
$resolver $resolver
->setRequired('role') ->setRequired('role')
->setAllowedTypes('role', [Role::class, 'string']); ->setAllowedTypes('role', ['string']);
} }
} }

View File

@ -159,7 +159,7 @@ class SingleTaskRepository extends EntityRepository
. '`setAuthorizationHelper`'); . '`setAuthorizationHelper`');
} }
$role = new Role(TaskVoter::SHOW); $role = TaskVoter::SHOW;
$qb->join('st.person', 'p'); $qb->join('st.person', 'p');
$centers = $this->authorizationHelper $centers = $this->authorizationHelper

View File

@ -14,8 +14,8 @@ namespace Chill\TaskBundle\Security\Authorization;
use Chill\PersonBundle\Entity\AccompanyingPeriod; use Chill\PersonBundle\Entity\AccompanyingPeriod;
use Chill\PersonBundle\Entity\Person; use Chill\PersonBundle\Entity\Person;
use Chill\TaskBundle\Entity\AbstractTask; use Chill\TaskBundle\Entity\AbstractTask;
use Symfony\Component\EventDispatcher\Event;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Contracts\EventDispatcher\Event;
class AuthorizationEvent extends Event class AuthorizationEvent extends Event
{ {

View File

@ -168,7 +168,7 @@ class TaskLifeCycleEventTimelineProvider implements TimelineProviderInterface
foreach ( foreach (
$this->authorizationHelper->getReachableCenters( $this->authorizationHelper->getReachableCenters(
$this->security->getUser(), $this->security->getUser(),
new Role(ActivityVoter::SEE_DETAILS) ActivityVoter::SEE_DETAILS
) as $center ) as $center
) { ) {
if (false === in_array($center, $centers, true)) { if (false === in_array($center, $centers, true)) {
@ -181,7 +181,7 @@ class TaskLifeCycleEventTimelineProvider implements TimelineProviderInterface
// we loop over circles // we loop over circles
$circles = $this->authorizationHelper->getReachableCircles( $circles = $this->authorizationHelper->getReachableCircles(
$this->security->getUser(), $this->security->getUser(),
new Role(ActivityVoter::SEE_DETAILS), ActivityVoter::SEE_DETAILS,
$center $center
); );
$circleIds = []; $circleIds = [];
@ -234,7 +234,7 @@ class TaskLifeCycleEventTimelineProvider implements TimelineProviderInterface
// we loop over circles // we loop over circles
$circles = $this->authorizationHelper->getReachableCircles( $circles = $this->authorizationHelper->getReachableCircles(
$this->security->getUser(), $this->security->getUser(),
new Role(ActivityVoter::SEE_DETAILS), ActivityVoter::SEE_DETAILS,
$personArg->getCenter() $personArg->getCenter()
); );