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 @@ -22,6 +22,7 @@ Latest
* [#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.
* [#123](https://github.com/cleverage/ui-process-bundle/issues/123) HTTP API: the parameters of the query string are also read without body, and `queue` is read from the query string (the form data takes precedence). Add tests.

v3.0.2
------
Expand Down
3 changes: 2 additions & 1 deletion docs/reference/06-http_api.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ Parameters can be sent either as a JSON body, or as form data (`application/x-ww
| `context` | `object` or JSON `string` | | `{}` | Process context, as key/value pairs. With form data, send one field per value: `context[key]=value`. |
| `queue` | `bool` | | `true` | `true`: the process is queued to the `execute_process` transport (see [messenger](08-messenger.md)). `false`: the process is executed during the HTTP request. |

With form data, `code` and `input` can also be passed in the query string.
`code`, `input`, `context` and `queue` can also be passed in the query string, with form data or without body (the form
data takes precedence).

Responses
---------
Expand Down
8 changes: 6 additions & 2 deletions src/Http/ValueResolver/HttpProcessExecuteValueResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@ public function resolve(Request $request, ArgumentMetadata $argument): iterable
{
try {
$hasRequestData = $request->request->count() > 0 || $request->files->count() > 0;
// The query string is read with form data, and also without body
$hasQueryOnly = !$hasRequestData && '' === $request->getContent() && $request->query->count() > 0;

if (!$hasRequestData) {
if (!$hasRequestData && !$hasQueryOnly) {
$content = $request->getContent();
if (empty($content)) {
return [new HttpProcessExecution()];
Expand Down Expand Up @@ -65,7 +67,9 @@ public function resolve(Request $request, ArgumentMetadata $argument): iterable
$context = $request->query->all('context');
}

$queue = $request->request->getBoolean('queue', true);
$queue = $request->request->has('queue')
? $request->request->getBoolean('queue')
: $request->query->getBoolean('queue', true);

$httpProcessExecution = new HttpProcessExecution(
(string) $code,
Expand Down
12 changes: 12 additions & 0 deletions tests/Functional/HttpProcessExecuteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,18 @@ public function testSynchronousExecution(): void
self::assertSame([], $this->getDispatchedMessages());
}

/**
* Parameters in the query string only, without body (they were ignored: 422 "Process code is required").
*/
public function testQueryStringWithoutBody(): void
{
$this->client->request('POST', '/http/process/execute?code=test.process&queue=0', server: ['HTTP_AUTHORIZATION' => 'Bearer '.self::TOKEN]);

self::assertResponseIsSuccessful();
self::assertSame('"Process has been proceed well."', $this->client->getResponse()->getContent());
self::assertSame([], $this->getDispatchedMessages());
}

public function testFailingSynchronousExecution(): void
{
$this->execute(['code' => 'test.failing', 'queue' => '0']);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,30 @@ public function testQueryParametersWithFormData(): void
);
}

public function testQueryParametersWithoutBody(): void
{
$request = Request::create('/http/process/execute?code=test.process&input=data.csv&context[foo]=bar&queue=0', 'POST');

self::assertEquals(
new HttpProcessExecution('test.process', 'data.csv', ['foo' => 'bar'], false),
$this->resolve($request)
);
}

public function testQueueFromTheQueryString(): void
{
$request = Request::create('/http/process/execute?queue=0', 'POST', ['code' => 'test.process']);

self::assertEquals(new HttpProcessExecution('test.process', null, [], false), $this->resolve($request));
}

public function testQueueOfTheBodyOverridesTheQueryString(): void
{
$request = Request::create('/http/process/execute?queue=0', 'POST', ['code' => 'test.process', 'queue' => '1']);

self::assertEquals(new HttpProcessExecution('test.process', null, [], true), $this->resolve($request));
}

public function testUploadedFileInput(): void
{
$file = tempnam(sys_get_temp_dir(), 'upload');
Expand Down
Loading