Allow to edit storedObject associated with workflow which are canceled

OP#753
This commit is contained in:
2024-10-21 15:59:54 +02:00
parent d45de5405b
commit ff5640e193
2 changed files with 85 additions and 12 deletions

View File

@@ -14,28 +14,41 @@ namespace Chill\DocStoreBundle\Service;
use Chill\MainBundle\Entity\Workflow\EntityWorkflowSignatureStateEnum;
use Chill\MainBundle\Workflow\EntityWorkflowManager;
use Symfony\Component\Security\Core\Security;
use Symfony\Component\Workflow\Registry;
class WorkflowStoredObjectPermissionHelper
{
public function __construct(private readonly Security $security, private readonly EntityWorkflowManager $entityWorkflowManager) {}
public function __construct(
private readonly Security $security,
private readonly EntityWorkflowManager $entityWorkflowManager,
private readonly Registry $registry,
) {}
public function notBlockedByWorkflow(object $entity): bool
{
$workflows = $this->entityWorkflowManager->findByRelatedEntity($entity);
$entityWorkflows = $this->entityWorkflowManager->findByRelatedEntity($entity);
$currentUser = $this->security->getUser();
foreach ($workflows as $workflow) {
if ($workflow->isFinal()) {
return false;
}
foreach ($entityWorkflows as $entityWorkflow) {
if ($entityWorkflow->isFinal()) {
if (!$workflow->getCurrentStep()->getAllDestUser()->contains($currentUser)) {
return false;
$workflow = $this->registry->get($entityWorkflow, $entityWorkflow->getWorkflowName());
$marking = $workflow->getMarkingStore()->getMarking($entityWorkflow);
foreach ($marking->getPlaces() as $place => $active) {
$metadata = $workflow->getMetadataStore()->getPlaceMetadata($place);
if ($metadata['isFinalPositive'] ?? true) {
return false;
}
}
} else {
if (!$entityWorkflow->getCurrentStep()->getAllDestUser()->contains($currentUser)) {
return false;
}
}
// as soon as there is one signatured applyied, we are not able to
// edit the document any more
foreach ($workflow->getSteps() as $step) {
foreach ($entityWorkflow->getSteps() as $step) {
foreach ($step->getSignatures() as $signature) {
if (EntityWorkflowSignatureStateEnum::SIGNED === $signature->getState()) {
return false;