Skip to content

Commit 9b49fba

Browse files
authored
Merge pull request #8738 from ProcessMaker/bugfix/FOUR-29448
FOUR-29448: The PMQL to filter in select list control is not working
2 parents 93d37ff + 97ae1a7 commit 9b49fba

2 files changed

Lines changed: 78 additions & 5 deletions

File tree

ProcessMaker/Traits/MakeHttpRequests.php

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -499,18 +499,27 @@ private function addQueryStringsParamsToUrl($endpoint, array $config, array $dat
499499
$parsedUrl = $this->parseUrl($url);
500500
$query = [];
501501
parse_str($parsedUrl['query'] ?? '', $query);
502-
if (array_key_exists('params', $endpoint)) {
502+
$hasEndpointParams = array_key_exists('params', $endpoint) && is_array($endpoint['params']);
503+
if ($hasEndpointParams) {
503504
foreach ($endpoint['params'] as $param) {
505+
if (!array_key_exists('key', $param)) {
506+
continue;
507+
}
508+
504509
$key = $this->evalMustache($param['key'], $data);
505510
// Get value from outbound configuration, if not defined get the default value
506-
$value = $params[$key] ?? $this->evalMustache($param['value'], $data);
507-
if ($value !== '' || $param['required']) {
511+
$value = $params[$key] ?? $this->evalMustache($param['value'] ?? '', $data);
512+
if ($value !== '' || ($param['required'] ?? false)) {
508513
$query[$key] = $value;
509514
}
510515
}
511-
} else {
516+
}
517+
518+
// Preserve legacy behavior for configured endpoint params, but when params are
519+
// missing/empty allow dynamic PARAM values (e.g. pmql from screen select-list).
520+
if (!$hasEndpointParams || empty($endpoint['params'])) {
512521
foreach ($params as $key => $value) {
513-
if ($value !== '') {
522+
if ($value !== '' && !array_key_exists($key, $query)) {
514523
$query[$key] = $value;
515524
}
516525
}

tests/Feature/MakeHttpRequestTest.php

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,70 @@ public function testRequestConstructionWithoutCommonParams()
128128
$this->assertEquals('json', $bodyType);
129129
}
130130

131+
public function testRequestConstructionAddsDynamicParamsWhenEndpointParamsAreEmpty()
132+
{
133+
$testStub = new class {
134+
use MakeHttpRequests;
135+
};
136+
$testStub->endpoints = json_decode('{"records":{"url":"https://example.test/api/1.0/collections/4/records","body":"","view":false,"method":"GET","params":[],"headers":[],"purpose":"records","body_type":"raw","outboundConfig":[]}}', true);
137+
$testStub->credentials = ['verify_certificate' => true];
138+
$testStub->authtype = 'NONE';
139+
140+
$endpointConfig = [
141+
'dataSource' => 1,
142+
'endpoint' => 'records',
143+
'outboundConfig' => [
144+
['value' => '{{pmqlValue}}', 'type' => 'PARAM', 'key' => 'pmql', 'format' => 'mustache'],
145+
],
146+
];
147+
$requestData = [
148+
'pmqlValue' => 'data.form_input_1=Lorem',
149+
];
150+
151+
$request = $this->callMethod(
152+
$testStub,
153+
'prepareRequestWithOutboundConfig',
154+
[$requestData, &$endpointConfig]
155+
);
156+
[$method, $url] = array_values($request);
157+
158+
$this->assertEquals('GET', $method);
159+
parse_str(parse_url($url, PHP_URL_QUERY), $query);
160+
$this->assertArrayHasKey('pmql', $query);
161+
$this->assertEquals('data.form_input_1=Lorem', $query['pmql']);
162+
}
163+
164+
public function testRequestConstructionWithEmptyEndpointParamsDoesNotOverwriteExistingQueryParams()
165+
{
166+
$testStub = new class {
167+
use MakeHttpRequests;
168+
};
169+
$testStub->endpoints = json_decode('{"records":{"url":"https://example.test/api/1.0/collections/4/records?pmql=data.form_input_1%3D%22Original%22","body":"","view":false,"method":"GET","params":[],"headers":[],"purpose":"records","body_type":"raw","outboundConfig":[]}}', true);
170+
$testStub->credentials = ['verify_certificate' => true];
171+
$testStub->authtype = 'NONE';
172+
173+
$endpointConfig = [
174+
'dataSource' => 1,
175+
'endpoint' => 'records',
176+
'outboundConfig' => [
177+
['value' => '{{pmqlValue}}', 'type' => 'PARAM', 'key' => 'pmql', 'format' => 'mustache'],
178+
],
179+
];
180+
$requestData = [
181+
'pmqlValue' => 'data.form_input_1=Lorem',
182+
];
183+
184+
$request = $this->callMethod(
185+
$testStub,
186+
'prepareRequestWithOutboundConfig',
187+
[$requestData, &$endpointConfig]
188+
);
189+
[, $url] = array_values($request);
190+
191+
parse_str(parse_url($url, PHP_URL_QUERY), $query);
192+
$this->assertEquals('data.form_input_1="Original"', html_entity_decode($query['pmql']));
193+
}
194+
131195
/**
132196
* Verifies that different Guzzle Http Responses are mapped correctly calling the function responseWithHeaderData
133197
*/

0 commit comments

Comments
 (0)