From 4be6c09d4dffe70e9c83bbf0a4860bb666242ad9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Tue, 19 Nov 2024 10:50:46 +0100 Subject: [PATCH 1/5] Add unique constraints to prevent person_documnt and accompanyingcourse_document with duplicated object_id This change ensures `object_id` uniqueness within `person_document` and `accompanyingcourse_document` tables. It includes migration scripts and entity annotations to enforce these constraints. This helps maintain data integrity and consistency across the database. --- .../Entity/AccompanyingCourseDocument.php | 1 + .../ChillDocStoreBundle/Entity/Document.php | 1 + .../Entity/PersonDocument.php | 1 + .../migrations/Version20241118151618.php | 41 +++++++++++++++++++ 4 files changed, 44 insertions(+) create mode 100644 src/Bundle/ChillDocStoreBundle/migrations/Version20241118151618.php diff --git a/src/Bundle/ChillDocStoreBundle/Entity/AccompanyingCourseDocument.php b/src/Bundle/ChillDocStoreBundle/Entity/AccompanyingCourseDocument.php index d0e72e74f..9ff4c51fd 100644 --- a/src/Bundle/ChillDocStoreBundle/Entity/AccompanyingCourseDocument.php +++ b/src/Bundle/ChillDocStoreBundle/Entity/AccompanyingCourseDocument.php @@ -18,6 +18,7 @@ use Doctrine\ORM\Mapping as ORM; #[ORM\Entity] #[ORM\Table('chill_doc.accompanyingcourse_document')] +#[ORM\UniqueConstraint(name: 'acc_course_document_unique_stored_object', columns: ['object_id'])] class AccompanyingCourseDocument extends Document implements HasScopesInterface, HasCentersInterface { #[ORM\ManyToOne(targetEntity: AccompanyingPeriod::class)] diff --git a/src/Bundle/ChillDocStoreBundle/Entity/Document.php b/src/Bundle/ChillDocStoreBundle/Entity/Document.php index 1970d1127..b98159919 100644 --- a/src/Bundle/ChillDocStoreBundle/Entity/Document.php +++ b/src/Bundle/ChillDocStoreBundle/Entity/Document.php @@ -40,6 +40,7 @@ class Document implements TrackCreationInterface, TrackUpdateInterface #[Assert\Valid] #[Assert\NotNull(message: 'Upload a document')] #[ORM\ManyToOne(targetEntity: StoredObject::class, cascade: ['persist'])] + #[ORM\JoinColumn(name: 'object_id', referencedColumnName: 'id')] private ?StoredObject $object = null; #[ORM\ManyToOne(targetEntity: DocGeneratorTemplate::class)] diff --git a/src/Bundle/ChillDocStoreBundle/Entity/PersonDocument.php b/src/Bundle/ChillDocStoreBundle/Entity/PersonDocument.php index b6eefc733..95afaee8d 100644 --- a/src/Bundle/ChillDocStoreBundle/Entity/PersonDocument.php +++ b/src/Bundle/ChillDocStoreBundle/Entity/PersonDocument.php @@ -19,6 +19,7 @@ use Doctrine\ORM\Mapping as ORM; #[ORM\Entity] #[ORM\Table('chill_doc.person_document')] +#[ORM\UniqueConstraint(name: 'person_document_unique_stored_object', columns: ['object_id'])] class PersonDocument extends Document implements HasCenterInterface, HasScopeInterface { #[ORM\Id] diff --git a/src/Bundle/ChillDocStoreBundle/migrations/Version20241118151618.php b/src/Bundle/ChillDocStoreBundle/migrations/Version20241118151618.php new file mode 100644 index 000000000..b27d57517 --- /dev/null +++ b/src/Bundle/ChillDocStoreBundle/migrations/Version20241118151618.php @@ -0,0 +1,41 @@ +addSql(<<<'SQL' + WITH ranked AS ( + SELECT id, rank() OVER (PARTITION BY object_id ORDER BY id ASC) FROM chill_doc.accompanyingcourse_document + ) + DELETE FROM chill_doc.accompanyingcourse_document WHERE id IN (SELECT id FROM ranked where "rank" <> 1) + SQL); + $this->addSql('CREATE UNIQUE INDEX acc_course_document_unique_stored_object ON chill_doc.accompanyingcourse_document (object_id)'); + $this->addSql('CREATE UNIQUE INDEX person_document_unique_stored_object ON chill_doc.person_document (object_id)'); + } + + public function down(Schema $schema): void + { + $this->addSql('DROP INDEX acc_course_document_unique_stored_object'); + $this->addSql('DROP INDEX person_document_unique_stored_object'); + } +} From 04b2def8a5a628b38415b0948d57eaf7628fe26a Mon Sep 17 00:00:00 2001 From: LenaertsJ Date: Tue, 19 Nov 2024 10:15:15 +0000 Subject: [PATCH 2/5] Save the comments on a workflow step --- src/Bundle/ChillMainBundle/Entity/Workflow/EntityWorkflow.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Bundle/ChillMainBundle/Entity/Workflow/EntityWorkflow.php b/src/Bundle/ChillMainBundle/Entity/Workflow/EntityWorkflow.php index 99d5cdb7d..4ba8f9803 100644 --- a/src/Bundle/ChillMainBundle/Entity/Workflow/EntityWorkflow.php +++ b/src/Bundle/ChillMainBundle/Entity/Workflow/EntityWorkflow.php @@ -441,6 +441,8 @@ class EntityWorkflow implements TrackCreationInterface, TrackUpdateInterface $newStep = new EntityWorkflowStep(); $newStep->setCurrentStep($step); + $newStep->setComment($transitionContextDTO->comment); + foreach ($transitionContextDTO->futureCcUsers as $user) { $newStep->addCcUser($user); } From 3a1947df9eda2ee9a2a45f46c3d71d83968b80fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Tue, 19 Nov 2024 12:01:31 +0100 Subject: [PATCH 3/5] Add entity workflow title to notification Introduced `EntityWorkflowManager` to `NotificationOnTransition` to fetch and include the entity workflow title in notifications. Updated relevant tests to support the new functionality and verify the entity title retrieval process. --- .../EventSubscriber/NotificationOnTransitionTest.php | 10 +++++++++- .../EventSubscriber/NotificationOnTransition.php | 5 +++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/Bundle/ChillMainBundle/Tests/Workflow/EventSubscriber/NotificationOnTransitionTest.php b/src/Bundle/ChillMainBundle/Tests/Workflow/EventSubscriber/NotificationOnTransitionTest.php index e2fc30da8..9f90c5b12 100644 --- a/src/Bundle/ChillMainBundle/Tests/Workflow/EventSubscriber/NotificationOnTransitionTest.php +++ b/src/Bundle/ChillMainBundle/Tests/Workflow/EventSubscriber/NotificationOnTransitionTest.php @@ -16,6 +16,8 @@ use Chill\MainBundle\Entity\User; use Chill\MainBundle\Entity\UserGroup; use Chill\MainBundle\Entity\Workflow\EntityWorkflow; use Chill\MainBundle\Entity\Workflow\EntityWorkflowStep; +use Chill\MainBundle\Workflow\EntityWorkflowHandlerInterface; +use Chill\MainBundle\Workflow\EntityWorkflowManager; use Chill\MainBundle\Workflow\EventSubscriber\NotificationOnTransition; use Chill\MainBundle\Workflow\Helper\MetadataExtractor; use Doctrine\ORM\EntityManagerInterface; @@ -91,12 +93,18 @@ final class NotificationOnTransitionTest extends TestCase $security = $this->prophesize(Security::class); $security->getUser()->willReturn($currentUser); + $entityWorkflowHandler = $this->prophesize(EntityWorkflowHandlerInterface::class); + $entityWorkflowHandler->getEntityTitle($entityWorkflow)->willReturn('workflow title'); + $entityWorkflowManager = $this->prophesize(EntityWorkflowManager::class); + $entityWorkflowManager->getHandler($entityWorkflow)->willReturn($entityWorkflowHandler->reveal()); + $notificationOnTransition = new NotificationOnTransition( $em->reveal(), $engine->reveal(), $extractor->reveal(), $security->reveal(), - $registry->reveal() + $registry->reveal(), + $entityWorkflowManager->reveal(), ); $event = new Event($entityWorkflow, new Marking(), new Transition('dummy_transition', ['from_state'], ['to_state']), $workflow); diff --git a/src/Bundle/ChillMainBundle/Workflow/EventSubscriber/NotificationOnTransition.php b/src/Bundle/ChillMainBundle/Workflow/EventSubscriber/NotificationOnTransition.php index 5e33fc3c0..63482ddff 100644 --- a/src/Bundle/ChillMainBundle/Workflow/EventSubscriber/NotificationOnTransition.php +++ b/src/Bundle/ChillMainBundle/Workflow/EventSubscriber/NotificationOnTransition.php @@ -15,6 +15,7 @@ use Chill\MainBundle\Entity\Notification; use Chill\MainBundle\Entity\User; use Chill\MainBundle\Entity\UserGroup; use Chill\MainBundle\Entity\Workflow\EntityWorkflow; +use Chill\MainBundle\Workflow\EntityWorkflowManager; use Chill\MainBundle\Workflow\Helper\MetadataExtractor; use Doctrine\ORM\EntityManagerInterface; use Symfony\Component\EventDispatcher\EventSubscriberInterface; @@ -30,6 +31,7 @@ class NotificationOnTransition implements EventSubscriberInterface private readonly MetadataExtractor $metadataExtractor, private readonly Security $security, private readonly Registry $registry, + private EntityWorkflowManager $entityWorkflowManager, ) {} public static function getSubscribedEvents(): array @@ -62,6 +64,8 @@ class NotificationOnTransition implements EventSubscriberInterface /** @var array $dests array of unique values, where keys is the object's hash */ $dests = []; + $title = $this->entityWorkflowManager->getHandler($entityWorkflow)->getEntityTitle($entityWorkflow); + foreach (array_merge( // the subscriber to each step $entityWorkflow->getSubscriberToStep()->toArray(), @@ -112,6 +116,7 @@ class NotificationOnTransition implements EventSubscriberInterface static fn (User $u) => $u->getId(), $entityWorkflow->getCurrentStep()->getDestUser()->toArray() ), true), + 'title' => $title, ]; $notification = new Notification(); From 6ca4b91e1e62ea852a7c745c66ecd605e7a11499 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Tue, 19 Nov 2024 12:58:20 +0100 Subject: [PATCH 4/5] Refactor breadcrumb macro parameters in Workflow templates Updated the breadcrumb macro's parameters to accept `entity_workflow` directly instead of a context object. This change affects the index, list, and macro_breadcrumb templates, ensuring consistent parameter usage and improving readability. This avoid exploiting a bug which was solved in twig 3.15.0 --- .../Resources/views/Workflow/index.html.twig | 2 +- .../ChillMainBundle/Resources/views/Workflow/list.html.twig | 2 +- .../Resources/views/Workflow/macro_breadcrumb.html.twig | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Bundle/ChillMainBundle/Resources/views/Workflow/index.html.twig b/src/Bundle/ChillMainBundle/Resources/views/Workflow/index.html.twig index 48f7ef361..f469e7f66 100644 --- a/src/Bundle/ChillMainBundle/Resources/views/Workflow/index.html.twig +++ b/src/Bundle/ChillMainBundle/Resources/views/Workflow/index.html.twig @@ -37,7 +37,7 @@

