diff --git a/src/Bundle/ChillMainBundle/Entity/Workflow/EntityWorkflow.php b/src/Bundle/ChillMainBundle/Entity/Workflow/EntityWorkflow.php index 89efde7c0..d25d20d6a 100644 --- a/src/Bundle/ChillMainBundle/Entity/Workflow/EntityWorkflow.php +++ b/src/Bundle/ChillMainBundle/Entity/Workflow/EntityWorkflow.php @@ -442,10 +442,14 @@ class EntityWorkflow implements TrackCreationInterface, TrackUpdateInterface $newStep->addCcUser($user); } - foreach ($transitionContextDTO->futureDestUsers as $user) { + foreach ($transitionContextDTO->getFutureDestUsers() as $user) { $newStep->addDestUser($user); } + foreach ($transitionContextDTO->getFutureDestUserGroups() as $userGroup) { + $newStep->addDestUserGroup($userGroup); + } + if (null !== $transitionContextDTO->futureUserSignature) { $newStep->addDestUser($transitionContextDTO->futureUserSignature); } diff --git a/src/Bundle/ChillMainBundle/Entity/Workflow/EntityWorkflowStep.php b/src/Bundle/ChillMainBundle/Entity/Workflow/EntityWorkflowStep.php index c6a849da5..419b42a83 100644 --- a/src/Bundle/ChillMainBundle/Entity/Workflow/EntityWorkflowStep.php +++ b/src/Bundle/ChillMainBundle/Entity/Workflow/EntityWorkflowStep.php @@ -12,6 +12,7 @@ declare(strict_types=1); namespace Chill\MainBundle\Entity\Workflow; use Chill\MainBundle\Entity\User; +use Chill\MainBundle\Entity\UserGroup; use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\Collection; use Doctrine\ORM\Mapping as ORM; @@ -48,6 +49,13 @@ class EntityWorkflowStep #[ORM\JoinTable(name: 'chill_main_workflow_entity_step_user')] private Collection $destUser; + /** + * @var Collection + */ + #[ORM\ManyToMany(targetEntity: UserGroup::class)] + #[ORM\JoinTable(name: 'chill_main_workflow_entity_step_user_group')] + private Collection $destUserGroups; + /** * @var Collection */ @@ -108,6 +116,7 @@ class EntityWorkflowStep { $this->ccUser = new ArrayCollection(); $this->destUser = new ArrayCollection(); + $this->destUserGroups = new ArrayCollection(); $this->destUserByAccessKey = new ArrayCollection(); $this->signatures = new ArrayCollection(); $this->holdsOnStep = new ArrayCollection(); @@ -141,6 +150,22 @@ class EntityWorkflowStep return $this; } + public function addDestUserGroup(UserGroup $userGroup): self + { + if (!$this->destUserGroups->contains($userGroup)) { + $this->destUserGroups[] = $userGroup; + } + + return $this; + } + + public function removeDestUserGroup(UserGroup $userGroup): self + { + $this->destUserGroups->removeElement($userGroup); + + return $this; + } + public function addDestUserByAccessKey(User $user): self { if (!$this->destUserByAccessKey->contains($user) && !$this->destUser->contains($user)) { diff --git a/src/Bundle/ChillMainBundle/Form/WorkflowStepType.php b/src/Bundle/ChillMainBundle/Form/WorkflowStepType.php index e2aece468..8ab17e1e1 100644 --- a/src/Bundle/ChillMainBundle/Form/WorkflowStepType.php +++ b/src/Bundle/ChillMainBundle/Form/WorkflowStepType.php @@ -15,6 +15,7 @@ use Chill\MainBundle\Entity\Workflow\EntityWorkflow; use Chill\MainBundle\Form\Type\ChillCollectionType; use Chill\MainBundle\Form\Type\ChillTextareaType; use Chill\MainBundle\Form\Type\PickUserDynamicType; +use Chill\MainBundle\Form\Type\PickUserGroupOrUserDynamicType; use Chill\MainBundle\Templating\TranslatableStringHelperInterface; use Chill\MainBundle\Workflow\WorkflowTransitionContextDTO; use Chill\PersonBundle\Form\Type\PickPersonDynamicType; @@ -156,7 +157,7 @@ class WorkflowStepType extends AbstractType 'label' => 'workflow.signature_zone.user signature', 'multiple' => false, ]) - ->add('futureDestUsers', PickUserDynamicType::class, [ + ->add('futureDestUsers', PickUserGroupOrUserDynamicType::class, [ 'label' => 'workflow.dest for next steps', 'multiple' => true, 'empty_data' => '[]', diff --git a/src/Bundle/ChillMainBundle/Workflow/WorkflowTransitionContextDTO.php b/src/Bundle/ChillMainBundle/Workflow/WorkflowTransitionContextDTO.php index f675b9646..cc22d614a 100644 --- a/src/Bundle/ChillMainBundle/Workflow/WorkflowTransitionContextDTO.php +++ b/src/Bundle/ChillMainBundle/Workflow/WorkflowTransitionContextDTO.php @@ -12,6 +12,7 @@ declare(strict_types=1); namespace Chill\MainBundle\Workflow; use Chill\MainBundle\Entity\User; +use Chill\MainBundle\Entity\UserGroup; use Chill\MainBundle\Entity\Workflow\EntityWorkflow; use Chill\PersonBundle\Entity\Person; use Symfony\Component\Validator\Constraints as Assert; @@ -24,25 +25,25 @@ use Symfony\Component\Workflow\Transition; class WorkflowTransitionContextDTO { /** - * a list of future dest users for the next steps. + * a list of future dest users or user groups for the next step. * * This is in used in order to let controller inform who will be the future users which will validate * the next step. This is necessary to perform some computation about the next users, before they are * associated to the entity EntityWorkflowStep. * - * @var array|User[] + * @var list */ public array $futureDestUsers = []; /** - * a list of future cc users for the next steps. + * a list of future cc users for the next step. * * @var array|User[] */ public array $futureCcUsers = []; /** - * a list of future dest emails for the next steps. + * a list of future dest emails for the next step. * * This is in used in order to let controller inform who will be the future emails which will validate * the next step. This is necessary to perform some computation about the next emails, before they are @@ -72,6 +73,22 @@ class WorkflowTransitionContextDTO public EntityWorkflow $entityWorkflow, ) {} + /** + * @return list + */ + public function getFutureDestUsers(): array + { + return array_values(array_filter($this->futureDestUsers, fn (User|UserGroup $user) => $user instanceof User)); + } + + /** + * @return list + */ + public function getFutureDestUserGroups(): array + { + return array_values(array_filter($this->futureDestUsers, fn (User|UserGroup $user) => $user instanceof UserGroup)); + } + #[Assert\Callback()] public function validateCCUserIsNotInDest(ExecutionContextInterface $context, $payload): void { diff --git a/src/Bundle/ChillMainBundle/migrations/Version20240926132856.php b/src/Bundle/ChillMainBundle/migrations/Version20240926132856.php new file mode 100644 index 000000000..e14bf7e78 --- /dev/null +++ b/src/Bundle/ChillMainBundle/migrations/Version20240926132856.php @@ -0,0 +1,39 @@ +addSql('CREATE TABLE chill_main_workflow_entity_step_user_group (entityworkflowstep_id INT NOT NULL, usergroup_id INT NOT NULL, PRIMARY KEY(entityworkflowstep_id, usergroup_id))'); + $this->addSql('CREATE INDEX IDX_AB433F907E6AF9D4 ON chill_main_workflow_entity_step_user_group (entityworkflowstep_id)'); + $this->addSql('CREATE INDEX IDX_AB433F90D2112630 ON chill_main_workflow_entity_step_user_group (usergroup_id)'); + $this->addSql('ALTER TABLE chill_main_workflow_entity_step_user_group ADD CONSTRAINT FK_AB433F907E6AF9D4 FOREIGN KEY (entityworkflowstep_id) REFERENCES chill_main_workflow_entity_step (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE'); + $this->addSql('ALTER TABLE chill_main_workflow_entity_step_user_group ADD CONSTRAINT FK_AB433F90D2112630 FOREIGN KEY (usergroup_id) REFERENCES chill_main_user_group (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE'); + } + + public function down(Schema $schema): void + { + $this->addSql('ALTER TABLE chill_main_workflow_entity_step_user_group DROP CONSTRAINT FK_AB433F907E6AF9D4'); + $this->addSql('ALTER TABLE chill_main_workflow_entity_step_user_group DROP CONSTRAINT FK_AB433F90D2112630'); + $this->addSql('DROP TABLE chill_main_workflow_entity_step_user_group'); + } +}