Merged in bugfix/PMC-633 (pull request #6998)

PMC-633

Approved-by: Julio Cesar Laura Avendaño <contact@julio-laura.com>
This commit is contained in:
Andrea Adamczyk
2019-07-26 18:08:10 +00:00
committed by Julio Cesar Laura Avendaño
3 changed files with 195 additions and 95 deletions

View File

@@ -0,0 +1,155 @@
<?php
namespace Tests\unit\workflow\engine\src\ProcessMaker\Model;
use G;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use ProcessMaker\Model\Process;
use ProcessMaker\Model\User;
use Tests\TestCase;
/**
* @coversDefaultClass ProcessMaker\BusinessModel\Model\Process
*/
class ProcessTest extends TestCase
{
use DatabaseTransactions;
/**
* Test it returns all the processes for an specific user
* @covers ::getProcessList
* @test
*/
public function it_should_return_all_the_processes_for_an_specific_user()
{
//Create user
$user1 = factory(User::class)->create();
$user2 = factory(User::class)->create();
//Create process
$process1 = factory(Process::class)->create(
['PRO_CREATE_USER' => $user1['USR_UID']]
);
$process2 = factory(Process::class)->create(
['PRO_CREATE_USER' => $user2['USR_UID']]
);
//Create a Process object
$process = new Process();
//Call the getProcessList() method
$res = $process->getProcessList('', $user2['USR_UID']);
//Assert the result is not empty
$this->assertNotEmpty($res);
//Assert there's one result
$this->assertCount(1, $res);
//Assert that the process returned is the one looked for
$this->assertEquals($process2['PRO_UID'], $res[0]['PRO_UID']);
//Assert the process that was not searched is not in the result
$this->assertNotEquals($process1['PRO_UID'], $res[0]['PRO_UID']);
}
/**
* Tests that it returns the processes in an specific category
* @covers ::getProcessList
* @test
*/
public function it_should_return_the_processes_in_an_specific_category()
{
$catUid1 = G::generateUniqueID();
$catUid2 = G::generateUniqueID();
//Create user
$user = factory(User::class)->create();
//Create process
$process1 = factory(Process::class)->create(
[
'PRO_CREATE_USER' => $user['USR_UID'],
'PRO_CATEGORY' => $catUid1
]
);
$process2 = factory(Process::class)->create(
[
'PRO_CREATE_USER' => $user['USR_UID'],
'PRO_CATEGORY' => $catUid2
]
);
//Create a Process object
$process = new Process();
//Call the getProcessList() method
$res = $process->getProcessList($process1['PRO_CATEGORY'], $user['USR_UID']);
//Assert the result is not empty
$this->assertNotEmpty($res);
//Assert there's one result
$this->assertCount(1, $res);
//Assert that the process returned belong to the category searched
$this->assertEquals($process1['PRO_UID'], $res[0]['PRO_UID']);
//Assert the process which their category was not searched is not in the result
$this->assertNotEquals($process2['PRO_UID'], $res[0]['PRO_UID']);
}
/**
* Tests that it returns an empty array if no processes where found
* @covers ::getProcessList
* @test
*/
public function it_should_return_empty_if_no_processes_where_found()
{
//Create user
$user = factory(User::class)->create();
//Create a Process object
$process = new Process();
//Call the getProcessList() method
$res = $process->getProcessList('', $user['USR_UID']);
//Assert the result is not empty
$this->assertEmpty($res);
}
/**
* Test it returns all the processes in status active
* @covers ::getProcessList
* @test
*/
public function it_should_return_all_the_processes_in_status_active()
{
//Create user
$user = factory(User::class)->create();
//Create process
$process1 = factory(Process::class)->create(
[
'PRO_CREATE_USER' => $user['USR_UID'],
'PRO_STATUS' => 'ACTIVE'
]
);
$process2 = factory(Process::class)->create(
[
'PRO_CREATE_USER' => $user['USR_UID'],
'PRO_STATUS' => 'INACTIVE'
]
);
$process3 = factory(Process::class)->create(
[
'PRO_CREATE_USER' => $user['USR_UID'],
'PRO_STATUS' => 'DISABLED'
]
);
//Create a Process object
$process = new Process();
//Call the getProcessList() method
$res = $process->getProcessList('', $user['USR_UID']);
//Assert the result is not empty
$this->assertNotEmpty($res);
//Assert there's one result
$this->assertCount(1, $res);
//Assert that the process returned is the one that has ACTIVE status
$this->assertEquals($process1['PRO_UID'], $res[0]['PRO_UID']);
//Assert the processes that have not ACTIVE status are not in the result
$this->assertNotEquals($process2['PRO_UID'], $res[0]['PRO_UID']);
$this->assertNotEquals($process3['PRO_UID'], $res[0]['PRO_UID']);
}
}

View File

@@ -30,6 +30,7 @@ use ProcessMaker\ChangeLog\ChangeLog;
/*----------------------------------********---------------------------------*/ /*----------------------------------********---------------------------------*/
use ProcessMaker\Core\RoutingScreen; use ProcessMaker\Core\RoutingScreen;
use ProcessMaker\Core\System; use ProcessMaker\Core\System;
use ProcessMaker\Model\Process as ProcessEloquent;
use ProcessMaker\Services\Api\Project\Activity\Step as ActivityStep; use ProcessMaker\Services\Api\Project\Activity\Step as ActivityStep;
use ProcessMaker\Util\DateTime; use ProcessMaker\Util\DateTime;
use ProcessMaker\Validation\ExceptionRestApi; use ProcessMaker\Validation\ExceptionRestApi;
@@ -1237,109 +1238,29 @@ class Light
} }
/** /**
* @param $action * Return the list of processes
* @param $categoryUid *
* @param $userUid * @param string $action
* @param string $categoryUid
* @param string $userUid
*
* @see ProcessMaker\Services\Api\Light::getProcessList();
* *
* @return array * @return array
* @throws PropelException
*/ */
public function getProcessList($action, $categoryUid, $userUid) public function getProcessList($action, $categoryUid, $userUid)
{ {
//$action = isset( $_REQUEST['action'] ) ? $_REQUEST['action'] : null; $processes = [];
//$categoryUid = isset( $_REQUEST['CATEGORY_UID'] ) ? $_REQUEST['CATEGORY_UID'] : null; $processes[] = ['', G::LoadTranslation('ID_ALL_PROCESS')];
//$userUid = (isset( $_SESSION['USER_LOGGED'] ) && $_SESSION['USER_LOGGED'] != '') ? $_SESSION['USER_LOGGED'] : null;
// global $oAppCache; $process = new ProcessEloquent();
$oAppCache = new AppCacheView(); $processList = $process->getProcessList($categoryUid, $userUid);
$processes = array();
$processes[] = array('', G::LoadTranslation('ID_ALL_PROCESS'));
//get the list based in the action provided $values = (array_map(function ($x) {
switch ($action) { return array_values([$x['PRO_UID'], $x['PRO_TITLE']]);
case 'draft': }, $processList));
$cProcess = $oAppCache->getDraftListCriteria($userUid); //fast enough
break;
case 'sent':
$cProcess = $oAppCache->getSentListProcessCriteria($userUid); // fast enough
break;
case 'simple_search':
case 'search':
//in search action, the query to obtain all process is too slow, so we need to query directly to
//process and content tables, and for that reason we need the current language in AppCacheView.
$oConf = new Configurations(); $processes = array_merge($processes, $values);
$oConf->loadConfig($x, 'APP_CACHE_VIEW_ENGINE', '', '', '', '');
$appCacheViewEngine = $oConf->aConfig;
$lang = isset($appCacheViewEngine['LANG']) ? $appCacheViewEngine['LANG'] : 'en';
$cProcess = new Criteria('workflow');
$cProcess->clearSelectColumns();
$cProcess->addSelectColumn(ProcessPeer::PRO_UID);
$cProcess->addSelectColumn(ProcessPeer::PRO_TITLE);
if ($categoryUid) {
$cProcess->add(ProcessPeer::PRO_CATEGORY, $categoryUid);
}
$cProcess->add(ProcessPeer::PRO_STATUS, 'ACTIVE');
$cProcess->addAscendingOrderByColumn(ProcessPeer::PRO_TITLE);
$oDataset = ProcessPeer::doSelectRS($cProcess);
$oDataset->setFetchmode(ResultSet::FETCHMODE_ASSOC);
$oDataset->next();
while ($aRow = $oDataset->getRow()) {
$processes[] = array($aRow['PRO_UID'], $aRow['PRO_TITLE']);
$oDataset->next();
}
return print G::json_encode($processes);
break;
case 'unassigned':
$cProcess = $oAppCache->getUnassignedListCriteria($userUid);
break;
case 'paused':
$cProcess = $oAppCache->getPausedListCriteria($userUid);
break;
case 'to_revise':
$cProcess = $oAppCache->getToReviseListCriteria($userUid);
break;
case 'to_reassign':
$cProcess = $oAppCache->getToReassignListCriteria($userUid);
break;
case 'gral':
$cProcess = $oAppCache->getGeneralListCriteria();
break;
case 'todo':
default:
$cProcess = $oAppCache->getToDoListCriteria($userUid); //fast enough
break;
}
//get the processes for this user in this action
$cProcess->clearSelectColumns();
$cProcess->addSelectColumn(AppCacheViewPeer::PRO_UID);
$cProcess->addSelectColumn(AppCacheViewPeer::APP_PRO_TITLE);
$cProcess->setDistinct(AppCacheViewPeer::PRO_UID);
if ($categoryUid) {
require_once 'classes/model/Process.php';
$cProcess->addAlias('CP', 'PROCESS');
$cProcess->add('CP.PRO_CATEGORY', $categoryUid, Criteria::EQUAL);
$cProcess->addJoin(AppCacheViewPeer::PRO_UID, 'CP.PRO_UID', Criteria::LEFT_JOIN);
$cProcess->addAsColumn('CATEGORY_UID', 'CP.PRO_CATEGORY');
}
$cProcess->addAscendingOrderByColumn(AppCacheViewPeer::APP_PRO_TITLE);
$oDataset = AppCacheViewPeer::doSelectRS($cProcess, Propel::getDbConnection('workflow_ro'));
$oDataset->setFetchmode(ResultSet::FETCHMODE_ASSOC);
$oDataset->next();
while ($aRow = $oDataset->getRow()) {
$processes[] = array(
$aRow['PRO_UID'],
$aRow['APP_PRO_TITLE']
);
$oDataset->next();
}
return $processes; return $processes;
} }

View File

@@ -39,4 +39,28 @@ class Process extends Model
{ {
return $this->hasOne(ProcessCategory::class, 'PRO_CATEGORY', 'CATEGORY_UID'); return $this->hasOne(ProcessCategory::class, 'PRO_CATEGORY', 'CATEGORY_UID');
} }
/**
* Obtains the process list for an specific user and/or for the specific category
*
* @param string $categoryUid
* @param string $userUid
* @return array
*
* @see ProcessMaker\BusinessModel\Light::getProcessList()
*/
public function getProcessList($categoryUid, $userUid)
{
$selectedColumns = ['PRO_UID', 'PRO_TITLE'];
$query = Process::query()
->select($selectedColumns)
->where('PRO_STATUS', 'ACTIVE')
->where('PRO_CREATE_USER', $userUid);
if (!empty($categoryUid)) {
$query->where('PRO_CATEGORY', $categoryUid);
}
return ($query->get()->values()->toArray());
}
} }