From ab44f240945760efa6e97a1e0d024dfd836af9b2 Mon Sep 17 00:00:00 2001 From: Nicolas Joubert Date: Thu, 8 Oct 2026 12:09:29 +0200 Subject: [PATCH] fix #121 Redirect /process/list and /process/launch to the dashboard when accessed directly Without the EasyAdmin context, their templates failed (500 "Impossible to access an attribute ("i18n")"). They are redirected to the dashboard URL (routeName), with the query parameters. Co-Authored-By: Claude Opus 5.5 (1M context) --- CHANGELOG.md | 1 + src/Controller/Admin/Process/LaunchAction.php | 7 ++++++- src/Controller/Admin/Process/ListAction.php | 8 ++++++++ tests/Functional/LaunchActionTest.php | 16 ++++++++++++++++ tests/Functional/ProcessListTest.php | 15 +++++++++++++++ 5 files changed, 46 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c5c14ce..8ade5d4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,7 @@ Latest * [#111](https://github.com/cleverage/ui-process-bundle/issues/111) `ProcessExecutionDurationFilter`: the filter values are bound as DQL parameters (they were concatenated in the DQL; not exploitable, the form field is numeric). Add tests. * [#113](https://github.com/cleverage/ui-process-bundle/issues/113) HTTP API, synchronous execution: the error message is followed by the id of the process execution (`(process execution: )`), to find its logs in the UI; add `ProcessExecutionManager::getLastProcessExecution()`. Add tests. * [#117](https://github.com/cleverage/ui-process-bundle/issues/117) Schedule validators: `every` expressions checked as the Symfony Scheduler does (`PeriodicalTrigger`): expressions such as `0 seconds`, `yesterday` or `monday` were accepted but stopped the `scheduler_cron` worker, ISO 8601 durations (`PT1H`) were refused; message fixed ("is not a valid \"every\" expression"). A "hashed" cron expression is refused (500). No `TypeError` on `null`. Add tests. +* [#121](https://github.com/cleverage/ui-process-bundle/issues/121) `ListAction` / `LaunchAction`: accessed directly (`/process/list`, `/process/launch`), redirected to the dashboard (`/process?routeName=...`) instead of a 500. Add tests. v3.0.2 ------ diff --git a/src/Controller/Admin/Process/LaunchAction.php b/src/Controller/Admin/Process/LaunchAction.php index b8e2fbd..07fc58e 100644 --- a/src/Controller/Admin/Process/LaunchAction.php +++ b/src/Controller/Admin/Process/LaunchAction.php @@ -19,6 +19,7 @@ use CleverAge\UiProcessBundle\Manager\ProcessConfigurationsManager; use CleverAge\UiProcessBundle\Message\ProcessExecuteMessage; use EasyCorp\Bundle\EasyAdminBundle\Config\Asset; +use EasyCorp\Bundle\EasyAdminBundle\Contracts\Context\AdminContextInterface; use EasyCorp\Bundle\EasyAdminBundle\Provider\AdminContextProvider; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\Filesystem\Filesystem; @@ -51,6 +52,10 @@ public function __construct( public function __invoke( string $uploadDirectory, ): Response { + // Accessed directly, not through the dashboard: the template needs the EasyAdmin context + if (!$this->adminContextProvider->getContext() instanceof AdminContextInterface) { + return $this->redirectToRoute('process', ['routeName' => 'process_launch'] + ($this->requestStack->getMainRequest()?->query->all() ?? [])); + } $processCode = (string) $this->requestStack->getMainRequest()?->query->get('process'); if ('' === $processCode) { throw new MissingProcessException(); @@ -105,7 +110,7 @@ public function __invoke( return $this->redirectToRoute('process', ['routeName' => 'process_list']); } - $this->adminContextProvider->getContext()?->getAssets()->addJsAsset(Asset::fromEasyAdminAssetPackage('field-collection.js')->getAsDto()); + $this->adminContextProvider->getContext()->getAssets()->addJsAsset(Asset::fromEasyAdminAssetPackage('field-collection.js')->getAsDto()); return $this->render( '@CleverAgeUiProcess/admin/process/launch.html.twig', diff --git a/src/Controller/Admin/Process/ListAction.php b/src/Controller/Admin/Process/ListAction.php index 78880ff..0355ed2 100644 --- a/src/Controller/Admin/Process/ListAction.php +++ b/src/Controller/Admin/Process/ListAction.php @@ -14,7 +14,9 @@ namespace CleverAge\UiProcessBundle\Controller\Admin\Process; use CleverAge\UiProcessBundle\Manager\ProcessConfigurationsManager; +use EasyCorp\Bundle\EasyAdminBundle\Contracts\Context\AdminContextInterface; use EasyCorp\Bundle\EasyAdminBundle\Contracts\Intl\IntlFormatterInterface; +use EasyCorp\Bundle\EasyAdminBundle\Provider\AdminContextProvider; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\Attribute\Route; @@ -27,11 +29,17 @@ class ListAction extends AbstractController public function __construct( private readonly IntlFormatterInterface $intlFormatter, private readonly ProcessConfigurationsManager $processConfigurationsManager, + private readonly AdminContextProvider $adminContextProvider, ) { } public function __invoke(): Response { + // Accessed directly, not through the dashboard: the template needs the EasyAdmin context + if (!$this->adminContextProvider->getContext() instanceof AdminContextInterface) { + return $this->redirectToRoute('process', ['routeName' => 'process_list']); + } + return $this->render( '@CleverAgeUiProcess/admin/process/list.html.twig', [ diff --git a/tests/Functional/LaunchActionTest.php b/tests/Functional/LaunchActionTest.php index 92c610b..72070c8 100644 --- a/tests/Functional/LaunchActionTest.php +++ b/tests/Functional/LaunchActionTest.php @@ -166,4 +166,20 @@ public function testUnknownProcess(): void self::assertResponseStatusCodeSame(500); self::assertSame([], $this->getDispatchedMessages()); } + + /** + * Accessed directly, not through the dashboard: redirected to the dashboard with the query parameters (the + * template of the form needs the EasyAdmin context, it was a 500). + */ + public function testDirectAccessRedirectsToTheDashboard(): void + { + $this->login(); + + $this->client->request('GET', '/process/launch?process=test.form'); + + self::assertResponseRedirects('/process?routeName=process_launch&process=test.form'); + $crawler = $this->client->followRedirect(); + self::assertResponseIsSuccessful(); + self::assertCount(1, $crawler->filter('input[name="launch[input]"]')); + } } diff --git a/tests/Functional/ProcessListTest.php b/tests/Functional/ProcessListTest.php index be8753d..77b12ec 100644 --- a/tests/Functional/ProcessListTest.php +++ b/tests/Functional/ProcessListTest.php @@ -111,4 +111,19 @@ public function testUserLocale(): void // EasyAdmin labels translated in the user locale self::assertStringContainsString('Déconnexion', $crawler->filter('body')->text()); } + + /** + * Accessed directly, not through the dashboard: redirected to the dashboard (the template needs the EasyAdmin + * context, it was a 500). + */ + public function testDirectAccessRedirectsToTheDashboard(): void + { + $this->login(); + + $this->client->request('GET', '/process/list'); + + self::assertResponseRedirects('/process?routeName=process_list'); + $this->client->followRedirect(); + self::assertResponseIsSuccessful(); + } }