PMCORE-4058
This commit is contained in:
@@ -11,6 +11,7 @@ use ProcessMaker\Model\Delegation;
|
||||
use ProcessMaker\Model\Documents;
|
||||
use ProcessMaker\Model\ListUnassigned;
|
||||
use ProcessMaker\Model\Process;
|
||||
use ProcessMaker\Model\ProcessUser;
|
||||
use ProcessMaker\Model\Step;
|
||||
use ProcessMaker\Model\Task;
|
||||
use ProcessMaker\Model\Triggers;
|
||||
@@ -424,4 +425,62 @@ class CasesTest extends TestCase
|
||||
$this->assertArrayHasKey('PRO_UID', $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* It tests the response true of supervisor function
|
||||
*
|
||||
* @covers \ProcessMaker\BusinessModel\Cases::isSupervisor()
|
||||
* @test
|
||||
*/
|
||||
public function it_should_test_supervisor_true()
|
||||
{
|
||||
$process = Process::factory()->create();
|
||||
ProcessUser::factory()->create([
|
||||
'PU_TYPE' => 'SUPERVISOR',
|
||||
'PRO_UID' => $process->PRO_UID,
|
||||
'USR_UID' => $process->PRO_CREATE_USER
|
||||
]);
|
||||
$application = Application::factory()->create([
|
||||
'PRO_UID' => $process->PRO_UID
|
||||
]);
|
||||
Delegation::factory()->create([
|
||||
'APP_UID' => $application->APP_UID,
|
||||
'APP_NUMBER' => $application->APP_NUMBER,
|
||||
'PRO_UID' => $process->PRO_UID,
|
||||
'PRO_ID' => $process->PRO_ID
|
||||
]);
|
||||
|
||||
$process = Process::factory()->create();
|
||||
|
||||
$cases = new Cases();
|
||||
$result = $cases->isSupervisor($process->PRO_CREATE_USER, $application->APP_NUMBER);
|
||||
|
||||
// Asserts
|
||||
$this->assertTrue($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* It tests the response false of supervisor function
|
||||
*
|
||||
* @covers \ProcessMaker\BusinessModel\Cases::isSupervisor()
|
||||
* @test
|
||||
*/
|
||||
public function it_should_test_supervisor_false()
|
||||
{
|
||||
$process = Process::factory()->create();
|
||||
$application = Application::factory()->create([
|
||||
'PRO_UID' => $process->PRO_UID
|
||||
]);
|
||||
Delegation::factory()->create([
|
||||
'APP_UID' => $application->APP_UID,
|
||||
'APP_NUMBER' => $application->APP_NUMBER,
|
||||
'PRO_UID' => $process->PRO_UID,
|
||||
'PRO_ID' => $process->PRO_ID
|
||||
]);
|
||||
|
||||
$cases = new Cases();
|
||||
$result = $cases->isSupervisor($process->PRO_CREATE_USER, $application->APP_NUMBER);
|
||||
|
||||
// Asserts
|
||||
$this->assertNotTrue($result);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -904,6 +904,26 @@ class Cases
|
||||
return $permission;
|
||||
}
|
||||
|
||||
/**
|
||||
* Review if the user is supervisor
|
||||
*
|
||||
* @param string $usrUid
|
||||
* @param int $caseNumber
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isSupervisor(string $usrUid, int $caseNumber)
|
||||
{
|
||||
$result = [];
|
||||
$user = new BmUser();
|
||||
if ($user->checkPermission($usrUid, 'PM_SUPERVISOR')) {
|
||||
$processes = ProcessUser::getProcessesOfSupervisor($usrUid);
|
||||
$query = Delegation::query()->select(['APP_NUMBER'])->case($caseNumber)->processInList($processes);
|
||||
$result = $query->get()->values()->toArray();
|
||||
}
|
||||
return !empty($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reassign Case
|
||||
*
|
||||
|
||||
@@ -1037,6 +1037,30 @@ class Cases extends Api
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* User case supervisor permissions
|
||||
*
|
||||
* @url GET /:appNumber/supervisor
|
||||
*
|
||||
* @param int $appNumber
|
||||
*
|
||||
* @return boolean
|
||||
* @throws RestException
|
||||
*
|
||||
* @access protected
|
||||
* @class AccessControl {@permission PM_CASES}
|
||||
*/
|
||||
public function isSupervisor(int $appNumber)
|
||||
{
|
||||
try {
|
||||
$userUid = $this->getUserId();
|
||||
$cases = new BmCases();
|
||||
return $cases->isSupervisor($userUid, $appNumber);
|
||||
} catch (Exception $e) {
|
||||
throw new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Assign Case
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user