Implement logic to check if editing of document is blocked by workflow

Using the workflow handlers we return the workflow that is attached to an object
so that within the workflowDocumentService we can then check whether this workflow blocks
the edition of a document.
This commit is contained in:
2024-07-01 12:14:03 +02:00
parent e9d4b9e2ab
commit c9d2e37cee
7 changed files with 86 additions and 20 deletions

View File

@@ -12,8 +12,10 @@ declare(strict_types=1);
namespace Chill\DocStoreBundle\Workflow;
use Chill\DocStoreBundle\Entity\AccompanyingCourseDocument;
use Chill\DocStoreBundle\Repository\AccompanyingCourseDocumentRepository;
use Chill\DocStoreBundle\Security\Authorization\AccompanyingCourseDocumentVoter;
use Chill\MainBundle\Entity\Workflow\EntityWorkflow;
use Chill\MainBundle\Repository\Workflow\EntityWorkflowRepository;
use Chill\MainBundle\Workflow\EntityWorkflowHandlerInterface;
use Chill\PersonBundle\Entity\AccompanyingPeriodParticipation;
use Doctrine\ORM\EntityManagerInterface;
@@ -22,16 +24,13 @@ use Symfony\Contracts\Translation\TranslatorInterface;
class AccompanyingCourseDocumentWorkflowHandler implements EntityWorkflowHandlerInterface
{
private readonly EntityRepository $repository;
/**
* TODO: injecter le repository directement.
*/
public function __construct(
EntityManagerInterface $em,
private readonly TranslatorInterface $translator
private readonly TranslatorInterface $translator,
private readonly EntityWorkflowRepository $workflowRepository,
private readonly AccompanyingCourseDocumentRepository $repository
) {
$this->repository = $em->getRepository(AccompanyingCourseDocument::class);
}
public function getDeletionRoles(): array
@@ -126,4 +125,13 @@ class AccompanyingCourseDocumentWorkflowHandler implements EntityWorkflowHandler
{
return false;
}
public function findByRelatedEntity(object $object): ?EntityWorkflow
{
if(!$object instanceof AccompanyingCourseDocument) {
return null;
}
return $this->workflowRepository->findByRelatedEntity(AccompanyingCourseDocument::class, $object->getId());
}
}