- No permission type is needed anymore in controllers CallerLibrary and CallerModel

- No permission type is anymore given as parameter to library CallerLib
- Removed method checkLibraryPermission from library CallerLib
- Adapted code in library CallerLib
This commit is contained in:
Paolo
2018-03-29 11:52:41 +02:00
parent e8bf6ad747
commit 0906f5bc85
3 changed files with 17 additions and 60 deletions
@@ -33,7 +33,7 @@ class CallerLibrary extends APIv1_Controller
public function getCall()
{
// Start me up!
$result = $this->callerlib->callLibrary($this->get(), PermissionLib::SELECT_RIGHT);
$result = $this->callerlib->callLibrary($this->get());
// Print the result
$this->response($result, REST_Controller::HTTP_OK);
@@ -45,7 +45,7 @@ class CallerLibrary extends APIv1_Controller
public function postCall()
{
// Start me up!
$result = $this->callerlib->callLibrary($this->post(), PermissionLib::UPDATE_RIGHT);
$result = $this->callerlib->callLibrary($this->post());
// Print the result
$this->response($result, REST_Controller::HTTP_OK);
@@ -57,7 +57,7 @@ class CallerLibrary extends APIv1_Controller
public function putCall()
{
// Start me up!
$result = $this->callerlib->callLibrary($this->put(), PermissionLib::INSERT_RIGHT);
$result = $this->callerlib->callLibrary($this->put());
// Print the result
$this->response($result, REST_Controller::HTTP_OK);
@@ -69,7 +69,7 @@ class CallerLibrary extends APIv1_Controller
public function deleteCall()
{
// Start me up!
$result = $this->callerlib->callLibrary($this->delete(), PermissionLib::DELETE_RIGHT);
$result = $this->callerlib->callLibrary($this->delete());
// Print the result
$this->response($result, REST_Controller::HTTP_OK);
@@ -33,7 +33,7 @@ class CallerModel extends APIv1_Controller
public function getCall()
{
// Start me up!
$result = $this->callerlib->callModel($this->get(), PermissionLib::SELECT_RIGHT);
$result = $this->callerlib->callModel($this->get());
// Print the result
$this->response($result, REST_Controller::HTTP_OK);
@@ -45,7 +45,7 @@ class CallerModel extends APIv1_Controller
public function postCall()
{
// Start me up!
$result = $this->callerlib->callModel($this->post(), PermissionLib::UPDATE_RIGHT);
$result = $this->callerlib->callModel($this->post());
// Print the result
$this->response($result, REST_Controller::HTTP_OK);
@@ -57,7 +57,7 @@ class CallerModel extends APIv1_Controller
public function putCall()
{
// Start me up!
$result = $this->callerlib->callModel($this->put(), PermissionLib::INSERT_RIGHT);
$result = $this->callerlib->callModel($this->put());
// Print the result
$this->response($result, REST_Controller::HTTP_OK);
@@ -69,7 +69,7 @@ class CallerModel extends APIv1_Controller
public function deleteCall()
{
// Start me up!
$result = $this->callerlib->callModel($this->delete(), PermissionLib::DELETE_RIGHT);
$result = $this->callerlib->callModel($this->delete());
// Print the result
$this->response($result, REST_Controller::HTTP_OK);
+9 -52
View File
@@ -43,23 +43,23 @@ class CallerLib
/**
* Wrapper method for _call
*/
public function callLibrary($callParameters, $permissionType)
public function callLibrary($callParameters)
{
return $this->_call($callParameters, $permissionType);
return $this->_call($callParameters);
}
/**
* Wrapper method for _call
*/
public function callModel($callParameters, $permissionType)
public function callModel($callParameters)
{
return $this->_call($callParameters, $permissionType);
return $this->_call($callParameters);
}
/**
* Everything starts here...
*/
private function _call($callParameters, $permissionType)
private function _call($callParameters)
{
$result = null;
$parameters = $this->_getParameters($callParameters);
@@ -87,26 +87,11 @@ class CallerLib
// If not loaded then load it
if ($isLoaded === false)
{
// Checks if the operation is permitted by the API caller
// Only for libraries, permissions are automatically handled by models
$result = $this->checkLibraryPermission(
$parameters->resourcePath,
$parameters->resourceName,
$parameters->function,
$permissionType
);
if (isError($result))
// Try to load the library
$result = $this->_loadLibrary($parameters->resourcePath, $parameters->resourceName);
if (isSuccess($result))
{
$loaded = null;
}
else
{
// Try to load the library
$result = $this->_loadLibrary($parameters->resourcePath, $parameters->resourceName);
if (isSuccess($result))
{
$loaded = $result->retval;
}
$loaded = $result->retval;
}
}
// If it is already loaded $isLoaded contains the instance of the library
@@ -244,34 +229,6 @@ class CallerLib
return $result;
}
/**
* Search for a valid permission for this library that should be present with this format:
* '<library path>.<library name>.<library method name>' => '<permission>'
*/
private function checkLibraryPermission($resourcePath, $resourceName, $function, $permissionType)
{
$result = null;
$permissionPath = '';
if ($resourcePath != '')
{
$permissionPath = $resourcePath;
}
$permissionPath .= $resourceName.'.'.$function;
if ($this->ci->permissionlib->isEntitled($permissionPath, $permissionType) === false)
{
$result = error(FHC_NORIGHT, FHC_NORIGHT);
}
else
{
$result = success('Has permission');
}
return $result;
}
/**
* Loads a library using the given path and name
*