HOR-4391 Error when creating a role by End Point
- Create rol Code Style Fix CR Fix CR Add validation Render format date
This commit is contained in:
committed by
Paula Quispe
parent
9a42249df8
commit
255a9526d2
File diff suppressed because it is too large
Load Diff
@@ -1,30 +1,47 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace ProcessMaker\BusinessModel;
|
namespace ProcessMaker\BusinessModel;
|
||||||
|
|
||||||
require_once(PATH_RBAC . "model" . PATH_SEP . "Roles.php");
|
use Configurations;
|
||||||
|
use Content;
|
||||||
|
use Criteria;
|
||||||
|
use DateTime;
|
||||||
|
use Exception;
|
||||||
|
use G;
|
||||||
|
use ProcessMaker\Util\Common;
|
||||||
|
use ResultSet;
|
||||||
|
use Roles as ModelRoles;
|
||||||
|
use RolesPeer;
|
||||||
|
use UsersRolesPeer;
|
||||||
|
|
||||||
|
|
||||||
|
require_once PATH_RBAC . 'model' . PATH_SEP . 'Roles.php';
|
||||||
|
|
||||||
class Role
|
class Role
|
||||||
{
|
{
|
||||||
private $arrayFieldDefinition = array(
|
private $arrayFieldDefinition = [
|
||||||
"ROL_UID" => array("type" => "string", "required" => false, "empty" => false, "defaultValues" => array(), "fieldNameAux" => "roleUid"),
|
'ROL_UID' => ['type' => 'string', 'required' => false, 'empty' => false, 'defaultValues' => [], 'fieldNameAux' => 'roleUid'],
|
||||||
|
|
||||||
"ROL_CODE" => array("type" => "string", "required" => true, "empty" => false, "defaultValues" => array(), "fieldNameAux" => "roleCode"),
|
'ROL_CODE' => ['type' => 'string', 'required' => true, 'empty' => false, 'defaultValues' => [], 'fieldNameAux' => 'roleCode'],
|
||||||
"ROL_NAME" => array("type" => "string", "required" => true, "empty" => false, "defaultValues" => array(), "fieldNameAux" => "roleName"),
|
'ROL_NAME' => ['type' => 'string', 'required' => true, 'empty' => false, 'defaultValues' => [], 'fieldNameAux' => 'roleName'],
|
||||||
"ROL_STATUS" => array("type" => "string", "required" => false, "empty" => false, "defaultValues" => array("ACTIVE", "INACTIVE"), "fieldNameAux" => "roleStatus")
|
'ROL_STATUS' => ['type' => 'string', 'required' => false, 'empty' => false, 'defaultValues' => ['ACTIVE', 'INACTIVE'], 'fieldNameAux' => 'roleStatus']
|
||||||
);
|
];
|
||||||
|
|
||||||
private $formatFieldNameInUppercase = true;
|
private $formatFieldNameInUppercase = true;
|
||||||
|
|
||||||
private $arrayFieldNameForException = array(
|
private $arrayFieldNameForException = [
|
||||||
"filter" => "FILTER",
|
'filter' => 'FILTER',
|
||||||
"start" => "START",
|
'start' => 'START',
|
||||||
"limit" => "LIMIT"
|
'limit' => 'LIMIT'
|
||||||
);
|
];
|
||||||
|
|
||||||
|
const SYSTEM_RBAC = '00000000000000000000000000000001';
|
||||||
|
const SYSTEM_PROCESSMAKER = '00000000000000000000000000000002';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor of the class
|
* Role constructor.
|
||||||
*
|
*
|
||||||
* return void
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
@@ -32,7 +49,7 @@ class Role
|
|||||||
foreach ($this->arrayFieldDefinition as $key => $value) {
|
foreach ($this->arrayFieldDefinition as $key => $value) {
|
||||||
$this->arrayFieldNameForException[$value["fieldNameAux"]] = $key;
|
$this->arrayFieldNameForException[$value["fieldNameAux"]] = $key;
|
||||||
}
|
}
|
||||||
} catch (\Exception $e) {
|
} catch (Exception $e) {
|
||||||
throw $e;
|
throw $e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -42,7 +59,8 @@ class Role
|
|||||||
*
|
*
|
||||||
* @param bool $flag Value that set the format
|
* @param bool $flag Value that set the format
|
||||||
*
|
*
|
||||||
* return void
|
* @return void
|
||||||
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function setFormatFieldNameInUppercase($flag)
|
public function setFormatFieldNameInUppercase($flag)
|
||||||
{
|
{
|
||||||
@@ -50,7 +68,7 @@ class Role
|
|||||||
$this->formatFieldNameInUppercase = $flag;
|
$this->formatFieldNameInUppercase = $flag;
|
||||||
|
|
||||||
$this->setArrayFieldNameForException($this->arrayFieldNameForException);
|
$this->setArrayFieldNameForException($this->arrayFieldNameForException);
|
||||||
} catch (\Exception $e) {
|
} catch (Exception $e) {
|
||||||
throw $e;
|
throw $e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -60,7 +78,8 @@ class Role
|
|||||||
*
|
*
|
||||||
* @param array $arrayData Data with the fields
|
* @param array $arrayData Data with the fields
|
||||||
*
|
*
|
||||||
* return void
|
* @return void
|
||||||
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function setArrayFieldNameForException(array $arrayData)
|
public function setArrayFieldNameForException(array $arrayData)
|
||||||
{
|
{
|
||||||
@@ -68,7 +87,7 @@ class Role
|
|||||||
foreach ($arrayData as $key => $value) {
|
foreach ($arrayData as $key => $value) {
|
||||||
$this->arrayFieldNameForException[$key] = $this->getFieldNameByFormatFieldName($value);
|
$this->arrayFieldNameForException[$key] = $this->getFieldNameByFormatFieldName($value);
|
||||||
}
|
}
|
||||||
} catch (\Exception $e) {
|
} catch (Exception $e) {
|
||||||
throw $e;
|
throw $e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -78,13 +97,14 @@ class Role
|
|||||||
*
|
*
|
||||||
* @param string $fieldName Field name
|
* @param string $fieldName Field name
|
||||||
*
|
*
|
||||||
* return string Return the field name according the format
|
* @return string Return the field name according the format
|
||||||
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function getFieldNameByFormatFieldName($fieldName)
|
public function getFieldNameByFormatFieldName($fieldName)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
return ($this->formatFieldNameInUppercase)? strtoupper($fieldName) : strtolower($fieldName);
|
return ($this->formatFieldNameInUppercase) ? strtoupper($fieldName) : strtolower($fieldName);
|
||||||
} catch (\Exception $e) {
|
} catch (Exception $e) {
|
||||||
throw $e;
|
throw $e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -92,35 +112,37 @@ class Role
|
|||||||
/**
|
/**
|
||||||
* Verify if exists the code of a Role
|
* Verify if exists the code of a Role
|
||||||
*
|
*
|
||||||
* @param string $roleCode Code
|
* @param string $roleCode Code
|
||||||
* @param string $roleSystemUid Unique id of System (00000000000000000000000000000001: RBAC, 00000000000000000000000000000002: PROCESSMAKER)
|
* @param string $roleSystemUid Unique id of System (00000000000000000000000000000001: RBAC,
|
||||||
|
* 00000000000000000000000000000002: PROCESSMAKER)
|
||||||
* @param string $roleUidExclude Unique id of Role to exclude
|
* @param string $roleUidExclude Unique id of Role to exclude
|
||||||
*
|
*
|
||||||
* return bool Return true if exists the code of a Role, false otherwise
|
* @return bool Return true if exists the code of a Role, false otherwise
|
||||||
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function existsCode($roleCode, $roleSystemUid, $roleUidExclude = "")
|
public function existsCode($roleCode, $roleSystemUid, $roleUidExclude = "")
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$criteria = new \Criteria("rbac");
|
$criteria = new Criteria("rbac");
|
||||||
|
|
||||||
$criteria->addSelectColumn(\RolesPeer::ROL_UID);
|
$criteria->addSelectColumn(RolesPeer::ROL_UID);
|
||||||
|
|
||||||
$criteria->add(\RolesPeer::ROL_SYSTEM, $roleSystemUid, \Criteria::EQUAL);
|
$criteria->add(RolesPeer::ROL_SYSTEM, $roleSystemUid, Criteria::EQUAL);
|
||||||
|
|
||||||
if ($roleUidExclude != "") {
|
if (!empty($roleUidExclude)) {
|
||||||
$criteria->add(\RolesPeer::ROL_UID, $roleUidExclude, \Criteria::NOT_EQUAL);
|
$criteria->add(RolesPeer::ROL_UID, $roleUidExclude, Criteria::NOT_EQUAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
$criteria->add(\RolesPeer::ROL_CODE, $roleCode, \Criteria::EQUAL);
|
$criteria->add(RolesPeer::ROL_CODE, $roleCode, Criteria::EQUAL);
|
||||||
|
|
||||||
$rsCriteria = \RolesPeer::doSelectRS($criteria);
|
$rsCriteria = RolesPeer::doSelectRS($criteria);
|
||||||
|
|
||||||
if ($rsCriteria->next()) {
|
if ($rsCriteria->next()) {
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} catch (\Exception $e) {
|
} catch (Exception $e) {
|
||||||
throw $e;
|
throw $e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -128,34 +150,36 @@ class Role
|
|||||||
/**
|
/**
|
||||||
* Verify if exists the name of a Role
|
* Verify if exists the name of a Role
|
||||||
*
|
*
|
||||||
* @param string $roleName Name
|
* @param string $roleName Name
|
||||||
* @param string $roleSystemUid Unique id of System (00000000000000000000000000000001: RBAC, 00000000000000000000000000000002: PROCESSMAKER)
|
* @param string $roleSystemUid Unique id of System (00000000000000000000000000000001: RBAC,
|
||||||
|
* 00000000000000000000000000000002: PROCESSMAKER)
|
||||||
* @param string $roleUidExclude Unique id of Role to exclude
|
* @param string $roleUidExclude Unique id of Role to exclude
|
||||||
*
|
*
|
||||||
* return bool Return true if exists the name of a Role, false otherwise
|
* @return bool Return true if exists the name of a Role, false otherwise
|
||||||
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function existsName($roleName, $roleSystemUid, $roleUidExclude = "")
|
public function existsName($roleName, $roleSystemUid, $roleUidExclude = "")
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
//Set variables
|
//Set variables
|
||||||
$content = new \Content();
|
$content = new Content();
|
||||||
$role = new \Roles();
|
$role = new ModelRoles();
|
||||||
|
|
||||||
$arrayContentByRole = $content->getAllContentsByRole();
|
$arrayContentByRole = $content->getAllContentsByRole();
|
||||||
|
|
||||||
//SQL
|
//SQL
|
||||||
$criteria = new \Criteria("rbac");
|
$criteria = new Criteria("rbac");
|
||||||
|
|
||||||
$criteria->addSelectColumn(\RolesPeer::ROL_UID);
|
$criteria->addSelectColumn(RolesPeer::ROL_UID);
|
||||||
|
|
||||||
$criteria->add(\RolesPeer::ROL_SYSTEM, $roleSystemUid, \Criteria::EQUAL);
|
$criteria->add(RolesPeer::ROL_SYSTEM, $roleSystemUid, Criteria::EQUAL);
|
||||||
|
|
||||||
if ($roleUidExclude != "") {
|
if ($roleUidExclude != "") {
|
||||||
$criteria->add(\RolesPeer::ROL_UID, $roleUidExclude, \Criteria::NOT_EQUAL);
|
$criteria->add(RolesPeer::ROL_UID, $roleUidExclude, Criteria::NOT_EQUAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
$rsCriteria = \RolesPeer::doSelectRS($criteria);
|
$rsCriteria = RolesPeer::doSelectRS($criteria);
|
||||||
$rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
|
$rsCriteria->setFetchmode(ResultSet::FETCHMODE_ASSOC);
|
||||||
|
|
||||||
while ($rsCriteria->next()) {
|
while ($rsCriteria->next()) {
|
||||||
$row = $rsCriteria->getRow();
|
$row = $rsCriteria->getRow();
|
||||||
@@ -175,7 +199,7 @@ class Role
|
|||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
} catch (\Exception $e) {
|
} catch (Exception $e) {
|
||||||
throw $e;
|
throw $e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -183,20 +207,21 @@ class Role
|
|||||||
/**
|
/**
|
||||||
* Verify if does not exist the Role in table ROLES
|
* Verify if does not exist the Role in table ROLES
|
||||||
*
|
*
|
||||||
* @param string $roleUid Unique id of Role
|
* @param string $roleUid Unique id of Role
|
||||||
* @param string $fieldNameForException Field name for the exception
|
* @param string $fieldNameForException Field name for the exception
|
||||||
*
|
*
|
||||||
* return void Throw exception if does not exist the Role in table ROLES
|
* @return void Throw exception if does not exist the Role in table ROLES
|
||||||
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function throwExceptionIfNotExistsRole($roleUid, $fieldNameForException)
|
public function throwExceptionIfNotExistsRole($roleUid, $fieldNameForException)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$obj = \RolesPeer::retrieveByPK($roleUid);
|
$obj = RolesPeer::retrieveByPK($roleUid);
|
||||||
|
|
||||||
if (is_null($obj)) {
|
if (is_null($obj)) {
|
||||||
throw new \Exception(\G::LoadTranslation("ID_ROLE_DOES_NOT_EXIST", array($fieldNameForException, $roleUid)));
|
throw new Exception(G::LoadTranslation("ID_ROLE_DOES_NOT_EXIST", [$fieldNameForException, $roleUid]));
|
||||||
}
|
}
|
||||||
} catch (\Exception $e) {
|
} catch (Exception $e) {
|
||||||
throw $e;
|
throw $e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -204,20 +229,22 @@ class Role
|
|||||||
/**
|
/**
|
||||||
* Verify if exists the code of a Role
|
* Verify if exists the code of a Role
|
||||||
*
|
*
|
||||||
* @param string $roleCode Code
|
* @param string $roleCode Code
|
||||||
* @param string $roleSystemUid Unique id of System (00000000000000000000000000000001: RBAC, 00000000000000000000000000000002: PROCESSMAKER)
|
* @param string $roleSystemUid Unique id of System (00000000000000000000000000000001: RBAC,
|
||||||
|
* 00000000000000000000000000000002: PROCESSMAKER)
|
||||||
* @param string $fieldNameForException Field name for the exception
|
* @param string $fieldNameForException Field name for the exception
|
||||||
* @param string $roleUidExclude Unique id of Role to exclude
|
* @param string $roleUidExclude Unique id of Role to exclude
|
||||||
*
|
*
|
||||||
* return void Throw exception if exists the code of a Role
|
* @return void Throw exception if exists the code of a Role
|
||||||
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function throwExceptionIfExistsCode($roleCode, $roleSystemUid, $fieldNameForException, $roleUidExclude = "")
|
public function throwExceptionIfExistsCode($roleCode, $roleSystemUid, $fieldNameForException, $roleUidExclude = "")
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
if ($this->existsCode($roleCode, $roleSystemUid, $roleUidExclude)) {
|
if ($this->existsCode($roleCode, $roleSystemUid, $roleUidExclude)) {
|
||||||
throw new \Exception(\G::LoadTranslation("ID_ROLE_CODE_ALREADY_EXISTS", array($fieldNameForException, $roleCode)));
|
throw new Exception(G::LoadTranslation("ID_ROLE_CODE_ALREADY_EXISTS", [$fieldNameForException, $roleCode]));
|
||||||
}
|
}
|
||||||
} catch (\Exception $e) {
|
} catch (Exception $e) {
|
||||||
throw $e;
|
throw $e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -225,20 +252,22 @@ class Role
|
|||||||
/**
|
/**
|
||||||
* Verify if exists the name of a Role
|
* Verify if exists the name of a Role
|
||||||
*
|
*
|
||||||
* @param string $roleName Name
|
* @param string $roleName Name
|
||||||
* @param string $roleSystemUid Unique id of System (00000000000000000000000000000001: RBAC, 00000000000000000000000000000002: PROCESSMAKER)
|
* @param string $roleSystemUid Unique id of System (00000000000000000000000000000001: RBAC,
|
||||||
|
* 00000000000000000000000000000002: PROCESSMAKER)
|
||||||
* @param string $fieldNameForException Field name for the exception
|
* @param string $fieldNameForException Field name for the exception
|
||||||
* @param string $roleUidExclude Unique id of Role to exclude
|
* @param string $roleUidExclude Unique id of Role to exclude
|
||||||
*
|
*
|
||||||
* return void Throw exception if exists the name of a Role
|
* @return void Throw exception if exists the name of a Role
|
||||||
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function throwExceptionIfExistsName($roleName, $roleSystemUid, $fieldNameForException, $roleUidExclude = "")
|
public function throwExceptionIfExistsName($roleName, $roleSystemUid, $fieldNameForException, $roleUidExclude = "")
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
if ($this->existsName($roleName, $roleSystemUid, $roleUidExclude)) {
|
if ($this->existsName($roleName, $roleSystemUid, $roleUidExclude)) {
|
||||||
throw new \Exception(\G::LoadTranslation("ID_ROLE_NAME_ALREADY_EXISTS", array($fieldNameForException, $roleName)));
|
throw new Exception(G::LoadTranslation("ID_ROLE_NAME_ALREADY_EXISTS", [$fieldNameForException, $roleName]));
|
||||||
}
|
}
|
||||||
} catch (\Exception $e) {
|
} catch (Exception $e) {
|
||||||
throw $e;
|
throw $e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -246,28 +275,29 @@ class Role
|
|||||||
/**
|
/**
|
||||||
* Validate the data if they are invalid (INSERT and UPDATE)
|
* Validate the data if they are invalid (INSERT and UPDATE)
|
||||||
*
|
*
|
||||||
* @param string $roleUid Unique id of Role
|
* @param string $roleUid Unique id of Role
|
||||||
* @param array $arrayData Data
|
* @param array $arrayData Data
|
||||||
*
|
*
|
||||||
* return void Throw exception if data has an invalid value
|
* @return void Throw exception if data has an invalid value
|
||||||
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function throwExceptionIfDataIsInvalid($roleUid, array $arrayData)
|
public function throwExceptionIfDataIsInvalid($roleUid, array $arrayData)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
//Set variables
|
//Set variables
|
||||||
$arrayRoleData = ($roleUid == "")? array() : $this->getRole($roleUid, true);
|
$arrayRoleData = ($roleUid == "") ? [] : $this->getRole($roleUid, true);
|
||||||
$flagInsert = ($roleUid == "")? true : false;
|
$flagInsert = ($roleUid == "") ? true : false;
|
||||||
|
|
||||||
$arrayDataMain = array_merge($arrayRoleData, $arrayData);
|
$arrayDataMain = array_merge($arrayRoleData, $arrayData);
|
||||||
|
|
||||||
//Verify data - Field definition
|
//Verify data - Field definition
|
||||||
$process = new \ProcessMaker\BusinessModel\Process();
|
$process = new Process();
|
||||||
|
|
||||||
$process->throwExceptionIfDataNotMetFieldDefinition($arrayData, $this->arrayFieldDefinition, $this->arrayFieldNameForException, $flagInsert);
|
$process->throwExceptionIfDataNotMetFieldDefinition($arrayData, $this->arrayFieldDefinition, $this->arrayFieldNameForException, $flagInsert);
|
||||||
|
|
||||||
//Verify data
|
//Verify data
|
||||||
if (isset($arrayData["ROL_CODE"]) && !preg_match("/^\w+$/", $arrayData["ROL_CODE"])) {
|
if (isset($arrayData["ROL_CODE"]) && !preg_match("/^\w+$/", $arrayData["ROL_CODE"])) {
|
||||||
throw new \Exception(\G::LoadTranslation("ID_ROLE_FIELD_CANNOT_CONTAIN_SPECIAL_CHARACTERS", array($this->arrayFieldNameForException["roleCode"])));
|
throw new Exception(G::LoadTranslation("ID_ROLE_FIELD_CANNOT_CONTAIN_SPECIAL_CHARACTERS", [$this->arrayFieldNameForException["roleCode"]]));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($arrayData["ROL_CODE"])) {
|
if (isset($arrayData["ROL_CODE"])) {
|
||||||
@@ -277,7 +307,7 @@ class Role
|
|||||||
if (isset($arrayData["ROL_NAME"])) {
|
if (isset($arrayData["ROL_NAME"])) {
|
||||||
$this->throwExceptionIfExistsName($arrayData["ROL_NAME"], $arrayDataMain["ROL_SYSTEM"], $this->arrayFieldNameForException["roleName"], $roleUid);
|
$this->throwExceptionIfExistsName($arrayData["ROL_NAME"], $arrayDataMain["ROL_SYSTEM"], $this->arrayFieldNameForException["roleName"], $roleUid);
|
||||||
}
|
}
|
||||||
} catch (\Exception $e) {
|
} catch (Exception $e) {
|
||||||
throw $e;
|
throw $e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -287,41 +317,42 @@ class Role
|
|||||||
*
|
*
|
||||||
* @param array $arrayData Data
|
* @param array $arrayData Data
|
||||||
*
|
*
|
||||||
* return array Return data of the new Role created
|
* @return array Return data of the new Role created
|
||||||
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function create(array $arrayData)
|
public function create(array $arrayData)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
//Verify data
|
//Verify data
|
||||||
$process = new \ProcessMaker\BusinessModel\Process();
|
$validator = new Validator();
|
||||||
$validator = new \ProcessMaker\BusinessModel\Validator();
|
|
||||||
|
|
||||||
$validator->throwExceptionIfDataIsEmpty($arrayData, "\$arrayData");
|
$validator->throwExceptionIfDataIsEmpty($arrayData, "\$arrayData");
|
||||||
|
|
||||||
//Set data
|
//Set data
|
||||||
$arrayData = array_change_key_case($arrayData, CASE_UPPER);
|
$arrayData = array_change_key_case($arrayData, CASE_UPPER);
|
||||||
|
|
||||||
unset($arrayData["ROL_UID"]);
|
unset($arrayData['ROL_UID']);
|
||||||
|
|
||||||
$arrayData["ROL_SYSTEM"] = "00000000000000000000000000000002"; //PROCESSMAKER
|
$arrayData['ROL_SYSTEM'] = self::SYSTEM_PROCESSMAKER;
|
||||||
|
|
||||||
//Verify data
|
//Verify data
|
||||||
$this->throwExceptionIfDataIsInvalid("", $arrayData);
|
$this->throwExceptionIfDataIsInvalid('', $arrayData);
|
||||||
|
|
||||||
//Create
|
//Create
|
||||||
$role = new \Roles();
|
$role = new ModelRoles();
|
||||||
|
|
||||||
$roleUid = \ProcessMaker\Util\Common::generateUID();
|
$roleUid = Common::generateUID();
|
||||||
|
|
||||||
$arrayData["ROL_UID"] = $roleUid;
|
$arrayData['ROL_UID'] = $roleUid;
|
||||||
$arrayData["ROL_STATUS"] = (isset($arrayData["ROL_STATUS"]))? (($arrayData["ROL_STATUS"] == "ACTIVE")? 1 : 0) : 1;
|
$arrayData['ROL_STATUS'] = isset($arrayData['ROL_STATUS']) ? $arrayData['ROL_STATUS'] === 'ACTIVE' ? 1 : 0 : 1;
|
||||||
$arrayData["ROL_CREATE_DATE"] = date("Y-M-d H:i:s");
|
$arrayData['ROL_CREATE_DATE'] = date('Y-M-d H:i:s');
|
||||||
|
$arrayData['ROL_UPDATE_DATE'] = date('Y-M-d H:i:s');
|
||||||
|
|
||||||
$result = $role->createRole($arrayData);
|
$role->createRole($arrayData);
|
||||||
|
|
||||||
//Return
|
//Return
|
||||||
return $this->getRole($roleUid);
|
return $this->getRole($roleUid);
|
||||||
} catch (\Exception $e) {
|
} catch (Exception $e) {
|
||||||
throw $e;
|
throw $e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -329,17 +360,17 @@ class Role
|
|||||||
/**
|
/**
|
||||||
* Update Role
|
* Update Role
|
||||||
*
|
*
|
||||||
* @param string $roleUid Unique id of Role
|
* @param string $roleUid Unique id of Role
|
||||||
* @param array $arrayData Data
|
* @param array $arrayData Data
|
||||||
*
|
*
|
||||||
* return array Return data of the Role updated
|
* @return array Return data of the Role updated
|
||||||
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function update($roleUid, array $arrayData)
|
public function update($roleUid, array $arrayData)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
//Verify data
|
//Verify data
|
||||||
$process = new \ProcessMaker\BusinessModel\Process();
|
$validator = new Validator();
|
||||||
$validator = new \ProcessMaker\BusinessModel\Validator();
|
|
||||||
|
|
||||||
$validator->throwExceptionIfDataIsEmpty($arrayData, "\$arrayData");
|
$validator->throwExceptionIfDataIsEmpty($arrayData, "\$arrayData");
|
||||||
|
|
||||||
@@ -350,29 +381,29 @@ class Role
|
|||||||
$arrayRoleData = $this->getRole($roleUid);
|
$arrayRoleData = $this->getRole($roleUid);
|
||||||
|
|
||||||
//Verify data
|
//Verify data
|
||||||
$this->throwExceptionIfNotExistsRole($roleUid, $this->arrayFieldNameForException["roleUid"]);
|
$this->throwExceptionIfNotExistsRole($roleUid, $this->arrayFieldNameForException['roleUid']);
|
||||||
|
|
||||||
if ($roleUid == "00000000000000000000000000000002") {
|
if ($roleUid === self::SYSTEM_PROCESSMAKER) {
|
||||||
throw new \Exception(\G::LoadTranslation("ID_ROLES_MSG"));
|
throw new Exception(G::LoadTranslation('ID_ROLES_MSG'));
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->throwExceptionIfDataIsInvalid($roleUid, $arrayData);
|
$this->throwExceptionIfDataIsInvalid($roleUid, $arrayData);
|
||||||
|
|
||||||
//Update
|
//Update
|
||||||
$role = new \Roles();
|
$role = new ModelRoles();
|
||||||
|
|
||||||
$arrayData["ROL_UID"] = $roleUid;
|
$arrayData['ROL_UID'] = $roleUid;
|
||||||
$arrayData["ROL_UPDATE_DATE"] = date("Y-M-d H:i:s");
|
$arrayData['ROL_UPDATE_DATE'] = date('Y-M-d H:i:s');
|
||||||
|
|
||||||
if (!isset($arrayData["ROL_NAME"])) {
|
if (!isset($arrayData['ROL_NAME'])) {
|
||||||
$arrayData["ROL_NAME"] = $arrayRoleData[$this->getFieldNameByFormatFieldName("ROL_NAME")];
|
$arrayData['ROL_NAME'] = $arrayRoleData[$this->getFieldNameByFormatFieldName('ROL_NAME')];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($arrayData["ROL_STATUS"])) {
|
if (isset($arrayData['ROL_STATUS'])) {
|
||||||
$arrayData["ROL_STATUS"] = ($arrayData["ROL_STATUS"] == "ACTIVE")? 1 : 0;
|
$arrayData['ROL_STATUS'] = $arrayData['ROL_STATUS'] === 'ACTIVE' ? 1 : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
$result = $role->updateRole($arrayData);
|
$role->updateRole($arrayData);
|
||||||
|
|
||||||
$arrayData = $arrayDataBackup;
|
$arrayData = $arrayDataBackup;
|
||||||
|
|
||||||
@@ -382,7 +413,7 @@ class Role
|
|||||||
}
|
}
|
||||||
|
|
||||||
return $arrayData;
|
return $arrayData;
|
||||||
} catch (\Exception $e) {
|
} catch (Exception $e) {
|
||||||
throw $e;
|
throw $e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -392,23 +423,24 @@ class Role
|
|||||||
*
|
*
|
||||||
* @param string $roleUid Unique id of Role
|
* @param string $roleUid Unique id of Role
|
||||||
*
|
*
|
||||||
* return void
|
* @return void
|
||||||
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function delete($roleUid)
|
public function delete($roleUid)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$role = new \Roles();
|
$role = new ModelRoles();
|
||||||
|
|
||||||
//Verify data
|
//Verify data
|
||||||
$this->throwExceptionIfNotExistsRole($roleUid, $this->arrayFieldNameForException["roleUid"]);
|
$this->throwExceptionIfNotExistsRole($roleUid, $this->arrayFieldNameForException["roleUid"]);
|
||||||
|
|
||||||
if ($role->numUsersWithRole($roleUid) > 0) {
|
if ($role->numUsersWithRole($roleUid) > 0) {
|
||||||
throw new \Exception(\G::LoadTranslation("ID_ROLES_CAN_NOT_DELETE"));
|
throw new Exception(G::LoadTranslation("ID_ROLES_CAN_NOT_DELETE"));
|
||||||
}
|
}
|
||||||
|
|
||||||
//Delete
|
//Delete
|
||||||
$result = $role->removeRole($roleUid);
|
$result = $role->removeRole($roleUid);
|
||||||
} catch (\Exception $e) {
|
} catch (Exception $e) {
|
||||||
throw $e;
|
throw $e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -416,25 +448,26 @@ class Role
|
|||||||
/**
|
/**
|
||||||
* Get criteria for Role
|
* Get criteria for Role
|
||||||
*
|
*
|
||||||
* return object
|
* @return object
|
||||||
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function getRoleCriteria()
|
public function getRoleCriteria()
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$criteria = new \Criteria("rbac");
|
$criteria = new Criteria("rbac");
|
||||||
|
|
||||||
$criteria->addSelectColumn(\RolesPeer::ROL_UID);
|
$criteria->addSelectColumn(RolesPeer::ROL_UID);
|
||||||
$criteria->addSelectColumn(\RolesPeer::ROL_PARENT);
|
$criteria->addSelectColumn(RolesPeer::ROL_PARENT);
|
||||||
$criteria->addSelectColumn(\RolesPeer::ROL_CODE);
|
$criteria->addSelectColumn(RolesPeer::ROL_CODE);
|
||||||
$criteria->addSelectColumn(\RolesPeer::ROL_STATUS);
|
$criteria->addSelectColumn(RolesPeer::ROL_STATUS);
|
||||||
$criteria->addSelectColumn(\RolesPeer::ROL_SYSTEM);
|
$criteria->addSelectColumn(RolesPeer::ROL_SYSTEM);
|
||||||
$criteria->addSelectColumn(\RolesPeer::ROL_CREATE_DATE);
|
$criteria->addSelectColumn(RolesPeer::ROL_CREATE_DATE);
|
||||||
$criteria->addSelectColumn(\RolesPeer::ROL_UPDATE_DATE);
|
$criteria->addSelectColumn(RolesPeer::ROL_UPDATE_DATE);
|
||||||
|
|
||||||
$criteria->add(\RolesPeer::ROL_SYSTEM, "00000000000000000000000000000002", \Criteria::EQUAL); //PROCESSMAKER
|
$criteria->add(RolesPeer::ROL_SYSTEM, self::SYSTEM_PROCESSMAKER, Criteria::EQUAL); //PROCESSMAKER
|
||||||
|
|
||||||
return $criteria;
|
return $criteria;
|
||||||
} catch (\Exception $e) {
|
} catch (Exception $e) {
|
||||||
throw $e;
|
throw $e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -444,35 +477,36 @@ class Role
|
|||||||
*
|
*
|
||||||
* @param array $record Record
|
* @param array $record Record
|
||||||
*
|
*
|
||||||
* return array Return an array with data Role
|
* @return array Return an array with data Role
|
||||||
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function getRoleDataFromRecord(array $record)
|
public function getRoleDataFromRecord(array $record)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$conf = new \Configurations();
|
$conf = new Configurations();
|
||||||
$confEnvSetting = $conf->getFormats();
|
$confEnvSetting = $conf->getFormats();
|
||||||
|
|
||||||
$dateTime = new \DateTime($record["ROL_CREATE_DATE"]);
|
$dateTime = new DateTime($record['ROL_CREATE_DATE']);
|
||||||
$roleCreateDate = $dateTime->format($confEnvSetting["dateFormat"]);
|
$roleCreateDate = $dateTime->format($confEnvSetting['dateFormat']);
|
||||||
|
|
||||||
$roleUpdateDate = "";
|
$roleUpdateDate = '';
|
||||||
|
|
||||||
if (!empty($record["ROL_UPDATE_DATE"])) {
|
if (!empty($record['ROL_UPDATE_DATE'])) {
|
||||||
$dateTime = new \DateTime($record["ROL_UPDATE_DATE"]);
|
$dateTime = new DateTime($record['ROL_UPDATE_DATE']);
|
||||||
$roleUpdateDate = $dateTime->format($confEnvSetting["dateFormat"]);
|
$roleUpdateDate = $dateTime->format($confEnvSetting['dateFormat']);
|
||||||
}
|
}
|
||||||
|
|
||||||
return array(
|
return [
|
||||||
$this->getFieldNameByFormatFieldName("ROL_UID") => $record["ROL_UID"],
|
$this->getFieldNameByFormatFieldName('ROL_UID') => $record['ROL_UID'],
|
||||||
$this->getFieldNameByFormatFieldName("ROL_CODE") => $record["ROL_CODE"],
|
$this->getFieldNameByFormatFieldName('ROL_CODE') => $record['ROL_CODE'],
|
||||||
$this->getFieldNameByFormatFieldName("ROL_NAME") => $record["ROL_NAME"],
|
$this->getFieldNameByFormatFieldName('ROL_NAME') => $record['ROL_NAME'],
|
||||||
$this->getFieldNameByFormatFieldName("ROL_STATUS") => ($record["ROL_STATUS"] . "" == "1")? "ACTIVE" : "INACTIVE",
|
$this->getFieldNameByFormatFieldName('ROL_STATUS') => $record['ROL_STATUS'] . '' === '1' ? 'ACTIVE' : 'INACTIVE',
|
||||||
$this->getFieldNameByFormatFieldName("ROL_SYSTEM") => $record["ROL_SYSTEM"],
|
$this->getFieldNameByFormatFieldName('ROL_SYSTEM') => $record['ROL_SYSTEM'],
|
||||||
$this->getFieldNameByFormatFieldName("ROL_CREATE_DATE") => $roleCreateDate,
|
$this->getFieldNameByFormatFieldName('ROL_CREATE_DATE') => $roleCreateDate,
|
||||||
$this->getFieldNameByFormatFieldName("ROL_UPDATE_DATE") => $roleUpdateDate,
|
$this->getFieldNameByFormatFieldName('ROL_UPDATE_DATE') => $roleUpdateDate,
|
||||||
$this->getFieldNameByFormatFieldName("ROL_TOTAL_USERS") => (int)($record["ROL_TOTAL_USERS"])
|
$this->getFieldNameByFormatFieldName('ROL_TOTAL_USERS') => (int)$record['ROL_TOTAL_USERS']
|
||||||
);
|
];
|
||||||
} catch (\Exception $e) {
|
} catch (Exception $e) {
|
||||||
throw $e;
|
throw $e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -480,23 +514,24 @@ class Role
|
|||||||
/**
|
/**
|
||||||
* Get all Roles
|
* Get all Roles
|
||||||
*
|
*
|
||||||
* @param array $arrayFilterData Data of the filters
|
* @param array $arrayFilterData Data of the filters
|
||||||
* @param string $sortField Field name to sort
|
* @param string $sortField Field name to sort
|
||||||
* @param string $sortDir Direction of sorting (ASC, DESC)
|
* @param string $sortDir Direction of sorting (ASC, DESC)
|
||||||
* @param int $start Start
|
* @param int $start Start
|
||||||
* @param int $limit Limit
|
* @param int $limit Limit
|
||||||
*
|
*
|
||||||
* return array Return an array with all Roles
|
* @return array Return an array with all Roles
|
||||||
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function getRoles(array $arrayFilterData = null, $sortField = null, $sortDir = null, $start = null, $limit = null)
|
public function getRoles(array $arrayFilterData = null, $sortField = null, $sortDir = null, $start = null, $limit = null)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$arrayRole = array();
|
$arrayRole = [];
|
||||||
|
|
||||||
//Verify data
|
//Verify data
|
||||||
$process = new \ProcessMaker\BusinessModel\Process();
|
$process = new Process();
|
||||||
|
|
||||||
$process->throwExceptionIfDataNotMetPagerVarDefinition(array("start" => $start, "limit" => $limit), $this->arrayFieldNameForException);
|
$process->throwExceptionIfDataNotMetPagerVarDefinition(["start" => $start, "limit" => $limit], $this->arrayFieldNameForException);
|
||||||
|
|
||||||
//Get data
|
//Get data
|
||||||
if (!is_null($limit) && $limit . "" == "0") {
|
if (!is_null($limit) && $limit . "" == "0") {
|
||||||
@@ -504,31 +539,31 @@ class Role
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Set variables
|
//Set variables
|
||||||
$content = new \Content();
|
$content = new Content();
|
||||||
$role = new \Roles();
|
$role = new ModelRoles();
|
||||||
|
|
||||||
$arrayContentByRole = $content->getAllContentsByRole();
|
$arrayContentByRole = $content->getAllContentsByRole();
|
||||||
|
|
||||||
//SQL
|
//SQL
|
||||||
$criteria = $this->getRoleCriteria();
|
$criteria = $this->getRoleCriteria();
|
||||||
|
|
||||||
$criteria->addAsColumn("ROL_TOTAL_USERS", "(SELECT COUNT(" . \UsersRolesPeer::ROL_UID . ") FROM " . \UsersRolesPeer::TABLE_NAME . " WHERE " . \UsersRolesPeer::ROL_UID . " = " . \RolesPeer::ROL_UID . ")");
|
$criteria->addAsColumn("ROL_TOTAL_USERS", "(SELECT COUNT(" . UsersRolesPeer::ROL_UID . ") FROM " . UsersRolesPeer::TABLE_NAME . " WHERE " . UsersRolesPeer::ROL_UID . " = " . RolesPeer::ROL_UID . ")");
|
||||||
|
|
||||||
if (!is_null($arrayFilterData) && is_array($arrayFilterData) && isset($arrayFilterData["filter"]) && trim($arrayFilterData["filter"]) != "") {
|
if (!is_null($arrayFilterData) && is_array($arrayFilterData) && isset($arrayFilterData["filter"]) && trim($arrayFilterData["filter"]) != "") {
|
||||||
$criteria->add(\RolesPeer::ROL_CODE, "%" . $arrayFilterData["filter"] . "%", \Criteria::LIKE);
|
$criteria->add(RolesPeer::ROL_CODE, "%" . $arrayFilterData["filter"] . "%", Criteria::LIKE);
|
||||||
}
|
}
|
||||||
|
|
||||||
//SQL
|
//SQL
|
||||||
if (!is_null($sortField) && trim($sortField) != "") {
|
if (!is_null($sortField) && trim($sortField) != "") {
|
||||||
$sortField = strtoupper($sortField);
|
$sortField = strtoupper($sortField);
|
||||||
|
|
||||||
if (in_array($sortField, array("ROL_UID", "ROL_PARENT", "ROL_STATUS", "ROL_SYSTEM", "ROL_CREATE_DATE", "ROL_UPDATE_DATE"))) {
|
if (in_array($sortField, ["ROL_UID", "ROL_PARENT", "ROL_STATUS", "ROL_SYSTEM", "ROL_CREATE_DATE", "ROL_UPDATE_DATE"])) {
|
||||||
$sortField = \RolesPeer::TABLE_NAME . "." . $sortField;
|
$sortField = RolesPeer::TABLE_NAME . "." . $sortField;
|
||||||
} else {
|
} else {
|
||||||
$sortField = \RolesPeer::ROL_CODE;
|
$sortField = RolesPeer::ROL_CODE;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$sortField = \RolesPeer::ROL_CODE;
|
$sortField = RolesPeer::ROL_CODE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!is_null($sortDir) && trim($sortDir) != "" && strtoupper($sortDir) == "DESC") {
|
if (!is_null($sortDir) && trim($sortDir) != "" && strtoupper($sortDir) == "DESC") {
|
||||||
@@ -545,8 +580,8 @@ class Role
|
|||||||
$criteria->setLimit((int)($limit));
|
$criteria->setLimit((int)($limit));
|
||||||
}
|
}
|
||||||
|
|
||||||
$rsCriteria = \RolesPeer::doSelectRS($criteria);
|
$rsCriteria = RolesPeer::doSelectRS($criteria);
|
||||||
$rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
|
$rsCriteria->setFetchmode(ResultSet::FETCHMODE_ASSOC);
|
||||||
|
|
||||||
while ($rsCriteria->next()) {
|
while ($rsCriteria->next()) {
|
||||||
$row = $rsCriteria->getRow();
|
$row = $rsCriteria->getRow();
|
||||||
@@ -567,7 +602,7 @@ class Role
|
|||||||
|
|
||||||
//Return
|
//Return
|
||||||
return $arrayRole;
|
return $arrayRole;
|
||||||
} catch (\Exception $e) {
|
} catch (Exception $e) {
|
||||||
throw $e;
|
throw $e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -575,10 +610,11 @@ class Role
|
|||||||
/**
|
/**
|
||||||
* Get data of a Role
|
* Get data of a Role
|
||||||
*
|
*
|
||||||
* @param string $roleUid Unique id of Role
|
* @param string $roleUid Unique id of Role
|
||||||
* @param bool $flagGetRecord Value that set the getting
|
* @param bool $flagGetRecord Value that set the getting
|
||||||
*
|
*
|
||||||
* return array Return an array with data of a Role
|
* @return array Return an array with data of a Role
|
||||||
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function getRole($roleUid, $flagGetRecord = false)
|
public function getRole($roleUid, $flagGetRecord = false)
|
||||||
{
|
{
|
||||||
@@ -588,8 +624,8 @@ class Role
|
|||||||
|
|
||||||
//Set variables
|
//Set variables
|
||||||
if (!$flagGetRecord) {
|
if (!$flagGetRecord) {
|
||||||
$content = new \Content();
|
$content = new Content();
|
||||||
$role = new \Roles();
|
$role = new ModelRoles();
|
||||||
|
|
||||||
$arrayContentByRole = $content->getAllContentsByRole();
|
$arrayContentByRole = $content->getAllContentsByRole();
|
||||||
}
|
}
|
||||||
@@ -599,13 +635,13 @@ class Role
|
|||||||
$criteria = $this->getRoleCriteria();
|
$criteria = $this->getRoleCriteria();
|
||||||
|
|
||||||
if (!$flagGetRecord) {
|
if (!$flagGetRecord) {
|
||||||
$criteria->addAsColumn("ROL_TOTAL_USERS", "(SELECT COUNT(" . \UsersRolesPeer::ROL_UID . ") FROM " . \UsersRolesPeer::TABLE_NAME . " WHERE " . \UsersRolesPeer::ROL_UID . " = " . \RolesPeer::ROL_UID . ")");
|
$criteria->addAsColumn("ROL_TOTAL_USERS", "(SELECT COUNT(" . UsersRolesPeer::ROL_UID . ") FROM " . UsersRolesPeer::TABLE_NAME . " WHERE " . UsersRolesPeer::ROL_UID . " = " . RolesPeer::ROL_UID . ")");
|
||||||
}
|
}
|
||||||
|
|
||||||
$criteria->add(\RolesPeer::ROL_UID, $roleUid, \Criteria::EQUAL);
|
$criteria->add(RolesPeer::ROL_UID, $roleUid, Criteria::EQUAL);
|
||||||
|
|
||||||
$rsCriteria = \RolesPeer::doSelectRS($criteria);
|
$rsCriteria = RolesPeer::doSelectRS($criteria);
|
||||||
$rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
|
$rsCriteria->setFetchmode(ResultSet::FETCHMODE_ASSOC);
|
||||||
|
|
||||||
$rsCriteria->next();
|
$rsCriteria->next();
|
||||||
|
|
||||||
@@ -623,8 +659,8 @@ class Role
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Return
|
//Return
|
||||||
return (!$flagGetRecord)? $this->getRoleDataFromRecord($row) : $row;
|
return (!$flagGetRecord) ? $this->getRoleDataFromRecord($row) : $row;
|
||||||
} catch (\Exception $e) {
|
} catch (Exception $e) {
|
||||||
throw $e;
|
throw $e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,14 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace ProcessMaker\Services\Api;
|
namespace ProcessMaker\Services\Api;
|
||||||
|
|
||||||
use \ProcessMaker\Services\Api;
|
use Exception;
|
||||||
use \Luracast\Restler\RestException;
|
use G;
|
||||||
|
use Luracast\Restler\RestException;
|
||||||
|
use ProcessMaker\BusinessModel\Role as BmRole;
|
||||||
|
use ProcessMaker\BusinessModel\User;
|
||||||
|
use ProcessMaker\Services\Api;
|
||||||
|
use ProcessMaker\Util\DateTime;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Role Api Controller
|
* Role Api Controller
|
||||||
@@ -14,86 +20,102 @@ class Role extends Api
|
|||||||
private $role;
|
private $role;
|
||||||
|
|
||||||
private $arrayFieldIso8601 = [
|
private $arrayFieldIso8601 = [
|
||||||
"rol_create_date",
|
'rol_create_date',
|
||||||
"rol_update_date"
|
'rol_update_date'
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor of the class
|
* Role constructor.
|
||||||
*
|
*
|
||||||
* return void
|
* @throws RestException
|
||||||
*/
|
*/
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$user = new \ProcessMaker\BusinessModel\User();
|
$user = new User();
|
||||||
|
|
||||||
$usrUid = $this->getUserId();
|
$usrUid = $this->getUserId();
|
||||||
|
|
||||||
if (!$user->checkPermission($usrUid, "PM_USERS")) {
|
if (!$user->checkPermission($usrUid, 'PM_USERS')) {
|
||||||
throw new \Exception(\G::LoadTranslation("ID_USER_NOT_HAVE_PERMISSION", array($usrUid)));
|
throw new Exception(G::LoadTranslation('ID_USER_NOT_HAVE_PERMISSION', [$usrUid]));
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->role = new \ProcessMaker\BusinessModel\Role();
|
$this->role = new BmRole();
|
||||||
|
|
||||||
$this->role->setFormatFieldNameInUppercase(false);
|
$this->role->setFormatFieldNameInUppercase(false);
|
||||||
} catch (\Exception $e) {
|
} catch (Exception $e) {
|
||||||
throw new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage());
|
throw new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Load all roles
|
||||||
|
*
|
||||||
|
* @url GET
|
||||||
|
*
|
||||||
|
* @param string $filter
|
||||||
|
* @param int $start
|
||||||
|
* @param int $limit
|
||||||
|
*
|
||||||
|
* @return mixed
|
||||||
|
* @throws RestException
|
||||||
|
*
|
||||||
* @access protected
|
* @access protected
|
||||||
* @class AccessControl {@permission PM_USERS}
|
* @class AccessControl {@permission PM_USERS}
|
||||||
* @url GET
|
|
||||||
*/
|
*/
|
||||||
public function index($filter = null, $start = null, $limit = null)
|
public function index($filter = null, $start = null, $limit = null)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$response = $this->role->getRoles(array("filter" => $filter), null, null, $start, $limit);
|
$response = $this->role->getRoles(['filter' => $filter], null, null, $start, $limit);
|
||||||
|
|
||||||
return \ProcessMaker\Util\DateTime::convertUtcToIso8601($response, $this->arrayFieldIso8601);
|
return DateTime::convertUtcToIso8601($response, $this->arrayFieldIso8601);
|
||||||
} catch (\Exception $e) {
|
} catch (Exception $e) {
|
||||||
throw new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage());
|
throw new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @access protected
|
* load information role
|
||||||
* @class AccessControl {@permission PM_USERS}
|
*
|
||||||
* @url GET /:rol_uid
|
* @url GET /:rol_uid
|
||||||
*
|
*
|
||||||
* @param string $rol_uid {@min 32}{@max 32}
|
* @param string $rol_uid {@min 32}{@max 32}
|
||||||
|
*
|
||||||
|
* @return mixed
|
||||||
|
* @throws RestException
|
||||||
|
*
|
||||||
|
* @access protected
|
||||||
|
* @class AccessControl {@permission PM_USERS}
|
||||||
*/
|
*/
|
||||||
public function doGet($rol_uid)
|
public function doGet($rol_uid)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$response = $this->role->getRole($rol_uid);
|
$response = $this->role->getRole($rol_uid);
|
||||||
|
|
||||||
return \ProcessMaker\Util\DateTime::convertUtcToIso8601($response, $this->arrayFieldIso8601);
|
return DateTime::convertUtcToIso8601($response, $this->arrayFieldIso8601);
|
||||||
} catch (\Exception $e) {
|
} catch (Exception $e) {
|
||||||
throw new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage());
|
throw new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @access protected
|
* Create rol
|
||||||
* @class AccessControl {@permission PM_USERS}
|
*
|
||||||
* @url POST
|
* @url POST
|
||||||
|
* @status 201
|
||||||
*
|
*
|
||||||
* @param array $request_data
|
* @param array $request_data
|
||||||
*
|
*
|
||||||
* @status 201
|
* @return array
|
||||||
|
* @throws RestException
|
||||||
|
*
|
||||||
|
* @access protected
|
||||||
|
* @class AccessControl {@permission PM_USERS}
|
||||||
*/
|
*/
|
||||||
public function doPost(array $request_data)
|
public function doPost(array $request_data)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$arrayData = $this->role->create($request_data);
|
return $this->role->create($request_data);
|
||||||
|
} catch (Exception $e) {
|
||||||
$response = $arrayData;
|
|
||||||
|
|
||||||
return $response;
|
|
||||||
} catch (\Exception $e) {
|
|
||||||
throw new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage());
|
throw new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -103,8 +125,8 @@ class Role extends Api
|
|||||||
*
|
*
|
||||||
* @url PUT /:rol_uid
|
* @url PUT /:rol_uid
|
||||||
*
|
*
|
||||||
* @param string $rol_uid {@min 32}{@max 32}
|
* @param string $rol_uid {@min 32}{@max 32}
|
||||||
* @param array $request_data
|
* @param array $request_data
|
||||||
*
|
*
|
||||||
* @throws RestException
|
* @throws RestException
|
||||||
*
|
*
|
||||||
@@ -114,24 +136,29 @@ class Role extends Api
|
|||||||
public function doPut($rol_uid, array $request_data)
|
public function doPut($rol_uid, array $request_data)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$arrayData = $this->role->update($rol_uid, $request_data);
|
$this->role->update($rol_uid, $request_data);
|
||||||
} catch (\Exception $e) {
|
} catch (Exception $e) {
|
||||||
throw new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage());
|
throw new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @access protected
|
* Delete role
|
||||||
* @class AccessControl {@permission PM_USERS}
|
*
|
||||||
* @url DELETE /:rol_uid
|
* @url DELETE /:rol_uid
|
||||||
*
|
*
|
||||||
* @param string $rol_uid {@min 32}{@max 32}
|
* @param string $rol_uid {@min 32}{@max 32}
|
||||||
|
*
|
||||||
|
* @throws RestException
|
||||||
|
*
|
||||||
|
* @access protected
|
||||||
|
* @class AccessControl {@permission PM_USERS}
|
||||||
*/
|
*/
|
||||||
public function doDelete($rol_uid)
|
public function doDelete($rol_uid)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$this->role->delete($rol_uid);
|
$this->role->delete($rol_uid);
|
||||||
} catch (\Exception $e) {
|
} catch (Exception $e) {
|
||||||
throw new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage());
|
throw new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -635,8 +635,11 @@ DoSearch = function(){
|
|||||||
};
|
};
|
||||||
|
|
||||||
//Render Date Function
|
//Render Date Function
|
||||||
render_date = function(v){
|
render_date = function(date){
|
||||||
return _DF(v);
|
if (date != null) {
|
||||||
|
return _DF(date);
|
||||||
|
}
|
||||||
|
return date;
|
||||||
};
|
};
|
||||||
|
|
||||||
//Update Page Size Configuration
|
//Update Page Size Configuration
|
||||||
|
|||||||
Reference in New Issue
Block a user