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