{{ handler.entityTitle(entity_workflow) }}

- {{ macro.breadcrumb({'entity_workflow': entity_workflow}) }} + {{ macro.breadcrumb(entity_workflow) }} {% if entity_workflow.isOnHoldAtCurrentStep %} {{ 'workflow.On hold'|trans }} {% endif %} diff --git a/src/Bundle/ChillMainBundle/Resources/views/Workflow/list.html.twig b/src/Bundle/ChillMainBundle/Resources/views/Workflow/list.html.twig index 5dd6dc714..d9e86c3f4 100644 --- a/src/Bundle/ChillMainBundle/Resources/views/Workflow/list.html.twig +++ b/src/Bundle/ChillMainBundle/Resources/views/Workflow/list.html.twig @@ -68,7 +68,7 @@
- {{ macro.breadcrumb(l) }} + {{ macro.breadcrumb(l.entity_workflow) }} {% if l.entity_workflow.isOnHoldAtCurrentStep %} {{ 'workflow.On hold'|trans }} {% endif %} diff --git a/src/Bundle/ChillMainBundle/Resources/views/Workflow/macro_breadcrumb.html.twig b/src/Bundle/ChillMainBundle/Resources/views/Workflow/macro_breadcrumb.html.twig index 6a1c66ae7..b0141aae7 100644 --- a/src/Bundle/ChillMainBundle/Resources/views/Workflow/macro_breadcrumb.html.twig +++ b/src/Bundle/ChillMainBundle/Resources/views/Workflow/macro_breadcrumb.html.twig @@ -52,10 +52,10 @@ {% endif %} {% endmacro %} -{% macro breadcrumb(_ctx) %} +{% macro breadcrumb(entity_workflow) %}