Merged in victorsl/processmaker (pull request #179)
ProcessMaker-MA "Group (endpoints & behat) and Web Entry (behat)"
This commit is contained in:
@@ -3,7 +3,9 @@ Feature: Group
|
||||
Background:
|
||||
Given that I have a valid access_token
|
||||
|
||||
#GET /api/1.0/{workspace}/groups?filter=abc&start=0&limit=25
|
||||
#GROUP
|
||||
|
||||
#GET /api/1.0/{workspace}/groups?filter={filter}&start={start}&limit={limit}
|
||||
# Get list Groups
|
||||
Scenario: Get list Groups
|
||||
And I request "groups?filter=for basic behat"
|
||||
@@ -56,7 +58,7 @@ Feature: Group
|
||||
| 0 | INACTIVE |
|
||||
| 1 | INACTIVE |
|
||||
|
||||
#GET /api/1.0/{workspace}/groups?filter=abc&start=0&limit=25
|
||||
#GET /api/1.0/{workspace}/groups?filter={filter}&start={start}&limit={limit}
|
||||
# Get list Groups
|
||||
Scenario Outline: Get list Groups
|
||||
And I request "groups?filter=for basic behat"
|
||||
@@ -108,7 +110,117 @@ Feature: Group
|
||||
| 0 |
|
||||
| 1 |
|
||||
|
||||
#GET /api/1.0/{workspace}/groups?filter=abc&start=0&limit=25
|
||||
#GET /api/1.0/{workspace}/groups?filter={filter}&start={start}&limit={limit}
|
||||
# Get list Groups
|
||||
Scenario: Get list Groups
|
||||
And I request "groups?filter=for basic behat"
|
||||
And the content type is "application/json"
|
||||
Then the response status code should be 200
|
||||
And the response charset is "UTF-8"
|
||||
And the type is "array"
|
||||
And the json data is an empty array
|
||||
|
||||
#GROUP - USER
|
||||
|
||||
#POST /api/1.0/{workspace}/group
|
||||
# Create new Group
|
||||
Scenario Outline: Create new Group
|
||||
Given POST this data:
|
||||
"""
|
||||
{
|
||||
"grp_title": "<grp_title>",
|
||||
"grp_status": "<grp_status>"
|
||||
}
|
||||
"""
|
||||
And I request "group"
|
||||
And the content type is "application/json"
|
||||
Then the response status code should be 201
|
||||
And the response charset is "UTF-8"
|
||||
And the type is "object"
|
||||
And store "grp_uid" in session array as variable "grp_uid<i>"
|
||||
|
||||
Examples:
|
||||
| i | grp_title | grp_status |
|
||||
| 0 | Demo Group1 for basic behat | ACTIVE |
|
||||
|
||||
#POST /api/1.0/{workspace}/group/{grp_uid}/user
|
||||
# Assign User to Group
|
||||
Scenario Outline: Assign User to Group
|
||||
Given POST this data:
|
||||
"""
|
||||
{
|
||||
"usr_uid": "<usr_uid>"
|
||||
}
|
||||
"""
|
||||
And I request "group/grp_uid<i>/user" with the key "grp_uid<i>" stored in session array
|
||||
And the content type is "application/json"
|
||||
Then the response status code should be 201
|
||||
And the response charset is "UTF-8"
|
||||
And the type is "object"
|
||||
|
||||
Examples:
|
||||
| i | usr_uid |
|
||||
| 0 | 00000000000000000000000000000001 |
|
||||
|
||||
#GET /api/1.0/{workspace}/group/{grp_uid}/users?filter={filter}&start={start}&limit={limit}
|
||||
# List assigned Users to Group
|
||||
Scenario Outline: List assigned Users to Group
|
||||
And I request "group/grp_uid<i>/users" with the key "grp_uid<i>" stored in session array
|
||||
And the content type is "application/json"
|
||||
Then the response status code should be 200
|
||||
And the response charset is "UTF-8"
|
||||
And the type is "array"
|
||||
And the "usr_uid" property in row <i> equals "<usr_uid>"
|
||||
And the "usr_username" property in row <i> equals "<usr_username>"
|
||||
And the "usr_status" property in row <i> equals "<usr_status>"
|
||||
|
||||
Examples:
|
||||
| i | usr_uid | usr_username | usr_status |
|
||||
| 0 | 00000000000000000000000000000001 | admin | ACTIVE |
|
||||
|
||||
#GET /api/1.0/{workspace}/group/{grp_uid}/available-users?filter={filter}&start={start}&limit={limit}
|
||||
# List available Users to assign to Group
|
||||
Scenario Outline: List available Users to assign to Group
|
||||
And I request "group/grp_uid<i>/available-users?filter=none" with the key "grp_uid<i>" stored in session array
|
||||
And the content type is "application/json"
|
||||
Then the response status code should be 200
|
||||
And the response charset is "UTF-8"
|
||||
And the type is "array"
|
||||
And the json data is an empty array
|
||||
|
||||
Examples:
|
||||
| i |
|
||||
| 0 |
|
||||
|
||||
#DELETE /api/1.0/{workspace}/group/{grp_uid}/user/{usr_uid}
|
||||
# Unassign User of the Group
|
||||
Scenario Outline: Unassign User of the Group
|
||||
Given that I want to delete a resource with the key "obj_uid" stored in session array
|
||||
And I request "group/grp_uid<i>/user/<usr_uid>" with the key "grp_uid<i>" stored in session array
|
||||
And the content type is "application/json"
|
||||
Then the response status code should be 200
|
||||
And the response charset is "UTF-8"
|
||||
And the type is "object"
|
||||
|
||||
Examples:
|
||||
| i | usr_uid |
|
||||
| 0 | 00000000000000000000000000000001 |
|
||||
|
||||
#DELETE /api/1.0/{workspace}/group/{grp_uid}
|
||||
# Delete Group
|
||||
Scenario Outline: Delete Group
|
||||
Given that I want to delete a resource with the key "grp_uid" stored in session array as variable "grp_uid<i>"
|
||||
And I request "group"
|
||||
And the content type is "application/json"
|
||||
Then the response status code should be 200
|
||||
And the response charset is "UTF-8"
|
||||
And the type is "object"
|
||||
|
||||
Examples:
|
||||
| i |
|
||||
| 0 |
|
||||
|
||||
#GET /api/1.0/{workspace}/groups?filter={filter}&start={start}&limit={limit}
|
||||
# Get list Groups
|
||||
Scenario: Get list Groups
|
||||
And I request "groups?filter=for basic behat"
|
||||
|
||||
@@ -146,6 +146,33 @@ Feature: Web Entry
|
||||
| 44199549652e66ba533bb06088252754 | Task 1 | 60308801852e66b7181ae21045247174 |DynaForm Demo1 |
|
||||
| 56118778152e66babcc2103002009439 | Task 2 | 99869771852e66b7dc4b858088901665 |DynaForm Demo2 |
|
||||
|
||||
#POST /api/1.0/{workspace}/project/{prj_uid}/web-entry
|
||||
# Create a new Web Entry for a project
|
||||
# Create a new Web Entry using the method: PHP pages with Web Services
|
||||
Scenario Outline: Create a new Web Entry using the method: PHP pages with Web Services
|
||||
Given POST this data:
|
||||
"""
|
||||
{
|
||||
"tas_uid": "<tas_uid>",
|
||||
"dyn_uid": "<dyn_uid>",
|
||||
"method": "WS",
|
||||
"input_document_access": 1,
|
||||
"usr_username": "admin",
|
||||
"usr_password": "admin"
|
||||
}
|
||||
"""
|
||||
And I request "project/28733629952e66a362c4f63066393844/web-entry"
|
||||
And the content type is "application/json"
|
||||
Then the response status code should be <status_code>
|
||||
And the response charset is "UTF-8"
|
||||
And the type is "object"
|
||||
And the response status message should have the following text "<status_message>"
|
||||
|
||||
Examples:
|
||||
| tas_uid | tas_title | dyn_uid | dyn_title | status_code | status_message |
|
||||
| 44199549652e66ba533bb06088252754 | Task 1 | 60308801852e66b7181ae21045247174 |DynaForm Demo1 | 400 | exist |
|
||||
| 56118778152e66babcc2103002009439 | Task 2 | 99869771852e66b7dc4b858088901665 |DynaForm Demo2 | 400 | exist |
|
||||
|
||||
#DELETE /api/1.0/{workspace}/project/{prj_uid}/web-entry/{tas_uid}/{dyn_uid}
|
||||
# Delete a Web Entry of a Project
|
||||
Scenario Outline: Delete a Web Entry of a Project
|
||||
|
||||
@@ -339,7 +339,7 @@ class RestContext extends BehatContext
|
||||
$this->_headers['Authorization'] = 'Bearer ' . $this->access_token;
|
||||
}
|
||||
|
||||
|
||||
|
||||
if($urlType=="absolute"){
|
||||
$this->_requestUrl = $pageUrl;
|
||||
}else{
|
||||
@@ -361,7 +361,7 @@ class RestContext extends BehatContext
|
||||
$url .= $this->_restGetQueryStringSuffix;
|
||||
}
|
||||
$this->_request = $this->_client
|
||||
->get($url, $this->_headers);
|
||||
->get($url, $this->_headers);
|
||||
$this->_response = $this->_request->send();
|
||||
break;
|
||||
case 'POST':
|
||||
@@ -1237,7 +1237,7 @@ class RestContext extends BehatContext
|
||||
$varValue = $sessionData->$sessionVarName;
|
||||
}
|
||||
|
||||
|
||||
|
||||
$pageUrl = str_replace($varName, $varValue, $pageUrl);
|
||||
|
||||
|
||||
@@ -1275,4 +1275,28 @@ class RestContext extends BehatContext
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
/**
|
||||
* @When /^I request "([^"]*)" with the keys? "([^"]*)" stored in session array$/
|
||||
*/
|
||||
public function iRequestWithTheKeysStoredInSessionArray($url, $sessionVarName)
|
||||
{
|
||||
if (file_exists("session.data")) {
|
||||
$sessionData = json_decode(file_get_contents("session.data"));
|
||||
} else {
|
||||
$sessionData = array();
|
||||
}
|
||||
|
||||
$arraySessionVarName = explode(",", $sessionVarName);
|
||||
|
||||
foreach ($arraySessionVarName as $value) {
|
||||
$varName = trim($value);
|
||||
|
||||
$varValue = (isset($sessionData->$varName))? $sessionData->$varName : "";
|
||||
|
||||
$url = str_replace($varName, $varValue, $url);
|
||||
}
|
||||
|
||||
$this->iRequest($url);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -227,10 +227,10 @@ class Group
|
||||
$arrayData = array_change_key_case($arrayData, CASE_UPPER);
|
||||
|
||||
//Verify data
|
||||
$this->throwExceptionIfNoExistsGroup($groupUid, $this->arrayFieldNameForException["groupUid"]);
|
||||
|
||||
$process = new \BusinessModel\Process();
|
||||
|
||||
$this->throwExceptionIfNoExistsGroup($groupUid, $this->arrayFieldNameForException["groupUid"]);
|
||||
|
||||
$process->throwExceptionIfDataNotMetFieldDefinition($arrayData, $this->arrayFieldDefinition, $this->arrayFieldNameForException, false);
|
||||
|
||||
if (isset($arrayData["GRP_TITLE"])) {
|
||||
@@ -475,7 +475,7 @@ class Group
|
||||
$criteria = $this->getGroupCriteria();
|
||||
|
||||
if (!is_null($arrayFilterData) && is_array($arrayFilterData) && isset($arrayFilterData["filter"]) && trim($arrayFilterData["filter"]) != "") {
|
||||
$criteria->add(\ContentPeer::CON_VALUE, "%" . trim($arrayFilterData["filter"]) . "%", \Criteria::LIKE);
|
||||
$criteria->add(\ContentPeer::CON_VALUE, "%" . $arrayFilterData["filter"] . "%", \Criteria::LIKE);
|
||||
}
|
||||
|
||||
//Number records total
|
||||
@@ -616,12 +616,10 @@ class Group
|
||||
}
|
||||
|
||||
if (!is_null($arrayFilterData) && is_array($arrayFilterData) && isset($arrayFilterData["filter"]) && trim($arrayFilterData["filter"]) != "") {
|
||||
$filter = trim($arrayFilterData["filter"]);
|
||||
|
||||
$criteria->add(
|
||||
$criteria->getNewCriterion(\UsersPeer::USR_USERNAME, "%" . $filter . "%", \Criteria::LIKE)->addOr(
|
||||
$criteria->getNewCriterion(\UsersPeer::USR_FIRSTNAME, "%" . $filter . "%", \Criteria::LIKE)->addOr(
|
||||
$criteria->getNewCriterion(\UsersPeer::USR_LASTNAME, "%" . $filter . "%", \Criteria::LIKE)))
|
||||
$criteria->getNewCriterion(\UsersPeer::USR_USERNAME, "%" . $arrayFilterData["filter"] . "%", \Criteria::LIKE)->addOr(
|
||||
$criteria->getNewCriterion(\UsersPeer::USR_FIRSTNAME, "%" . $arrayFilterData["filter"] . "%", \Criteria::LIKE)->addOr(
|
||||
$criteria->getNewCriterion(\UsersPeer::USR_LASTNAME, "%" . $arrayFilterData["filter"] . "%", \Criteria::LIKE)))
|
||||
);
|
||||
}
|
||||
|
||||
@@ -673,10 +671,10 @@ class Group
|
||||
$arrayUser = array();
|
||||
|
||||
//Verify data
|
||||
$this->throwExceptionIfNoExistsGroup($groupUid, $this->arrayFieldNameForException["groupUid"]);
|
||||
|
||||
$process = new \BusinessModel\Process();
|
||||
|
||||
$this->throwExceptionIfNoExistsGroup($groupUid, $this->arrayFieldNameForException["groupUid"]);
|
||||
|
||||
$process->throwExceptionIfDataNotMetPagerVarDefinition(array("start" => $start, "limit" => $limit), $this->arrayFieldNameForException);
|
||||
|
||||
//Get data
|
||||
|
||||
206
workflow/engine/src/BusinessModel/Group/User.php
Normal file
206
workflow/engine/src/BusinessModel/Group/User.php
Normal file
@@ -0,0 +1,206 @@
|
||||
<?php
|
||||
namespace BusinessModel\Group;
|
||||
|
||||
class User
|
||||
{
|
||||
private $arrayFieldDefinition = array(
|
||||
"GRP_UID" => array("type" => "string", "required" => false, "empty" => false, "defaultValues" => array(), "fieldNameAux" => "groupUid"),
|
||||
"USR_UID" => array("type" => "string", "required" => true, "empty" => false, "defaultValues" => array(), "fieldNameAux" => "userUid")
|
||||
);
|
||||
|
||||
private $formatFieldNameInUppercase = true;
|
||||
|
||||
private $arrayFieldNameForException = array();
|
||||
|
||||
/**
|
||||
* Constructor of the class
|
||||
*
|
||||
* return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
try {
|
||||
foreach ($this->arrayFieldDefinition as $key => $value) {
|
||||
$this->arrayFieldNameForException[$value["fieldNameAux"]] = $key;
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the format of the fields name (uppercase, lowercase)
|
||||
*
|
||||
* @param bool $flag Value that set the format
|
||||
*
|
||||
* return void
|
||||
*/
|
||||
public function setFormatFieldNameInUppercase($flag)
|
||||
{
|
||||
try {
|
||||
$this->formatFieldNameInUppercase = $flag;
|
||||
|
||||
$this->setArrayFieldNameForException($this->arrayFieldNameForException);
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set exception messages for fields
|
||||
*
|
||||
* @param array $arrayData Data with the fields
|
||||
*
|
||||
* return void
|
||||
*/
|
||||
public function setArrayFieldNameForException($arrayData)
|
||||
{
|
||||
try {
|
||||
foreach ($arrayData as $key => $value) {
|
||||
$this->arrayFieldNameForException[$key] = $this->getFieldNameByFormatFieldName($value);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the name of the field according to the format
|
||||
*
|
||||
* @param string $fieldName Field name
|
||||
*
|
||||
* return string Return the field name according the format
|
||||
*/
|
||||
public function getFieldNameByFormatFieldName($fieldName)
|
||||
{
|
||||
try {
|
||||
return ($this->formatFieldNameInUppercase)? strtoupper($fieldName) : strtolower($fieldName);
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify if doesn't exist the User in Group
|
||||
*
|
||||
* @param string $groupUid Unique id of Group
|
||||
* @param string $userUid Unique id of User
|
||||
* @param string $fieldNameForException Field name for the exception
|
||||
*
|
||||
* return void Throw exception if doesn't exist the User in Group
|
||||
*/
|
||||
public function throwExceptionIfNotExistsGroupUser($groupUid, $userUid, $fieldNameForException)
|
||||
{
|
||||
try {
|
||||
$obj = \GroupUserPeer::retrieveByPK($groupUid, $userUid);
|
||||
|
||||
if (!(is_object($obj) && get_class($obj) == "GroupUser")) {
|
||||
$msg = str_replace(array("{0}", "{1}"), array($fieldNameForException, $userUid), "The user with {0}: {1}, is not assigned to the group");
|
||||
|
||||
throw (new \Exception($msg));
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify if exists the User in Group
|
||||
*
|
||||
* @param string $groupUid Unique id of Group
|
||||
* @param string $userUid Unique id of User
|
||||
* @param string $fieldNameForException Field name for the exception
|
||||
*
|
||||
* return void Throw exception if exists the User in Group
|
||||
*/
|
||||
public function throwExceptionIfExistsGroupUser($groupUid, $userUid, $fieldNameForException)
|
||||
{
|
||||
try {
|
||||
$obj = \GroupUserPeer::retrieveByPK($groupUid, $userUid);
|
||||
|
||||
if (is_object($obj) && get_class($obj) == "GroupUser") {
|
||||
$msg = str_replace(array("{0}", "{1}"), array($fieldNameForException, $userUid), "The user with {0}: {1}, is already assigned to the group");
|
||||
|
||||
throw (new \Exception($msg));
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Assign User to Group
|
||||
*
|
||||
* @param string $groupUid Unique id of Group
|
||||
* @param array $arrayData Data
|
||||
*
|
||||
* return array Return data of the User assigned to Group
|
||||
*/
|
||||
public function create($groupUid, $arrayData)
|
||||
{
|
||||
try {
|
||||
$arrayData = array_change_key_case($arrayData, CASE_UPPER);
|
||||
|
||||
unset($arrayData["GRP_UID"]);
|
||||
|
||||
//Verify data
|
||||
$process = new \BusinessModel\Process();
|
||||
$group = new \BusinessModel\Group();
|
||||
|
||||
$group->throwExceptionIfNoExistsGroup($groupUid, $this->arrayFieldNameForException["groupUid"]);
|
||||
|
||||
$process->throwExceptionIfDataNotMetFieldDefinition($arrayData, $this->arrayFieldDefinition, $this->arrayFieldNameForException, true);
|
||||
|
||||
$process->throwExceptionIfNoExistsUser($arrayData["USR_UID"], $this->arrayFieldNameForException["userUid"]);
|
||||
|
||||
$this->throwExceptionIfExistsGroupUser($groupUid, $arrayData["USR_UID"], $this->arrayFieldNameForException["userUid"]);
|
||||
|
||||
//Create
|
||||
$group = new \Groups();
|
||||
|
||||
$group->addUserToGroup($groupUid, $arrayData["USR_UID"]);
|
||||
|
||||
//Return
|
||||
$arrayData = array_merge(array("GRP_UID" => $groupUid), $arrayData);
|
||||
|
||||
if (!$this->formatFieldNameInUppercase) {
|
||||
$arrayData = array_change_key_case($arrayData, CASE_LOWER);
|
||||
}
|
||||
|
||||
return $arrayData;
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Unassign User of the Group
|
||||
*
|
||||
* @param string $groupUid Unique id of Group
|
||||
* @param string $userUid Unique id of User
|
||||
*
|
||||
* return void
|
||||
*/
|
||||
public function delete($groupUid, $userUid)
|
||||
{
|
||||
try {
|
||||
//Verify data
|
||||
$process = new \BusinessModel\Process();
|
||||
$group = new \BusinessModel\Group();
|
||||
|
||||
$group->throwExceptionIfNoExistsGroup($groupUid, $this->arrayFieldNameForException["groupUid"]);
|
||||
|
||||
$process->throwExceptionIfNoExistsUser($userUid, $this->arrayFieldNameForException["userUid"]);
|
||||
|
||||
$this->throwExceptionIfNotExistsGroupUser($groupUid, $userUid, $this->arrayFieldNameForException["userUid"]);
|
||||
|
||||
//Delete
|
||||
$group = new \Groups();
|
||||
|
||||
$group->removeUserOfGroup($groupUid, $userUid);
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
52
workflow/engine/src/Services/Api/ProcessMaker/Group/User.php
Normal file
52
workflow/engine/src/Services/Api/ProcessMaker/Group/User.php
Normal file
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
namespace Services\Api\ProcessMaker\Group;
|
||||
|
||||
use \ProcessMaker\Services\Api;
|
||||
use \Luracast\Restler\RestException;
|
||||
|
||||
/**
|
||||
* Group\User Api Controller
|
||||
*
|
||||
* @protected
|
||||
*/
|
||||
class User extends Api
|
||||
{
|
||||
/**
|
||||
* @url POST /:grp_uid/user
|
||||
*
|
||||
* @param string $grp_uid {@min 32}{@max 32}
|
||||
* @param array $request_data
|
||||
*
|
||||
* @status 201
|
||||
*/
|
||||
public function doPostUser($grp_uid, $request_data)
|
||||
{
|
||||
try {
|
||||
$groupUser = new \BusinessModel\Group\User();
|
||||
$groupUser->setFormatFieldNameInUppercase(false);
|
||||
|
||||
$arrayData = $groupUser->create($grp_uid, $request_data);
|
||||
} catch (\Exception $e) {
|
||||
throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage()));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @url DELETE /:grp_uid/user/:usr_uid
|
||||
*
|
||||
* @param string $grp_uid {@min 32}{@max 32}
|
||||
* @param string $usr_uid {@min 32}{@max 32}
|
||||
*/
|
||||
public function doDeleteUser($grp_uid, $usr_uid)
|
||||
{
|
||||
try {
|
||||
$groupUser = new \BusinessModel\Group\User();
|
||||
$groupUser->setFormatFieldNameInUppercase(false);
|
||||
|
||||
$groupUser->delete($grp_uid, $usr_uid);
|
||||
} catch (\Exception $e) {
|
||||
throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user