Skip to content

Commit 9cf93a2

Browse files
authored
Merge pull request #8233 from ProcessMaker/bugfix/FOUR-24286
FOUR-24286: Advanced filter on PROCESS in task saved search does not work
2 parents 9b8f017 + 59c2f8f commit 9cf93a2

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

ProcessMaker/Filters/BaseFilter.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ abstract class BaseFilter
2929

3030
public const TYPE_PROCESS_NAME = 'ProcessName';
3131

32+
public const PROCESS_NAME_IN_REQUEST = 'process_request.name';
33+
3234
public const TYPE_RELATIONSHIP = 'Relationship';
3335

3436
public string|null $subjectValue;
@@ -98,6 +100,11 @@ private function apply($query): void
98100
$this->valueAliasAdapter($valueAliasMethod, $query);
99101
} elseif ($this->subjectType === self::TYPE_PROCESS) {
100102
$this->filterByProcessId($query);
103+
} elseif ($this->subjectValue === self::PROCESS_NAME_IN_REQUEST) {
104+
// For performance reasons, the task list uses the column process_request.name
105+
// But the filters must use the Process table, for this reason the subjectType is updated
106+
$this->subjectType = self::TYPE_PROCESS_NAME;
107+
$this->filterByProcessName($query);
101108
} elseif ($this->subjectType === self::TYPE_PROCESS_NAME) {
102109
$this->filterByProcessName($query);
103110
} elseif ($this->subjectType === self::TYPE_RELATIONSHIP) {

tests/Feature/Api/TasksTest.php

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -788,6 +788,54 @@ public function testAdvancedFilter()
788788
$this->assertEquals($hitTask->id, $json['data'][0]['id']);
789789
}
790790

791+
public function testAdvancedFilterByProcessRequestName()
792+
{
793+
$hitProcess = Process::factory()->create(['name' => 'foo']);
794+
$missProcess = Process::factory()->create(['name' => 'bar']);
795+
$hitRequest = ProcessRequest::factory()->create([
796+
'process_id' => $hitProcess->id,
797+
'name' => $hitProcess->name,
798+
]);
799+
$missRequest = ProcessRequest::factory()->create([
800+
'process_id' => $missProcess->id,
801+
]);
802+
$hitTask = ProcessRequestToken::factory()->create([
803+
'process_request_id' => $hitRequest->id,
804+
]);
805+
ProcessRequestToken::factory()->create([
806+
'process_request_id' => $missRequest->id,
807+
]);
808+
809+
// Filter by operator =
810+
$filterString = json_encode([
811+
[
812+
'subject' => ['type' => 'Field', 'value' => 'process_request.name'],
813+
'operator' => '=',
814+
'value' => $hitProcess->name,
815+
816+
],
817+
]);
818+
819+
$response = $this->apiCall('GET', '/tasks', ['advanced_filter' => $filterString]);
820+
$json = $response->json();
821+
822+
$this->assertEquals($hitTask->id, $json['data'][0]['id']);
823+
// Filter by operator contains
824+
$filterString = json_encode([
825+
[
826+
'subject' => ['type' => 'Field', 'value' => 'process_request.name'],
827+
'operator' => 'contains',
828+
'value' => $hitProcess->name,
829+
830+
],
831+
]);
832+
833+
$response = $this->apiCall('GET', '/tasks', ['advanced_filter' => $filterString]);
834+
$json = $response->json();
835+
836+
$this->assertEquals($hitTask->id, $json['data'][0]['id']);
837+
}
838+
791839
public function testGetScreenFields()
792840
{
793841
$this->be($this->user);

0 commit comments

Comments
 (0)