Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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: <id>)`), 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
------
Expand Down
7 changes: 6 additions & 1 deletion src/Controller/Admin/Process/LaunchAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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',
Expand Down
8 changes: 8 additions & 0 deletions src/Controller/Admin/Process/ListAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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',
[
Expand Down
16 changes: 16 additions & 0 deletions tests/Functional/LaunchActionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]"]'));
}
}
15 changes: 15 additions & 0 deletions tests/Functional/ProcessListTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Loading