mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-21 23:23:51 +00:00
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:
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user