Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FOUR-19816 when I start a case and route to the next task with the same user the "In Progress" cases list is empty #7624

Merged
merged 2 commits into from
Oct 25, 2024
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
10 changes: 6 additions & 4 deletions ProcessMaker/Repositories/CaseRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public function create(ExecutionInstanceInterface $instance): void
'user_id' => $instance->user_id,
'case_title' => $instance->case_title,
'case_title_formatted' => $instance->case_title_formatted,
'case_status' => $instance->status === CaseStatusConstants::ACTIVE ? CaseStatusConstants::IN_PROGRESS : $instance->status,
'case_status' => CaseUtils::getStatus($instance->status),
'processes' => CaseUtils::storeProcesses(collect(), $processData),
'requests' => CaseUtils::storeRequests(collect(), $requestData),
'request_tokens' => [],
Expand Down Expand Up @@ -118,7 +118,7 @@ public function update(ExecutionInstanceInterface $instance, TokenInterface $tok

$this->case->case_title = $instance->case_title;
$this->case->case_title_formatted = $instance->case_title_formatted;
$this->case->case_status = $instance->status === CaseStatusConstants::ACTIVE ? CaseStatusConstants::IN_PROGRESS : $instance->status;
$this->case->case_status = CaseUtils::getStatus($instance->status);
$this->case->request_tokens = CaseUtils::storeRequestTokens($this->case->request_tokens, $token->getKey());
$this->case->tasks = CaseUtils::storeTasks($this->case->tasks, $taskData);
$this->case->keywords = CaseUtils::getKeywords($dataKeywords);
Expand Down Expand Up @@ -146,11 +146,13 @@ public function updateStatus(ExecutionInstanceInterface $instance): void
}

try {
$caseStatus = CaseUtils::getStatus($instance->status);

$data = [
'case_status' => $instance->status,
'case_status' => $caseStatus,
];

if ($instance->status === CaseStatusConstants::COMPLETED) {
if ($caseStatus === CaseStatusConstants::COMPLETED) {
$data['completed_at'] = Carbon::now();
}

Expand Down
3 changes: 1 addition & 2 deletions ProcessMaker/Repositories/CaseSyncRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace ProcessMaker\Repositories;

use Illuminate\Support\Collection;
use ProcessMaker\Constants\CaseStatusConstants;
use ProcessMaker\Models\CaseParticipated;
use ProcessMaker\Models\CaseStarted;
use ProcessMaker\Models\ProcessRequest;
Expand Down Expand Up @@ -49,7 +48,7 @@ public static function syncCases(array $requestIds): array
$caseStartedRequestTokens = collect();
$caseStartedTasks = collect();
$participants = $instance->participants->pluck('id');
$status = $instance->status === CaseStatusConstants::ACTIVE ? CaseStatusConstants::IN_PROGRESS : $instance->status;
$status = CaseUtils::getStatus($instance->status);

$caseParticipatedData = self::prepareCaseStartedData($instance, $status, $participants);

Expand Down
19 changes: 17 additions & 2 deletions ProcessMaker/Repositories/CaseUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
namespace ProcessMaker\Repositories;

use Illuminate\Support\Collection;
use ProcessMaker\Nayra\Contracts\Bpmn\TokenInterface;
use ProcessMaker\Nayra\Contracts\Engine\ExecutionInstanceInterface;
use ProcessMaker\Constants\CaseStatusConstants;

class CaseUtils
{
Expand Down Expand Up @@ -167,4 +166,20 @@ public static function extractData(object $object, array $mapping): array
}
return $data;
}

/**
* The getStatus function returns the status of a case as "IN_PROGRESS" if it is "ACTIVE", otherwise it returns the
* current status.
*
* @param string instanceStatus The `instanceStatus` parameter is a string that represents the status of a case
* instance. The `getStatus` function compares this status with the `ACTIVE` status defined in the
* `CaseStatusConstants` class. If the `instanceStatus` is `ACTIVE`, the function returns `IN_PROGRESS
*
* @return If the is equal to CaseStatusConstants::ACTIVE, then CaseStatusConstants::IN_PROGRESS will
* be returned. Otherwise, will be returned as is.
*/
public static function getStatus(string $instanceStatus)
{
return $instanceStatus === CaseStatusConstants::ACTIVE ? CaseStatusConstants::IN_PROGRESS : $instanceStatus;
}
}
22 changes: 22 additions & 0 deletions tests/Feature/Api/V1_1/CaseUtilsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Illuminate\Support\Collection;
use PHPUnit\Framework\TestCase;
use ProcessMaker\Constants\CaseStatusConstants;
use ProcessMaker\Repositories\CaseUtils;

class CaseUtilsTest extends TestCase
Expand Down Expand Up @@ -174,4 +175,25 @@ public function test_extract_data_with_partial_object()
];
$this->assertEquals($expected, CaseUtils::extractData($object, $mapping));
}

public function testGetStatusInProgress()
{
$instanceStatus = CaseStatusConstants::ACTIVE;
$expected = CaseStatusConstants::IN_PROGRESS;
$this->assertEquals($expected, CaseUtils::getStatus($instanceStatus));
}

public function testGetStatusCompleted()
{
$instanceStatus = CaseStatusConstants::COMPLETED;
$expected = CaseStatusConstants::COMPLETED;
$this->assertEquals($expected, CaseUtils::getStatus($instanceStatus));
}

public function testGetStatusError()
{
$instanceStatus = 'ERROR';
$expected = 'ERROR';
$this->assertEquals($expected, CaseUtils::getStatus($instanceStatus));
}
}
Loading