Merge branch 'master' into feature/Anrechnungen_NEU

This commit is contained in:
Andreas Österreicher
2021-08-26 11:32:47 +02:00
289 changed files with 4616 additions and 1523 deletions
+124
View File
@@ -0,0 +1,124 @@
<?php
if (!defined('BASEPATH')) exit('No direct script access allowed');
/**
* Extends the RESTFul_Controller and performs authentication
*/
abstract class API_Controller extends RESTFul_Controller
{
private $_requiredPermissions;
/**
* Standard constructor for all the RESTful resources
*/
public function __construct($requiredPermissions)
{
parent::__construct();
$this->_requiredPermissions = $requiredPermissions;
// Loads LogLib with different debug trace levels to get data of the job that extends this class
// It also specify parameters to set database fields
$this->load->library('LogLib', array(
'classIndex' => 5,
'functionIndex' => 5,
'lineIndex' => 4,
'dbLogType' => 'API', // required
'dbExecuteUser' => 'RESTful API'
));
}
/**
* This method is automatically called by CodeIgniter after the execution of the constructor is completed
* - Cheks if the Authlib was loaded, if not it means that the authentication failed
* - Loads the permsission lib and calls permissionlib->isEntitled
* - 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
* - Calls the parent (REST_Controller) _remap method to performs other checks
* NOTE: this methods override the parent method!!!
*/
public function _remap($object_called, $arguments = [])
{
if (isset($this->authlib)) // if set then the authentication is ok
{
// Loads permission lib
$this->load->library('PermissionLib');
// Cheks if the user has the permission to call a method
if (!$this->permissionlib->isEntitled($this->_requiredPermissions, $this->router->method))
{
// If not...
$this->response(error('You are not allowed to access to this content'), REST_Controller::HTTP_UNAUTHORIZED);
}
}
// Finally calls the parent _remap to perform other checks
parent::_remap($object_called, $arguments);
}
//------------------------------------------------------------------------------------------------------------------
// Protected methods
/**
* Writes a REST call info log
*/
protected function logInfo($response, $parameters = null)
{
$this->_log(LogLib::INFO, 'RESTful API info', $response, $parameters);
}
/**
* Writes a REST call debug log
*/
protected function logDebug($response, $parameters = null)
{
$this->_log(LogLib::DEBUG, 'RESTful API debug', $response, $parameters);
}
/**
* Writes a REST call warning log
*/
protected function logWarning($response, $parameters = null)
{
$this->_log(LogLib::WARNING, 'RESTful API warning', $response, $parameters);
}
/**
* Writes a REST call error log
*/
protected function logError($response, $parameters = null)
{
$this->_log(LogLib::ERROR, 'RESTful API error', $response, $parameters);
}
//------------------------------------------------------------------------------------------------------------------
// Private methods
/**
* Writes a log to database
*/
private function _log($level, $requestId, $response, $parameters)
{
$data = new stdClass();
$data->response = $response;
if ($parameters != null) $data->parameters = $parameters;
switch($level)
{
case LogLib::INFO:
$this->loglib->logInfoDB($requestId, json_encode(success($data, LogLib::INFO)));
break;
case LogLib::DEBUG:
$this->loglib->logDebugDB($requestId, json_encode(success($data, LogLib::DEBUG)));
break;
case LogLib::WARNING:
$this->loglib->logWarningDB($requestId, json_encode(error($data, LogLib::WARNING)));
break;
case LogLib::ERROR:
$this->loglib->logErrorDB($requestId, json_encode(error($data, LogLib::ERROR)));
break;
}
}
}
-51
View File
@@ -1,51 +0,0 @@
<?php
if (!defined('BASEPATH')) exit('No direct script access allowed');
/**
*
*/
abstract class APIv1_Controller extends RESTFul_Controller
{
private $_requiredPermissions;
/**
* Standard constructor for all the RESTful resources
*/
public function __construct($requiredPermissions)
{
parent::__construct();
$this->_requiredPermissions = $requiredPermissions;
log_message('debug', 'Called API: '.$_SERVER['PHP_SELF'].'?'.$_SERVER['QUERY_STRING']);
}
/**
* This method is automatically called by CodeIgniter after the execution of the constructor is completed
* - Cheks if the Authlib was loaded, if not it means that the authentication failed
* - Loads the permsission lib and calls permissionlib->isEntitled
* - 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
* - Calls the parent (REST_Controller) _remap method to performs other checks
* NOTE: this methods override the parent method!!!
*/
public function _remap($object_called, $arguments = [])
{
if (isset($this->authlib)) // if set then the authentication is ok
{
// Loads permission lib
$this->load->library('PermissionLib');
// Cheks if the user has the permission to call a method
if (!$this->permissionlib->isEntitled($this->_requiredPermissions, $this->router->method))
{
// If not...
$this->response(error('You are not allowed to access to this content'), REST_Controller::HTTP_UNAUTHORIZED);
}
}
// Finally calls the parent _remap to perform other checks
parent::_remap($object_called, $arguments);
}
}
+12 -7
View File
@@ -49,10 +49,20 @@ abstract class JQW_Controller extends JOB_Controller
/**
* To get the oldest added job using the given job type
* NOTE: just a wrapper
*/
protected function getOldestJob($type)
{
$jobs = $this->jobsqueuelib->getOldestJob($type);
return $this->getOldestJobs($type, 1);
}
/**
* To get the oldest added jobs using the given job type
* It is eventually specify the maximum amount of jobs to be retrieved
*/
protected function getOldestJobs($type, $maxAmount)
{
$jobs = $this->jobsqueuelib->getOldestJobs($type, $maxAmount);
// If an error occurred then log it in database
if (isError($jobs)) $this->logError(getError($jobs), $type);
@@ -131,12 +141,7 @@ abstract class JQW_Controller extends JOB_Controller
*/
protected function generateJobs($status, $input)
{
$job = new stdClass();
$job->{JobsQueueLib::PROPERTY_STATUS} = $status;
$job->{JobsQueueLib::PROPERTY_INPUT} = $input;
return array($job);
return JobsQueueLib::generateJobs($status, $input);
}
}