From 5065e669e14c72c928c33d665252718c4f366491 Mon Sep 17 00:00:00 2001 From: Roly Rudy Gutierrez Pinto Date: Thu, 18 May 2017 10:58:13 -0400 Subject: [PATCH 1/6] HOR-2887 --- workflow/engine/controllers/home.php | 11 +++++------ .../engine/src/ProcessMaker/BusinessModel/Cases.php | 4 +--- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/workflow/engine/controllers/home.php b/workflow/engine/controllers/home.php index 54fb21631..3640d993a 100644 --- a/workflow/engine/controllers/home.php +++ b/workflow/engine/controllers/home.php @@ -279,6 +279,7 @@ class Home extends Controller // settings html template $this->setView( $this->userUxBaseTemplate . PATH_SEP . 'appListSearch' ); + // get data $process = (isset($httpData->process)) ? $httpData->process : null; $status = (isset($httpData->status)) ? $httpData->status : null; $search = (isset($httpData->search)) ? $httpData->search : null; @@ -286,16 +287,14 @@ class Home extends Controller $user = (isset($httpData->user)) ? $httpData->user : null; $dateFrom = (isset($httpData->dateFrom)) ? $httpData->dateFrom : null; $dateTo = (isset($httpData->dateTo)) ? $httpData->dateTo : null; + $processTitle = ""; if (!empty($process)) { $processTitle = Process::loadById($process)->getProTitle(); - } else { - $processTitle = ''; } - if (!empty($user)) { + $userName = ""; + if (!empty($user) && $user !== "ALL" && $user !== "CURRENT_USER") { $userObject = Users::loadById($user); - $userName = $userObject->getUsrLastname()." ".$userObject->getUsrFirstname(); - } else { - $userName = ''; + $userName = $userObject->getUsrLastname() . " " . $userObject->getUsrFirstname(); } $cases = $this->getAppsData( $httpData->t, null, null, $user, null, $search, $process, $status, $dateFrom, $dateTo, null, null, 'APP_CACHE_VIEW.APP_NUMBER', $category); diff --git a/workflow/engine/src/ProcessMaker/BusinessModel/Cases.php b/workflow/engine/src/ProcessMaker/BusinessModel/Cases.php index fd651d249..ba1cbc5e8 100644 --- a/workflow/engine/src/ProcessMaker/BusinessModel/Cases.php +++ b/workflow/engine/src/ProcessMaker/BusinessModel/Cases.php @@ -227,9 +227,7 @@ class Cases { Validator::isArray($dataList, '$dataList'); if (!isset($dataList["userId"])) { - throw (new \Exception(\G::LoadTranslation("ID_USER_NOT_EXIST", array('userId','')))); - } else { - Validator::usrUid($dataList["userId"], "userId"); + $dataList["userId"] = null; } $solrEnabled = false; From b752c4e5b806edf25316202c652e4e38ab0379af Mon Sep 17 00:00:00 2001 From: qronald Date: Thu, 18 May 2017 11:57:56 -0400 Subject: [PATCH 2/6] HOR-3056 --- .../engine/src/ProcessMaker/Util/System.php | 80 ++++++++++++++++++- 1 file changed, 79 insertions(+), 1 deletion(-) diff --git a/workflow/engine/src/ProcessMaker/Util/System.php b/workflow/engine/src/ProcessMaker/Util/System.php index 25ba3c2aa..087d83100 100644 --- a/workflow/engine/src/ProcessMaker/Util/System.php +++ b/workflow/engine/src/ProcessMaker/Util/System.php @@ -1,12 +1,19 @@ add(PATH_TRUNK . 'vendor/bshaffer/oauth2-server-php/src/', "OAuth2"); + + $request = array( + 'grant_type' => 'authorization_code', + 'code' => $authCode + ); + $server = array( + 'REQUEST_METHOD' => 'POST' + ); + $headers = array( + "PHP_AUTH_USER" => $client['CLIENT_ID'], + "PHP_AUTH_PW" => $client['CLIENT_SECRET'], + "Content-Type" => "multipart/form-data;", + "Authorization" => "Basic " . base64_encode($client['CLIENT_ID'] . ":" . $client['CLIENT_SECRET']) + ); + + $request = new Request(array(), $request, array(), array(), array(), $server, null, $headers); + $oauthServer = new Server(); + $response = $oauthServer->postToken($request, true); + $clientToken = $response->getParameters(); + $clientToken["client_id"] = $client['CLIENT_ID']; + $clientToken["client_secret"] = $client['CLIENT_SECRET']; + return $clientToken; + } + + protected function getClientCredentials() + { + $oauthQuery = new PmPdo(self::getDsn()); + return $oauthQuery->getClientDetails(self::CLIENT_ID); + } + + protected function getDsn() + { + list($host, $port) = strpos(DB_HOST, ':') !== false ? explode(':', DB_HOST) : array(DB_HOST, ''); + $port = empty($port) ? '' : ";port=$port"; + $dsn = DB_ADAPTER . ':host=' . $host . ';dbname=' . DB_NAME . $port; + + return array('dsn' => $dsn, 'username' => DB_USER, 'password' => DB_PASS); + } + + protected function getAuthorizationCode($client) + { + Server::setDatabaseSource(self::getDsn()); + Server::setPmClientId($client['CLIENT_ID']); + + $oauthServer = new Server(); + + $userId = $_SESSION['USER_LOGGED']; + $authorize = true; + $_GET = array_merge($_GET, array( + 'response_type' => 'code', + 'client_id' => $client['CLIENT_ID'], + 'scope' => implode(' ', $oauthServer->getScope()) + )); + + $response = $oauthServer->postAuthorize($authorize, $userId, true); + $code = substr($response->getHttpHeader('Location'), strpos($response->getHttpHeader('Location'), 'code=') + 5, 40); + return $code; + } +} From 8cc1b16f286a556605edaad049290412aa5aec65 Mon Sep 17 00:00:00 2001 From: qronald Date: Mon, 22 May 2017 09:52:17 -0400 Subject: [PATCH 3/6] change name function and add comments --- .../engine/src/ProcessMaker/Util/System.php | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/workflow/engine/src/ProcessMaker/Util/System.php b/workflow/engine/src/ProcessMaker/Util/System.php index 087d83100..754ab1eb7 100644 --- a/workflow/engine/src/ProcessMaker/Util/System.php +++ b/workflow/engine/src/ProcessMaker/Util/System.php @@ -32,11 +32,11 @@ class System * * @return array */ - public static function token() + public static function tokenUserLogged() { $client = self::getClientCredentials(); - $authCode = self::getAuthorizationCode($client); + $authCode = self::getAuthorizationCodeUserLogged($client); $loader = \Maveriks\Util\ClassLoader::getInstance(); $loader->add(PATH_TRUNK . 'vendor/bshaffer/oauth2-server-php/src/', "OAuth2"); @@ -64,12 +64,20 @@ class System return $clientToken; } + /** + * Get client credentials + * @return array + */ protected function getClientCredentials() { $oauthQuery = new PmPdo(self::getDsn()); return $oauthQuery->getClientDetails(self::CLIENT_ID); } + /** + * Get DNS of workspace + * @return array + */ protected function getDsn() { list($host, $port) = strpos(DB_HOST, ':') !== false ? explode(':', DB_HOST) : array(DB_HOST, ''); @@ -79,7 +87,12 @@ class System return array('dsn' => $dsn, 'username' => DB_USER, 'password' => DB_PASS); } - protected function getAuthorizationCode($client) + /** + * Get authorization code for user logged in session + * @param $client + * @return bool|string + */ + protected function getAuthorizationCodeUserLogged($client) { Server::setDatabaseSource(self::getDsn()); Server::setPmClientId($client['CLIENT_ID']); From c35c6db26064a299c5bd47356592a326855f570f Mon Sep 17 00:00:00 2001 From: Roly Rudy Gutierrez Pinto Date: Wed, 24 May 2017 08:51:17 -0400 Subject: [PATCH 4/6] HOR-2887 problem solving in the user experience lists --- workflow/engine/controllers/home.php | 38 +++++++++++-------- workflow/engine/templates/home/appList.html | 2 +- .../engine/templates/home/appListSearch.html | 2 +- 3 files changed, 24 insertions(+), 18 deletions(-) diff --git a/workflow/engine/controllers/home.php b/workflow/engine/controllers/home.php index 3640d993a..6715f720a 100644 --- a/workflow/engine/controllers/home.php +++ b/workflow/engine/controllers/home.php @@ -22,6 +22,7 @@ class Home extends Controller private $clientBrowser; private $lastSkin; + private $usrId; public function __construct () { @@ -39,6 +40,10 @@ class Home extends Controller $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); + $this->usrId = $users["USR_ID"]; } } @@ -261,7 +266,6 @@ class Home extends Controller // settings vars and rendering $this->setVar( 'cases', $cases['data'] ); - $this->setVar( 'cases_count', $cases['totalCount'] ); $this->setVar( 'title', $title ); $this->setVar( 'noPerms', G::LoadTranslation( 'ID_CASES_NOTES_NO_PERMISSIONS' )); $this->setVar( 'appListStart', $this->appListLimit ); @@ -296,7 +300,7 @@ class Home extends Controller $userObject = Users::loadById($user); $userName = $userObject->getUsrLastname() . " " . $userObject->getUsrFirstname(); } - + $cases = $this->getAppsData( $httpData->t, null, null, $user, null, $search, $process, $status, $dateFrom, $dateTo, null, null, 'APP_CACHE_VIEW.APP_NUMBER', $category); $arraySearch = array($process, $status, $search, $category, $user, $dateFrom, $dateTo ); @@ -317,7 +321,6 @@ class Home extends Controller $this->setVar( 'arraySearch', $arraySearch ); $this->setVar( 'cases', $cases['data'] ); - $this->setVar( 'cases_count', $cases['totalCount'] ); $this->setVar( 'title', $title ); $this->setVar( 'noPerms', G::LoadTranslation( 'ID_CASES_NOTES_NO_PERMISSIONS' )); $this->setVar( 'appListStart', $this->appListLimit ); @@ -368,13 +371,13 @@ class Home extends Controller $notesLimit = 4; switch ($user) { case 'CURRENT_USER': - $user = $this->userID; + $user = $this->usrId; break; case 'ALL': $user = null; break; case null: - $user = $this->userID; + $user = $this->usrId; break; default: //$user = $this->userID; @@ -449,6 +452,8 @@ class Home extends Controller case 'draft': case 'todo': $listName = 'inbox'; + $userObject = Users::loadById($dataList['userId']); + $dataList['userId'] = $userObject->getUsrUid(); $cases = $list->getList($listName, $dataList); break; case 'unassigned': @@ -558,31 +563,32 @@ class Home extends Controller $this->render(); } - function getUserArray ($action, $userUid, $search = null) + function getUserArray($action, $userUid, $search = null) { global $oAppCache; - $status = array (); - $users[] = array ("CURRENT_USER",G::LoadTranslation( "ID_CURRENT_USER" )); - $users[] = array ("ALL",G::LoadTranslation( "ID_ALL_USERS" )); + $status = array(); + $users[] = array("CURRENT_USER", G::LoadTranslation("ID_CURRENT_USER")); + $users[] = array("ALL", G::LoadTranslation("ID_ALL_USERS")); //now get users, just for the Search action switch ($action) { case 'search_simple': case 'search': - $cUsers = new Criteria( 'workflow' ); + $cUsers = new Criteria('workflow'); $cUsers->clearSelectColumns(); - $cUsers->addSelectColumn( UsersPeer::USR_UID ); - $cUsers->addSelectColumn( UsersPeer::USR_FIRSTNAME ); - $cUsers->addSelectColumn( UsersPeer::USR_LASTNAME ); + $cUsers->addSelectColumn(UsersPeer::USR_UID); + $cUsers->addSelectColumn(UsersPeer::USR_FIRSTNAME); + $cUsers->addSelectColumn(UsersPeer::USR_LASTNAME); + $cUsers->addSelectColumn(UsersPeer::USR_ID); if (!empty($search)) { $cUsers->addOr(UsersPeer::USR_FIRSTNAME, "%$search%", Criteria::LIKE); $cUsers->addOr(UsersPeer::USR_LASTNAME, "%$search%", Criteria::LIKE); } - $oDataset = UsersPeer::doSelectRS( $cUsers ); - $oDataset->setFetchmode( ResultSet::FETCHMODE_ASSOC ); + $oDataset = UsersPeer::doSelectRS($cUsers); + $oDataset->setFetchmode(ResultSet::FETCHMODE_ASSOC); $oDataset->next(); while ($aRow = $oDataset->getRow()) { - $users[] = array ($aRow['USR_UID'], htmlentities($aRow['USR_LASTNAME'] . ' ' . $aRow['USR_FIRSTNAME'], ENT_QUOTES, "UTF-8")); + $users[] = array($aRow['USR_ID'], htmlentities($aRow['USR_LASTNAME'] . ' ' . $aRow['USR_FIRSTNAME'], ENT_QUOTES, "UTF-8")); $oDataset->next(); } break; diff --git a/workflow/engine/templates/home/appList.html b/workflow/engine/templates/home/appList.html index aa9807248..f5552928b 100644 --- a/workflow/engine/templates/home/appList.html +++ b/workflow/engine/templates/home/appList.html @@ -173,7 +173,7 @@
-

