mirror of
https://github.com/FH-Complete/FHC-Core.git
synced 2026-07-20 00:12:15 +00:00
- Moved _checkPermissions from FHC_Controller to PermissionLib (now is public and it's renamed checkPermissions)
- Added include of PermissionLib in APIv1_Controller - Added method _isAllowed to APIv1_Controller to call checkPermissions from PermissionLib - Now the APIv1_Controller constructor requires an array of permissions as parameter
This commit is contained in:
@@ -7,13 +7,31 @@ class APIv1_Controller extends REST_Controller
|
||||
/**
|
||||
* Standard constructor for all the RESTful resources
|
||||
*/
|
||||
public function __construct()
|
||||
public function __construct($requiredPermissions)
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
|
||||
// Loads return messages
|
||||
$this->load->helper('message');
|
||||
|
||||
|
||||
// Loads permission lib
|
||||
$this->load->library('PermissionLib');
|
||||
|
||||
log_message('debug', 'Called API: '.$_SERVER['PHP_SELF'].'?'.$_SERVER['QUERY_STRING']);
|
||||
|
||||
$this->_isAllowed($requiredPermissions);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the caller is allowed to access to this content with the given permissions
|
||||
* If it is not allowed will set the HTTP header with code 401
|
||||
* Wrapper for _checkPermissions
|
||||
*/
|
||||
private function _isAllowed($requiredPermissions)
|
||||
{
|
||||
if (!$this->permissionlib->checkPermissions($requiredPermissions, $this->router->method))
|
||||
{
|
||||
$this->response(error('You are not allowed to access to this content'), REST_Controller::HTTP_UNAUTHORIZED);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user