move permissions from abstract to concrete Notiz Controller

This commit is contained in:
Harald Bamberger
2024-08-13 14:12:55 +02:00
parent 4fc61c342c
commit 5d169e188a
3 changed files with 100 additions and 12 deletions
@@ -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'],
]);
}
@@ -0,0 +1,69 @@
<?php
/**
* Copyright (C) 2024 fhcomplete.org
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
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);
}
}
+23 -12
View File
@@ -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');