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

@@ -4,32 +4,36 @@ namespace Chill\DocStoreBundle\Service;
use Chill\MainBundle\Entity\Workflow\EntityWorkflow;
use Chill\MainBundle\Repository\Workflow\EntityWorkflowRepository;
use Chill\MainBundle\Workflow\EntityWorkflowManager;
use Symfony\Component\Security\Core\Security;
class WorkflowDocumentService
{
public function __construct(private readonly Security $security, private readonly EntityWorkflowRepository $repository)
public function __construct(private readonly Security $security, private readonly EntityWorkflowManager $entityWorkflowManager)
{
}
public function notBlockedByWorkflow($entity): bool
public function notBlockedByWorkflow(object $entity): bool
{
/**
* @var EntityWorkflow
*/
$workflow = $this->repository->findByRelatedEntity(get_class($entity), $entity->getId());
if ($workflow->isFinal()) {
return false;
}
$workflow = $this->entityWorkflowManager->findByRelatedEntity($entity);
$currentUser = $this->security->getUser();
if ($workflow->getCurrentStep()->getAllDestUser()->contains($currentUser)) {
return true;
if (null !== $workflow) {
if ($workflow->isFinal()) {
return false;
}
if ($workflow->getCurrentStep()->getAllDestUser()->contains($currentUser)) {
return true;
}
}
return false;
return true;
}
}