diff --git a/CHANGELOG.md b/CHANGELOG.md index c6a997c..4a994aa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,7 @@ Latest * [#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. * [#119](https://github.com/cleverage/ui-process-bundle/issues/119) Launch form: a context row without key is left out of the context (reported by its `NotBlank` constraint): it gave a 500 when the process has constraints on the context, and a PHP 8.5 deprecation (`null` array offset). 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 21e0cfd..85cbb07 100644 --- a/tests/Functional/LaunchActionTest.php +++ b/tests/Functional/LaunchActionTest.php @@ -187,4 +187,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(); + } }