diff --git a/gulliver/system/class.rbac.php b/gulliver/system/class.rbac.php index 7b5d2f02d..2b0b6a5fc 100644 --- a/gulliver/system/class.rbac.php +++ b/gulliver/system/class.rbac.php @@ -142,7 +142,9 @@ class RBAC 'getCategoryArray' => array('PM_ALLCASES'), 'getAllUsersArray' => array('PM_ALLCASES'), 'getStatusArray' => array('PM_ALLCASES'), - 'getProcessArray' => array('PM_ALLCASES') + 'getProcessArray' => array('PM_ALLCASES'), + 'getProcesses' => array('PM_ALLCASES'), + 'getUsers' => array('PM_ALLCASES') ) ); diff --git a/workflow/engine/controllers/home.php b/workflow/engine/controllers/home.php index a239dea25..d19c38d52 100644 --- a/workflow/engine/controllers/home.php +++ b/workflow/engine/controllers/home.php @@ -9,7 +9,7 @@ class Home extends Controller { - private $userID; + private $userUid; private $userName; private $userFullName; private $userRolName; @@ -23,6 +23,9 @@ class Home extends Controller private $lastSkin; private $usrId; + /** + * Check the if the user has permissions over functions + */ public function call ($name) { global $RBAC; @@ -41,13 +44,13 @@ class Home extends Controller $this->userUxBaseTemplate = (is_dir( PATH_CUSTOM_SKINS . 'uxs' )) ? PATH_CUSTOM_SKINS . 'simplified' . PATH_SEP . 'templates' : 'home'; if (isset( $_SESSION['USER_LOGGED'] ) && ! empty( $_SESSION['USER_LOGGED'] )) { - $this->userID = isset( $_SESSION['USER_LOGGED'] ) ? $_SESSION['USER_LOGGED'] : null; + $this->userUid = isset( $_SESSION['USER_LOGGED'] ) ? $_SESSION['USER_LOGGED'] : null; $this->userName = isset( $_SESSION['USR_USERNAME'] ) ? $_SESSION['USR_USERNAME'] : ''; $this->userFullName = isset( $_SESSION['USR_FULLNAME'] ) ? $_SESSION['USR_FULLNAME'] : ''; $this->userRolName = isset( $_SESSION['USR_ROLENAME'] ) ? $_SESSION['USR_ROLENAME'] : ''; $users = new Users(); - $users = $users->load($this->userID); + $users = $users->load($this->userUid); $this->usrId = $users["USR_ID"]; } } @@ -64,7 +67,10 @@ class Home extends Controller $skin = $this->clientBrowser['name'] == 'msie' ? $this->lastSkin : 'simplified'; if (! is_array( $data )) { - $data = array ('u' => '','p' => '','m' => '' + $data = array ( + 'u' => '', + 'p' => '', + 'm' => '' ); } @@ -163,7 +169,7 @@ class Home extends Controller $this->setView( $this->userUxBaseTemplate . PATH_SEP . 'index' ); - $this->setVar( 'usrUid', $this->userID ); + $this->setVar( 'usrUid', $this->userUid ); $this->setVar( 'userName', $this->userName ); $this->setVar( 'processList', $processesList ); $this->setVar( 'canStartCase', $case->canStartCase( $_SESSION['USER_LOGGED'] ) ); @@ -204,13 +210,13 @@ class Home extends Controller } if ($solrEnabled) { - $cases = $ApplicationSolrIndex->getAppGridData($this->userID, 0, 1, 'todo'); + $cases = $ApplicationSolrIndex->getAppGridData($this->userUid, 0, 1, 'todo'); } else { G::LoadClass( 'applications' ); $apps = new Applications(); - $cases = $apps->getAll( $this->userID, 0, 1, 'todo' ); + $cases = $apps->getAll( $this->userUid, 0, 1, 'todo' ); } if (! isset( $cases['data'][0] )) { @@ -234,7 +240,7 @@ class Home extends Controller $this->setView( $this->userUxBaseTemplate . PATH_SEP . 'indexSingle' ); - $this->setVar( 'usrUid', $this->userID ); + $this->setVar( 'usrUid', $this->userUid ); $this->setVar( 'userName', $this->userName ); $this->setVar( 'steps', $steps ); $this->setVar( 'default_url', "cases/cases_Open?APP_UID={$lastApp['APP_UID']}&DEL_INDEX={$lastApp['DEL_INDEX']}&action=todo" ); @@ -325,9 +331,7 @@ class Home extends Controller $arraySearch = array($process, $status, $search, $category, $user, $dateFrom, $dateTo ); // settings vars and rendering - $processes = array(); - $processes = $this->getProcessArray($httpData->t, $this->userID ); - $this->setVar( 'statusValues', $this->getStatusArray( $httpData->t, $this->userID ) ); + $this->setVar( 'statusValues', $this->getStatusArray( $httpData->t, $this->userUid) ); $this->setVar( 'categoryValues', $this->getCategoryArray() ); $this->setVar( 'allUsersValues', $this->getAllUsersArray( 'search' ) ); $this->setVar( 'categoryTitle', G::LoadTranslation("ID_CATEGORY") ); @@ -404,7 +408,7 @@ class Home extends Controller } break; default: - //$user = $this->userID; + break; } @@ -453,6 +457,7 @@ class Home extends Controller ); } else { $dataList['userId'] = $user; + $dataList['userUid'] = $this->userUid; $dataList['start'] = $start; $dataList['limit'] = $limit; $dataList['filter'] = $filter; @@ -512,7 +517,7 @@ class Home extends Controller if(empty($cases) && $type == 'search') { $case = new \ProcessMaker\BusinessModel\Cases(); - $cases = $case->getList($dataList); + $cases = $case->getCasesSearch($dataList); foreach ($cases['data'] as &$value) { $value = array_change_key_case($value, CASE_UPPER); } @@ -600,7 +605,7 @@ class Home extends Controller G::LoadClass("configuration"); $conf = new Configurations(); $confEnvSetting = $conf->getFormats(); - $status = array(); + $users = array(); $users[] = array("CURRENT_USER", G::LoadTranslation("ID_CURRENT_USER")); $users[] = array("ALL", G::LoadTranslation("ID_ALL_USERS")); @@ -644,10 +649,9 @@ class Home extends Controller function getCategoryArray () { - global $oAppCache; require_once 'classes/model/ProcessCategory.php'; - $category[] = array ("",G::LoadTranslation( "ID_ALL_CATEGORIES" ) - ); + $category = array(); + $category[] = array ("",G::LoadTranslation( "ID_ALL_CATEGORIES" )); $criteria = new Criteria( 'workflow' ); $criteria->addSelectColumn( ProcessCategoryPeer::CATEGORY_UID ); @@ -666,11 +670,9 @@ class Home extends Controller function getAllUsersArray ($action) { global $oAppCache; - $status = array (); - $users[] = array ("CURRENT_USER",G::LoadTranslation( "ID_CURRENT_USER" ) - ); - $users[] = array ("",G::LoadTranslation( "ID_ALL_USERS" ) - ); + $users = array (); + $users[] = array ("CURRENT_USER",G::LoadTranslation( "ID_CURRENT_USER" )); + $users[] = array ("",G::LoadTranslation( "ID_ALL_USERS" )); if ($action == 'to_reassign') { //now get users, just for the Search action @@ -718,8 +720,6 @@ class Home extends Controller */ private function getProcessArray($action, $userUid, $search=null) { - global $oAppCache; - $processes = array(); $processes[] = array("", G::LoadTranslation("ID_ALL_PROCESS")); @@ -732,9 +732,7 @@ class Home extends Controller $cProcess->add(ProcessPeer::PRO_TITLE, "%$search%", Criteria::LIKE); } $oDataset = ProcessPeer::doSelectRS($cProcess); - $oDataset->setFetchmode(ResultSet::FETCHMODE_ASSOC); - $oDataset->next(); while ($aRow = $oDataset->getRow()) { $processes[] = array($aRow["PRO_ID"], $aRow["PRO_TITLE"]); diff --git a/workflow/engine/src/ProcessMaker/BusinessModel/Cases.php b/workflow/engine/src/ProcessMaker/BusinessModel/Cases.php index 39cf05952..23aa8007a 100644 --- a/workflow/engine/src/ProcessMaker/BusinessModel/Cases.php +++ b/workflow/engine/src/ProcessMaker/BusinessModel/Cases.php @@ -214,14 +214,17 @@ class Cases } /** - * Get list for Cases + * Get list of cases from: todo, draft, unassigned + * Get list of cases for the following REST endpoints: + * /light/todo + * /light/draft + * /light/participated + * /light/paused + * /light/unassigned * * @access public * @param array $dataList, Data for list - * @return array - * - * @author Brayan Pereyra (Cochalo) - * @copyright Colosa - Bolivia + * @return array $response */ public function getList($dataList = array()) { @@ -230,8 +233,8 @@ class Cases $dataList["userId"] = null; } - $solrEnabled = false; - $userUid = $dataList["userId"]; + //We need to use the USR_UID for the cases in the list + $userUid = isset($dataList["userUid"]) ? $dataList["userUid"] : $dataList["userId"]; $callback = isset( $dataList["callback"] ) ? $dataList["callback"] : "stcCallback1001"; $dir = isset( $dataList["dir"] ) ? $dataList["dir"] : "DESC"; $sort = isset( $dataList["sort"] ) ? $dataList["sort"] : "APPLICATION.APP_NUMBER"; @@ -244,7 +247,6 @@ class Cases $process = isset( $dataList["process"] ) ? $dataList["process"] : ""; $category = isset( $dataList["category"] ) ? $dataList["category"] : ""; $status = isset( $dataList["status"] ) ? strtoupper( $dataList["status"] ) : ""; - $user = isset( $dataList["user"] ) ? $dataList["user"] : ""; $search = isset( $dataList["search"] ) ? $dataList["search"] : ""; $action = isset( $dataList["action"] ) ? $dataList["action"] : "todo"; $paged = isset( $dataList["paged"] ) ? $dataList["paged"] : true; @@ -253,12 +255,84 @@ class Cases $dateTo = (!empty( $dataList["dateTo"] )) ? substr( $dataList["dateTo"], 0, 10 ) : ""; $newerThan = (!empty($dataList['newerThan']))? $dataList['newerThan'] : ''; $oldestThan = (!empty($dataList['oldestthan']))? $dataList['oldestthan'] : ''; - $first = isset( $dataList["first"] ) ? true :false; + + $apps = new \Applications(); + $response = $apps->getAll( + $userUid, + $start, + $limit, + $action, + $filter, + $search, + $process, + $status, + $type, + $dateFrom, + $dateTo, + $callback, + $dir, + (strpos($sort, ".") !== false)? $sort : "APP_CACHE_VIEW." . $sort, + $category, + true, + $paged, + $newerThan, + $oldestThan + ); + if (!empty($response['data'])) { + foreach ($response['data'] as &$value) { + $value = array_change_key_case($value, CASE_LOWER); + } + } + + if ($paged) { + $response['total'] = $response['totalCount']; + $response['start'] = $start+1; + $response['limit'] = $limit; + $response['sort'] = G::toLower($sort); + $response['dir'] = G::toLower($dir); + $response['cat_uid'] = $category; + $response['pro_uid'] = $process; + $response['search'] = $search; + } else { + $response = $response['data']; + } + return $response; + } + /** + * Search cases and get list of cases + * + * @access public + * @param array $dataList, Data for list + * @return array $response + */ + public function getCasesSearch($dataList = array()) + { + Validator::isArray($dataList, '$dataList'); + if (!isset($dataList["userId"])) { + $dataList["userId"] = null; + } + + //We need to user the USR_ID for performance + $userId = $dataList["userId"]; + $dir = isset( $dataList["dir"] ) ? $dataList["dir"] : "DESC"; + $sort = isset( $dataList["sort"] ) ? $dataList["sort"] : "APPLICATION.APP_NUMBER"; + if ($sort === 'APP_CACHE_VIEW.APP_NUMBER') { + $sort = "APPLICATION.APP_NUMBER"; + } + $start = isset( $dataList["start"] ) ? $dataList["start"] : "0"; + $limit = isset( $dataList["limit"] ) ? $dataList["limit"] : ""; + $process = isset( $dataList["process"] ) ? $dataList["process"] : ""; + $category = isset( $dataList["category"] ) ? $dataList["category"] : ""; + $status = isset( $dataList["status"] ) ? strtoupper( $dataList["status"] ) : ""; + $user = isset( $dataList["user"] ) ? $dataList["user"] : ""; + $search = isset( $dataList["search"] ) ? $dataList["search"] : ""; + $dateFrom = (!empty( $dataList["dateFrom"] )) ? substr( $dataList["dateFrom"], 0, 10 ) : ""; + $dateTo = (!empty( $dataList["dateTo"] )) ? substr( $dataList["dateTo"], 0, 10 ) : ""; $filterStatus = isset( $dataList["filterStatus"] ) ? strtoupper( $dataList["filterStatus"] ) : ""; $apps = new \Applications(); $response = $apps->searchAll( - $userUid, + $userId, $start, $limit, $search, @@ -272,19 +346,18 @@ class Cases ); $response['total'] = 0; - $response['start'] = $start + 1; + $response['start'] = $start+1; $response['limit'] = $limit; $response['sort'] = G::toLower($sort); $response['dir'] = G::toLower($dir); $response['cat_uid'] = $category; $response['pro_uid'] = $process; $response['search'] = $search; - if ($action == 'search') { - $response['app_status'] = G::toLower($status); - $response['usr_uid'] = $user; - $response['date_from'] = $dateFrom; - $response['date_to'] = $dateTo; - } + $response['app_status'] = G::toLower($status); + $response['usr_uid'] = $user; + $response['date_from'] = $dateFrom; + $response['date_to'] = $dateTo; + return $response; }