mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-09-04 05:44:58 +00:00
Allow users to edit a document if they were added to the previous step of a workflow.
OP#826 Workflow - les utilisateurs des étapes précédentes sur un workflow doivent aussi avoir la main sur les étapes en cours du workflow (Vendee/accent-suivi-developpement/1289) https://champs-libres.openproject.com/work_packages/826
This commit is contained in:
@@ -16,6 +16,9 @@ use Chill\MainBundle\Workflow\EntityWorkflowManager;
|
||||
use Symfony\Component\Security\Core\Security;
|
||||
use Symfony\Component\Workflow\Registry;
|
||||
|
||||
/**
|
||||
* Check if an object, associated with a workflow, is blocked, or not, by this workflow.
|
||||
*/
|
||||
class WorkflowStoredObjectPermissionHelper
|
||||
{
|
||||
public function __construct(
|
||||
@@ -24,28 +27,19 @@ class WorkflowStoredObjectPermissionHelper
|
||||
private readonly Registry $registry,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* Return true if the user is allowed to update the given object.
|
||||
*
|
||||
* Return false if some workflow block the edition of the object.
|
||||
*/
|
||||
public function notBlockedByWorkflow(object $entity): bool
|
||||
{
|
||||
$entityWorkflows = $this->entityWorkflowManager->findByRelatedEntity($entity);
|
||||
$currentUser = $this->security->getUser();
|
||||
|
||||
$usersInvolved = [];
|
||||
$entityWorkflowsNotFinalizedPositive = [];
|
||||
foreach ($entityWorkflows as $entityWorkflow) {
|
||||
if ($entityWorkflow->isFinal()) {
|
||||
|
||||
$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 ($entityWorkflow->getSteps() as $step) {
|
||||
@@ -55,6 +49,33 @@ class WorkflowStoredObjectPermissionHelper
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($entityWorkflow->isFinal()) {
|
||||
$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 {
|
||||
$entityWorkflowsNotFinalizedPositive[] = $entityWorkflow;
|
||||
foreach ($entityWorkflow->getSteps() as $step) {
|
||||
foreach ($step->getAllDestUser()->toArray() as $user) {
|
||||
$usersInvolved[] = $user;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// if there isn't any user, but a workflow, blocked
|
||||
if ([] !== $entityWorkflowsNotFinalizedPositive) {
|
||||
if ([] === $usersInvolved) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return in_array($currentUser, $usersInvolved, true);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
Reference in New Issue
Block a user