From 5d169e188a082215538a8d624307c2d5359f97da Mon Sep 17 00:00:00 2001 From: Harald Bamberger Date: Tue, 13 Aug 2024 14:12:55 +0200 Subject: [PATCH] move permissions from abstract to concrete Notiz Controller --- .../api/frontend/v1/notiz/NotizPerson.php | 8 +++ .../core/Abstract_Searchbar_Controller.php | 69 +++++++++++++++++++ application/core/Notiz_Controller.php | 35 ++++++---- 3 files changed, 100 insertions(+), 12 deletions(-) create mode 100644 application/core/Abstract_Searchbar_Controller.php diff --git a/application/controllers/api/frontend/v1/notiz/NotizPerson.php b/application/controllers/api/frontend/v1/notiz/NotizPerson.php index 15445bd14..cb9d31024 100644 --- a/application/controllers/api/frontend/v1/notiz/NotizPerson.php +++ b/application/controllers/api/frontend/v1/notiz/NotizPerson.php @@ -9,6 +9,14 @@ class NotizPerson extends Notiz_Controller public function __construct() { parent::__construct([ + 'getUid' => ['admin:r', 'assistenz:r'], + 'getNotizen' => ['admin:r', 'assistenz:r'], + 'loadNotiz' => ['admin:r', 'assistenz:r'], + 'addNewNotiz' => ['admin:rw', 'assistenz:rw'], + 'updateNotiz' => ['admin:rw', 'assistenz:rw'], + 'deleteNotiz' => ['admin:rw', 'assistenz:rw'], + 'loadDokumente' => ['admin:r', 'assistenz:r'], + 'getMitarbeiter' => ['admin:r', 'assistenz:r'], 'isBerechtigt' => ['admin:r', 'assistenz:r'], ]); } diff --git a/application/core/Abstract_Searchbar_Controller.php b/application/core/Abstract_Searchbar_Controller.php new file mode 100644 index 000000000..8b383e042 --- /dev/null +++ b/application/core/Abstract_Searchbar_Controller.php @@ -0,0 +1,69 @@ +. + */ + +if (! defined('BASEPATH')) exit('No direct script access allowed'); + +/** + * This controller operates between (interface) the JS (GUI) and the SearchBarLib (back-end) + * Provides data to the ajax get calls about the searchbar component + * This controller works with JSON calls on the HTTP GET and the output is always JSON + */ +class Searchbar extends FHCAPI_Controller +{ + const SEARCHSTR_PARAM = 'searchstr'; + const TYPES_PARAM = 'types'; + + /** + * Object initialization + */ + public function __construct() + { + // NOTE(chris): additional permission checks will be done in SearchBarLib + parent::__construct([ + 'search' => self::PERM_LOGGED + ]); + + // Load the library SearchBarLib + $this->load->library('SearchBarLib'); + } + + //------------------------------------------------------------------------------------------------------------------ + // Public methods + + /** + * Gets a JSON body via HTTP POST and provides the parameters + */ + public function search() + { + $this->load->library('form_validation'); + + // Checks if the searchstr and the types parameters are in the POSTed JSON + $this->form_validation->set_rules(self::SEARCHSTR_PARAM, null, 'required'); + $this->form_validation->set_rules(self::TYPES_PARAM . '[]', null, 'required'); + + if (!$this->form_validation->run()) + $this->terminateWithError(SearchBarLib::ERROR_WRONG_JSON, self::ERROR_TYPE_GENERAL); + + // Convert to json the result from searchbarlib->search + $result = $this->searchbarlib->search($this->input->post(self::SEARCHSTR_PARAM), $this->input->post(self::TYPES_PARAM)); + if (property_exists($result, 'error')) + $this->terminateWithError(getError($result), self::ERROR_TYPE_GENERAL); + $this->terminateWithSuccess($result); + } +} + diff --git a/application/core/Notiz_Controller.php b/application/core/Notiz_Controller.php index 17bd28481..05f70ee85 100644 --- a/application/core/Notiz_Controller.php +++ b/application/core/Notiz_Controller.php @@ -6,20 +6,31 @@ use \DateTime as DateTime; abstract class Notiz_Controller extends FHCAPI_Controller { + const DEFAULT_PERMISSION_R = 'admin:r'; + const DEFAULT_PERMISSION_RW = 'admin:rw'; //public function __construct($zuordnung = 'person/Notizzuordnung_model') - public function __construct() + public function __construct($permissions) { - parent::__construct([ - 'getUid' => self::PERM_LOGGED, - 'getNotizen' => self::PERM_LOGGED, - 'loadNotiz' => self::PERM_LOGGED, - 'addNewNotiz' => self::PERM_LOGGED, - 'updateNotiz' => self::PERM_LOGGED, - 'deleteNotiz' => ['admin:w', 'assistenz:w'], - 'loadDokumente' => ['admin:w', 'assistenz:w'], - 'getMitarbeiter' => self::PERM_LOGGED, - 'isBerechtigt' => self::PERM_LOGGED, - ]); + $default_permissions = [ + 'getUid' => self::DEFAULT_PERMISSION_R, + 'getNotizen' => self::DEFAULT_PERMISSION_R, + 'loadNotiz' => self::DEFAULT_PERMISSION_R, + 'addNewNotiz' => self::DEFAULT_PERMISSION_RW, + 'updateNotiz' => self::DEFAULT_PERMISSION_RW, + 'deleteNotiz' => self::DEFAULT_PERMISSION_RW, + 'loadDokumente' => self::DEFAULT_PERMISSION_R, + 'getMitarbeiter' => self::DEFAULT_PERMISSION_R, + 'isBerechtigt' => self::DEFAULT_PERMISSION_R, + ]; + + if(!is_array($permissions)) + { + $this->terminateWithError("Notiz_controller construct: permissions must be an array"); + } + + $merged_permissions = array_merge($default_permissions, $permissions); + + parent::__construct($merged_permissions); //Load Models $this->load->model('person/Notiz_model', 'NotizModel');