Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 2 additions & 2 deletions ProcessMaker/Http/Controllers/Api/TaskController.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,13 +136,13 @@ public function index(Request $request, $getTotal = false, User $user = null)

$this->applyAdvancedFilter($query, $request);

$this->applyForCurrentUser($query, $user);

// Apply filter overdue
$query->overdue($request->input('overdue'));

if ($request->input('processesIManage') === 'true') {
$this->applyProcessManager($query, $user);
} else {
$this->applyForCurrentUser($query, $user);
}

// If only the total is being requested (by a Saved Search), send it now
Expand Down
6 changes: 4 additions & 2 deletions ProcessMaker/Models/ProcessRequestToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -743,13 +743,15 @@ public function valueAliasStatus($value, $expression, $callback = null, User $us

$value = mb_strtolower($value);

return function ($query) use ($value, $statusMap, $expression, $user) {
$processesIManage = request()->input('processesIManage') === 'true';

return function ($query) use ($value, $statusMap, $expression, $user, $processesIManage) {
if ($value === 'self service') {
if (!$user) {
$user = auth()->user();
}

if ($user) {
if ($user && !$processesIManage) {
$taskIds = $user->availableSelfServiceTaskIds();
$query->whereIn('id', $taskIds);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class ProcessRequestTokenFactory extends Factory
public function definition(): array
{
return [
'element_type' => 'TASK',
'element_type' => 'task',
'element_id' => $this->faker->randomDigit(),
'element_name' => $this->faker->name(),
'status' => $this->faker->randomElement(['ACTIVE', 'FAILING', 'COMPLETED', 'CLOSED', 'EVENT_CATCH']),
Expand Down
57 changes: 57 additions & 0 deletions tests/Feature/Api/TaskControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -196,4 +196,61 @@ public function testIndexCaseReturnsWithData()
'meta',
]);
}

public function testProcessesIManage()
{
$managerUser = User::factory()->create();
$taskUser = User::factory()->create();
Auth::login($managerUser);

$process = Process::factory()->create([
'properties' => [
'manager_id' => $managerUser->id,
],
]);

$processRequest = ProcessRequest::factory()->create([
'process_id' => $process->id,
]);

$selfServiceTask = ProcessRequestToken::factory()->create([
'process_request_id' => $processRequest->id,
'process_id' => $process->id,
'user_id' => null,
'status' => 'ACTIVE',
'is_self_service' => true,
]);

$regularTask = ProcessRequestToken::factory()->create([
'process_request_id' => $processRequest->id,
'process_id' => $process->id,
'user_id' => $taskUser->id,
'status' => 'ACTIVE',
]);

$this->user = $managerUser;
$params = [
'processesIManage' => 'true',
'pmql' => '(status = "Self Service" or status = "In Progress")',
];
$response = $this->apiCall('GET', '/tasks', $params);
$this->assertCount(2, $response->json()['data']);
$this->assertEquals($selfServiceTask->id, $response->json()['data'][0]['id']);
$this->assertEquals($regularTask->id, $response->json()['data'][1]['id']);

// Add the advanced filter to only show the self service task
$params['advanced_filter'] = [
[
'subject' => [
'type' => 'Status',
'value' => 'status',
],
'operator' => '=',
'value' => 'Self Service',
],
];
$response = $this->apiCall('GET', '/tasks', $params);
$this->assertCount(1, $response->json()['data']);
$this->assertEquals($selfServiceTask->id, $response->json()['data'][0]['id']);
}
}
Loading