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
File diff suppressed because it is too large
Load Diff
@@ -1,8 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace ProcessMaker\Services\Api;
|
||||
|
||||
use \ProcessMaker\Services\Api;
|
||||
use \Luracast\Restler\RestException;
|
||||
use Exception;
|
||||
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
|
||||
@@ -14,86 +20,102 @@ class Role extends Api
|
||||
private $role;
|
||||
|
||||
private $arrayFieldIso8601 = [
|
||||
"rol_create_date",
|
||||
"rol_update_date"
|
||||
'rol_create_date',
|
||||
'rol_update_date'
|
||||
];
|
||||
|
||||
/**
|
||||
* Constructor of the class
|
||||
* Role constructor.
|
||||
*
|
||||
* return void
|
||||
* @throws RestException
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
try {
|
||||
$user = new \ProcessMaker\BusinessModel\User();
|
||||
$user = new User();
|
||||
|
||||
$usrUid = $this->getUserId();
|
||||
|
||||
if (!$user->checkPermission($usrUid, "PM_USERS")) {
|
||||
throw new \Exception(\G::LoadTranslation("ID_USER_NOT_HAVE_PERMISSION", array($usrUid)));
|
||||
if (!$user->checkPermission($usrUid, 'PM_USERS')) {
|
||||
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);
|
||||
} catch (\Exception $e) {
|
||||
} catch (Exception $e) {
|
||||
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
|
||||
* @class AccessControl {@permission PM_USERS}
|
||||
* @url GET
|
||||
*/
|
||||
public function index($filter = null, $start = null, $limit = null)
|
||||
{
|
||||
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);
|
||||
} catch (\Exception $e) {
|
||||
return DateTime::convertUtcToIso8601($response, $this->arrayFieldIso8601);
|
||||
} catch (Exception $e) {
|
||||
throw new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @access protected
|
||||
* @class AccessControl {@permission PM_USERS}
|
||||
* load information role
|
||||
*
|
||||
* @url GET /:rol_uid
|
||||
*
|
||||
* @param string $rol_uid {@min 32}{@max 32}
|
||||
*
|
||||
* @return mixed
|
||||
* @throws RestException
|
||||
*
|
||||
* @access protected
|
||||
* @class AccessControl {@permission PM_USERS}
|
||||
*/
|
||||
public function doGet($rol_uid)
|
||||
{
|
||||
try {
|
||||
$response = $this->role->getRole($rol_uid);
|
||||
|
||||
return \ProcessMaker\Util\DateTime::convertUtcToIso8601($response, $this->arrayFieldIso8601);
|
||||
} catch (\Exception $e) {
|
||||
return DateTime::convertUtcToIso8601($response, $this->arrayFieldIso8601);
|
||||
} catch (Exception $e) {
|
||||
throw new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @access protected
|
||||
* @class AccessControl {@permission PM_USERS}
|
||||
* Create rol
|
||||
*
|
||||
* @url POST
|
||||
* @status 201
|
||||
*
|
||||
* @param array $request_data
|
||||
*
|
||||
* @status 201
|
||||
* @return array
|
||||
* @throws RestException
|
||||
*
|
||||
* @access protected
|
||||
* @class AccessControl {@permission PM_USERS}
|
||||
*/
|
||||
public function doPost(array $request_data)
|
||||
{
|
||||
try {
|
||||
$arrayData = $this->role->create($request_data);
|
||||
|
||||
$response = $arrayData;
|
||||
|
||||
return $response;
|
||||
} catch (\Exception $e) {
|
||||
return $this->role->create($request_data);
|
||||
} catch (Exception $e) {
|
||||
throw new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage());
|
||||
}
|
||||
}
|
||||
@@ -103,8 +125,8 @@ class Role extends Api
|
||||
*
|
||||
* @url PUT /:rol_uid
|
||||
*
|
||||
* @param string $rol_uid {@min 32}{@max 32}
|
||||
* @param array $request_data
|
||||
* @param string $rol_uid {@min 32}{@max 32}
|
||||
* @param array $request_data
|
||||
*
|
||||
* @throws RestException
|
||||
*
|
||||
@@ -114,24 +136,29 @@ class Role extends Api
|
||||
public function doPut($rol_uid, array $request_data)
|
||||
{
|
||||
try {
|
||||
$arrayData = $this->role->update($rol_uid, $request_data);
|
||||
} catch (\Exception $e) {
|
||||
$this->role->update($rol_uid, $request_data);
|
||||
} catch (Exception $e) {
|
||||
throw new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @access protected
|
||||
* @class AccessControl {@permission PM_USERS}
|
||||
* Delete role
|
||||
*
|
||||
* @url DELETE /:rol_uid
|
||||
*
|
||||
* @param string $rol_uid {@min 32}{@max 32}
|
||||
*
|
||||
* @throws RestException
|
||||
*
|
||||
* @access protected
|
||||
* @class AccessControl {@permission PM_USERS}
|
||||
*/
|
||||
public function doDelete($rol_uid)
|
||||
{
|
||||
try {
|
||||
$this->role->delete($rol_uid);
|
||||
} catch (\Exception $e) {
|
||||
} catch (Exception $e) {
|
||||
throw new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -635,8 +635,11 @@ DoSearch = function(){
|
||||
};
|
||||
|
||||
//Render Date Function
|
||||
render_date = function(v){
|
||||
return _DF(v);
|
||||
render_date = function(date){
|
||||
if (date != null) {
|
||||
return _DF(date);
|
||||
}
|
||||
return date;
|
||||
};
|
||||
|
||||
//Update Page Size Configuration
|
||||
|
||||
Reference in New Issue
Block a user