Add WorkflowDocumentService and use in StoredObject voters

A WorkflowDocumentService was created that can be injected\
in context-specific StoredObject voters that need to check whether\
the document in question is attached to a workflow.
This commit is contained in:
2024-06-20 17:32:09 +02:00
parent 7c03a25f1a
commit 4607c36b57
2 changed files with 56 additions and 10 deletions

View File

@@ -0,0 +1,35 @@
<?php
namespace Chill\DocStoreBundle\Service;
use Chill\MainBundle\Entity\Workflow\EntityWorkflow;
use Chill\MainBundle\Repository\Workflow\EntityWorkflowRepository;
use Symfony\Component\Security\Core\Security;
class WorkflowDocumentService
{
public function __construct(private readonly Security $security, private readonly EntityWorkflowRepository $repository)
{
}
public function getRelatedWorkflow($entity): ?EntityWorkflow
{
return $this->repository->findByRelatedEntity(get_class($entity), $entity->getId());
}
public function canApplyTransition(EntityWorkflow $entityWorkflow): bool
{
if ($entityWorkflow->isFinal()) {
return false;
}
$currentUser = $this->security->getUser();
if ($entityWorkflow->getCurrentStep()->getAllDestUser()->contains($currentUser)) {
return true;
}
return false;
}
}