diff --git a/src/Bundle/ChillMainBundle/Controller/WorkflowController.php b/src/Bundle/ChillMainBundle/Controller/WorkflowController.php index 353369ecf..646a69438 100644 --- a/src/Bundle/ChillMainBundle/Controller/WorkflowController.php +++ b/src/Bundle/ChillMainBundle/Controller/WorkflowController.php @@ -82,7 +82,10 @@ class WorkflowController extends AbstractController $entityWorkflow ->setRelatedEntityClass($request->query->get('entityClass')) ->setRelatedEntityId($request->query->getInt('entityId')) - ->setWorkflowName($request->query->get('workflow')); + ->setWorkflowName($request->query->get('workflow')) + ->addSubscriberToStep($this->getUser()) + ->addSubscriberToFinal($this->getUser()) + ; $errors = $this->validator->validate($entityWorkflow, null, ['creation']); diff --git a/src/Bundle/ChillMainBundle/Entity/Workflow/EntityWorkflowStep.php b/src/Bundle/ChillMainBundle/Entity/Workflow/EntityWorkflowStep.php index c68247174..bde2f28ac 100644 --- a/src/Bundle/ChillMainBundle/Entity/Workflow/EntityWorkflowStep.php +++ b/src/Bundle/ChillMainBundle/Entity/Workflow/EntityWorkflowStep.php @@ -86,7 +86,7 @@ class EntityWorkflowStep private ?string $transitionAfter = null; /** - * @ORM\Column(type="datetime_immutable") + * @ORM\Column(type="datetime_immutable", nullable=true, options={"default": null}) */ private ?DateTimeImmutable $transitionAt = null; @@ -101,9 +101,15 @@ class EntityWorkflowStep */ private ?string $transitionByEmail = null; + /** + * @ORM\Column(type="text", nullable=false) + */ + private string $accessKey; + public function __construct() { $this->destUser = new ArrayCollection(); + $this->accessKey = bin2hex(openssl_random_pseudo_bytes(32)); } public function addDestEmail(string $email): self @@ -119,6 +125,9 @@ class EntityWorkflowStep { if (!$this->destUser->contains($user)) { $this->destUser[] = $user; + $this->getEntityWorkflow() + ->addSubscriberToFinal($user) + ->addSubscriberToStep($user); } return $this; diff --git a/src/Bundle/ChillMainBundle/migrations/Version20220223171457.php b/src/Bundle/ChillMainBundle/migrations/Version20220223171457.php new file mode 100644 index 000000000..c79954fa3 --- /dev/null +++ b/src/Bundle/ChillMainBundle/migrations/Version20220223171457.php @@ -0,0 +1,40 @@ +addSql('ALTER TABLE chill_main_workflow_entity_step ADD accessKey TEXT DEFAULT NULL'); + $this->addSql('WITH randoms AS (select + cmwes.id, + string_agg(substr(characters, (random() * length(characters) + 0.5)::integer, 1), \'\') as random_word + from (values(\'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789\')) as symbols(characters) + -- length of word + join generate_series(1, 32) on 1 = 1 + JOIN chill_main_workflow_entity_step cmwes ON true + GROUP BY cmwes.id) + UPDATE chill_main_workflow_entity_step SET accessKey = randoms.random_word FROM randoms WHERE chill_main_workflow_entity_step.id = randoms.id'); + $this->addSql('ALTER TABLE chill_main_workflow_entity_step ALTER accessKey DROP DEFAULT '); + $this->addSql('ALTER TABLE chill_main_workflow_entity_step ALTER accessKey SET NOT NULL'); + } + + public function down(Schema $schema): void + { + $this->addSql('ALTER TABLE chill_main_workflow_entity_step DROP accessKey'); + } +}