{$title} ({$cases_count})

+

{$title}

    {include file='home/applications.html'}
diff --git a/workflow/engine/templates/home/appListSearch.html b/workflow/engine/templates/home/appListSearch.html index 2f5dd5fcd..ecb61fb7f 100644 --- a/workflow/engine/templates/home/appListSearch.html +++ b/workflow/engine/templates/home/appListSearch.html @@ -356,7 +356,7 @@
-

{$title} ({$cases_count})

+

{$title}

    {include file='home/applications.html'}
From c017e1fcb18b33f07221804c0b4707f2dad981d2 Mon Sep 17 00:00:00 2001 From: Roly Rudy Gutierrez Pinto Date: Wed, 24 May 2017 13:27:21 -0400 Subject: [PATCH 5/6] HOR-2887 add message --- workflow/engine/controllers/home.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/workflow/engine/controllers/home.php b/workflow/engine/controllers/home.php index 6715f720a..be5a4be9f 100644 --- a/workflow/engine/controllers/home.php +++ b/workflow/engine/controllers/home.php @@ -452,6 +452,8 @@ class Home extends Controller case 'draft': case 'todo': $listName = 'inbox'; + //The change is made because the method 'getList()' does not + //support 'USR_UID', this method uses the numeric field 'USR_ID'. $userObject = Users::loadById($dataList['userId']); $dataList['userId'] = $userObject->getUsrUid(); $cases = $list->getList($listName, $dataList); From 47e7f8bfd71e9c56f676b9616e7fdb020dd4d578 Mon Sep 17 00:00:00 2001 From: Roly Rudy Gutierrez Pinto Date: Thu, 25 May 2017 11:51:38 -0400 Subject: [PATCH 6/6] HOR-2887 problem resolved in unassigned list --- workflow/engine/controllers/home.php | 28 +++++++++------------------- 1 file changed, 9 insertions(+), 19 deletions(-) diff --git a/workflow/engine/controllers/home.php b/workflow/engine/controllers/home.php index be5a4be9f..c298b5a59 100644 --- a/workflow/engine/controllers/home.php +++ b/workflow/engine/controllers/home.php @@ -446,25 +446,15 @@ class Home extends Controller if (true) { //In enterprise version this block of code should always be executed //In community version this block of code is deleted and is executed the other - $list = new \ProcessMaker\BusinessModel\Lists(); - $listName = 'inbox'; - switch ($type) { - case 'draft': - case 'todo': - $listName = 'inbox'; - //The change is made because the method 'getList()' does not - //support 'USR_UID', this method uses the numeric field 'USR_ID'. - $userObject = Users::loadById($dataList['userId']); - $dataList['userId'] = $userObject->getUsrUid(); - $cases = $list->getList($listName, $dataList); - break; - case 'unassigned': - $case = new \ProcessMaker\BusinessModel\Cases(); - $cases = $case->getList($dataList); - foreach ($cases['data'] as &$value) { - $value = array_change_key_case($value, CASE_UPPER); - } - break; + $swType = $type === "todo" || $type === "draft"; + if ($swType || $type === "unassigned") { + //The change is made because the method 'getList()' does not + //support 'USR_UID', this method uses the numeric field 'USR_ID'. + $userObject = Users::loadById($dataList['userId']); + $dataList['userId'] = $userObject->getUsrUid(); + $listType = $swType ? "inbox" : $type; + $list = new \ProcessMaker\BusinessModel\Lists(); + $cases = $list->getList($listType, $dataList); } } else { /*----------------------------------********---------------------------------*/