mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
Refactor workflow handlers and update comments
Changes include class refactoring for Workflow handlers, using `readonly` and better indentation in constructors for better readability. In addition, outdated comments are removed. Also, entity workflow handlers now implement the EntityWorkflowHandlerInterface type for better type safety.
This commit is contained in:
parent
fe6b4848e6
commit
c1cf27c42d
@ -12,13 +12,14 @@ declare(strict_types=1);
|
|||||||
namespace Chill\MainBundle\Security\Authorization;
|
namespace Chill\MainBundle\Security\Authorization;
|
||||||
|
|
||||||
use Chill\MainBundle\Repository\Workflow\EntityWorkflowRepository;
|
use Chill\MainBundle\Repository\Workflow\EntityWorkflowRepository;
|
||||||
|
use Chill\MainBundle\Workflow\EntityWorkflowHandlerInterface;
|
||||||
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
|
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
|
||||||
use Symfony\Component\Security\Core\Authorization\Voter\Voter;
|
use Symfony\Component\Security\Core\Authorization\Voter\Voter;
|
||||||
|
|
||||||
class WorkflowEntityDeletionVoter extends Voter
|
class WorkflowEntityDeletionVoter extends Voter
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @param \Chill\MainBundle\Workflow\EntityWorkflowHandlerInterface[] $handlers
|
* @param EntityWorkflowHandlerInterface[] $handlers
|
||||||
*/
|
*/
|
||||||
public function __construct(private $handlers, private readonly EntityWorkflowRepository $entityWorkflowRepository) {}
|
public function __construct(private $handlers, private readonly EntityWorkflowRepository $entityWorkflowRepository) {}
|
||||||
|
|
||||||
@ -30,7 +31,7 @@ class WorkflowEntityDeletionVoter extends Voter
|
|||||||
|
|
||||||
foreach ($this->handlers as $handler) {
|
foreach ($this->handlers as $handler) {
|
||||||
if ($handler->isObjectSupported($subject)
|
if ($handler->isObjectSupported($subject)
|
||||||
&& \in_array($attribute, $handler->getDeletionRoles($subject), true)) {
|
&& \in_array($attribute, $handler->getDeletionRoles(), true)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,6 +14,9 @@ namespace Chill\MainBundle\Workflow;
|
|||||||
use Chill\MainBundle\Entity\User;
|
use Chill\MainBundle\Entity\User;
|
||||||
use Chill\MainBundle\Entity\Workflow\EntityWorkflow;
|
use Chill\MainBundle\Entity\Workflow\EntityWorkflow;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @template T of object
|
||||||
|
*/
|
||||||
interface EntityWorkflowHandlerInterface
|
interface EntityWorkflowHandlerInterface
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
@ -25,6 +28,9 @@ interface EntityWorkflowHandlerInterface
|
|||||||
|
|
||||||
public function getEntityTitle(EntityWorkflow $entityWorkflow, array $options = []): string;
|
public function getEntityTitle(EntityWorkflow $entityWorkflow, array $options = []): string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return T|null
|
||||||
|
*/
|
||||||
public function getRelatedEntity(EntityWorkflow $entityWorkflow): ?object;
|
public function getRelatedEntity(EntityWorkflow $entityWorkflow): ?object;
|
||||||
|
|
||||||
public function getRelatedObjects(object $object): array;
|
public function getRelatedObjects(object $object): array;
|
||||||
|
@ -20,9 +20,16 @@ use Chill\PersonBundle\Repository\AccompanyingPeriod\AccompanyingPeriodWorkEvalu
|
|||||||
use Chill\PersonBundle\Security\Authorization\AccompanyingPeriodWorkEvaluationVoter;
|
use Chill\PersonBundle\Security\Authorization\AccompanyingPeriodWorkEvaluationVoter;
|
||||||
use Symfony\Contracts\Translation\TranslatorInterface;
|
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||||
|
|
||||||
class AccompanyingPeriodWorkEvaluationWorkflowHandler implements EntityWorkflowHandlerInterface
|
/**
|
||||||
|
* @implements EntityWorkflowHandlerInterface<AccompanyingPeriodWorkEvaluation>
|
||||||
|
*/
|
||||||
|
readonly class AccompanyingPeriodWorkEvaluationWorkflowHandler implements EntityWorkflowHandlerInterface
|
||||||
{
|
{
|
||||||
public function __construct(private readonly AccompanyingPeriodWorkEvaluationRepository $repository, private readonly TranslatableStringHelperInterface $translatableStringHelper, private readonly TranslatorInterface $translator) {}
|
public function __construct(
|
||||||
|
private AccompanyingPeriodWorkEvaluationRepository $repository,
|
||||||
|
private TranslatableStringHelperInterface $translatableStringHelper,
|
||||||
|
private TranslatorInterface $translator
|
||||||
|
) {}
|
||||||
|
|
||||||
public function getDeletionRoles(): array
|
public function getDeletionRoles(): array
|
||||||
{
|
{
|
||||||
@ -53,9 +60,6 @@ class AccompanyingPeriodWorkEvaluationWorkflowHandler implements EntityWorkflowH
|
|||||||
return $this->repository->find($entityWorkflow->getRelatedEntityId());
|
return $this->repository->find($entityWorkflow->getRelatedEntityId());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param AccompanyingPeriodWorkEvaluation $object
|
|
||||||
*/
|
|
||||||
public function getRelatedObjects(object $object): array
|
public function getRelatedObjects(object $object): array
|
||||||
{
|
{
|
||||||
$relateds = [];
|
$relateds = [];
|
||||||
|
@ -21,9 +21,16 @@ use Chill\PersonBundle\Repository\AccompanyingPeriod\AccompanyingPeriodWorkRepos
|
|||||||
use Chill\PersonBundle\Security\Authorization\AccompanyingPeriodWorkVoter;
|
use Chill\PersonBundle\Security\Authorization\AccompanyingPeriodWorkVoter;
|
||||||
use Symfony\Contracts\Translation\TranslatorInterface;
|
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||||
|
|
||||||
class AccompanyingPeriodWorkWorkflowHandler implements EntityWorkflowHandlerInterface
|
/**
|
||||||
|
* @implements EntityWorkflowHandlerInterface<AccompanyingPeriodWork>
|
||||||
|
*/
|
||||||
|
readonly class AccompanyingPeriodWorkWorkflowHandler implements EntityWorkflowHandlerInterface
|
||||||
{
|
{
|
||||||
public function __construct(private readonly AccompanyingPeriodWorkRepository $repository, private readonly TranslatableStringHelperInterface $translatableStringHelper, private readonly TranslatorInterface $translator) {}
|
public function __construct(
|
||||||
|
private AccompanyingPeriodWorkRepository $repository,
|
||||||
|
private TranslatableStringHelperInterface $translatableStringHelper,
|
||||||
|
private TranslatorInterface $translator
|
||||||
|
) {}
|
||||||
|
|
||||||
public function getDeletionRoles(): array
|
public function getDeletionRoles(): array
|
||||||
{
|
{
|
||||||
@ -55,9 +62,6 @@ class AccompanyingPeriodWorkWorkflowHandler implements EntityWorkflowHandlerInte
|
|||||||
return $this->repository->find($entityWorkflow->getRelatedEntityId());
|
return $this->repository->find($entityWorkflow->getRelatedEntityId());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param AccompanyingPeriodWork $object
|
|
||||||
*/
|
|
||||||
public function getRelatedObjects(object $object): array
|
public function getRelatedObjects(object $object): array
|
||||||
{
|
{
|
||||||
$relateds = [];
|
$relateds = [];
|
||||||
|
Loading…
x
Reference in New Issue
Block a user