From 49e24b0431daca44afa236b568eb4715285792de Mon Sep 17 00:00:00 2001 From: Paolo Date: Thu, 29 Mar 2018 16:53:38 +0200 Subject: [PATCH] - Controller system/Filters now extends CI_Controller - Added private method _isAllowed to controller system/Filters - The method _isAllowed is called in the controller constructor and checks if the caller has the permission to read data with this instance of the FilterWidget - The permission is given as parameter when calling the FilterWidget, the parameter is called requiredPermissions - Updated the view system/infocenter/infocenterData to give the infocenter permission to the FilterWidget - Changed the logic into the FilterWidget to manage the requiredPermissions parameter --- application/controllers/system/Filters.php | 36 ++++++++++++++++++- .../system/infocenter/infocenterData.php | 9 ++--- application/widgets/FilterWidget.php | 14 ++++++++ 3 files changed, 54 insertions(+), 5 deletions(-) diff --git a/application/controllers/system/Filters.php b/application/controllers/system/Filters.php index 759f9c56b..73ffc0d27 100644 --- a/application/controllers/system/Filters.php +++ b/application/controllers/system/Filters.php @@ -5,7 +5,7 @@ if (! defined('BASEPATH')) exit('No direct script access allowed'); /** * */ -class Filters extends FHC_Controller +class Filters extends CI_Controller { const SESSION_NAME = 'FILTER'; @@ -25,9 +25,13 @@ class Filters extends FHC_Controller // Load session library $this->load->library('session'); + // Load permission library + $this->load->library('PermissionLib'); $this->load->model('system/Filters_model', 'FiltersModel'); $this->load->model('person/Benutzer_model', 'BenutzerModel'); + + $this->_isAllowed(); } /** @@ -469,4 +473,34 @@ class Filters extends FHC_Controller $this->output->set_content_type('application/json')->set_output(json_encode($json)); } + + /** + * Cheks + */ + private function _isAllowed() + { + if (isset($_SESSION[self::SESSION_NAME]['requiredPermissions'])) + { + $requiredPermissions = array( + 'filters' => $_SESSION[self::SESSION_NAME]['requiredPermissions'].':rw' + ); + + if (!$this->permissionlib->isEntitled($requiredPermissions, 'filters')) + { + header('Content-Type: application/json'); + + echo json_encode('You are not allowed to access to this content'); + + exit(1); + } + } + else + { + header('Content-Type: application/json'); + + echo json_encode('You are not allowed to access to this content'); + + exit(1); + } + } } diff --git a/application/views/system/infocenter/infocenterData.php b/application/views/system/infocenter/infocenterData.php index 663e69ca6..9c2024510 100644 --- a/application/views/system/infocenter/infocenterData.php +++ b/application/views/system/infocenter/infocenterData.php @@ -137,12 +137,13 @@ ) ORDER BY "LastAction" ASC ', - 'hideHeader' => false, - 'hideSave' => false, + 'requiredPermissions' => 'infocenter', 'checkboxes' => 'PersonId', 'additionalColumns' => array('Details'), - 'columnsAliases' => array('PersonID','Vorname','Nachname','GebDatum','Letzte Aktion','Letzter Bearbeiter', - 'StSem','GesendetAm','NumAbgeschickt','Studiengänge','Sperrdatum','GesperrtVon'), + 'columnsAliases' => array( + 'PersonID','Vorname','Nachname','GebDatum','Letzte Aktion','Letzter Bearbeiter', + 'StSem','GesendetAm','NumAbgeschickt','Studiengänge','Sperrdatum','GesperrtVon' + ), 'formatRaw' => function($datasetRaw) { $datasetRaw->{'Details'} = sprintf( diff --git a/application/widgets/FilterWidget.php b/application/widgets/FilterWidget.php index 925126a43..68e204f5c 100644 --- a/application/widgets/FilterWidget.php +++ b/application/widgets/FilterWidget.php @@ -18,6 +18,7 @@ class FilterWidget extends Widget const HIDE_HEADER = 'hideHeader'; const HIDE_SAVE = 'hideSave'; const COLUMNS_ALIASES = 'columnsAliases'; + const REQUIRED_PERMISSIONS = 'requiredPermissions'; const DATASET_PARAMETER = 'dataset'; const METADATA_PARAMETER = 'metaData'; @@ -78,6 +79,7 @@ class FilterWidget extends Widget private $checkboxes; private $columnsAliases; private $filterName; + private $requiredPermissions; private $dataset; private $metaData; @@ -164,6 +166,7 @@ class FilterWidget extends Widget $filterSessionArray[self::COLUMNS_ALIASES] = $this->_getColumnAliasesFromPost(); $filterSessionArray[self::CHECKBOXES] = $this->checkboxes; + $filterSessionArray[self::REQUIRED_PERMISSIONS] = $this->requiredPermissions; if ($this->app != null) { @@ -482,6 +485,11 @@ class FilterWidget extends Widget $filterSessionArray[self::DATASET_NAME_PARAMETER] = null; } + if (!isset($filterSessionArray[self::REQUIRED_PERMISSIONS])) + { + $filterSessionArray[self::REQUIRED_PERMISSIONS] = null; + } + $this->session->set_userdata(self::SESSION_NAME, $filterSessionArray); } @@ -503,6 +511,7 @@ class FilterWidget extends Widget $this->hideSave = false; $this->columnsAliases = null; $this->filterName = null; + $this->requiredPermissions = null; if (!is_array($args) || (is_array($args) && count($args) == 0)) { @@ -589,6 +598,11 @@ class FilterWidget extends Widget { $this->columnsAliases = $args[self::COLUMNS_ALIASES]; } + + if (isset($args[self::REQUIRED_PERMISSIONS])) + { + $this->requiredPermissions = $args[self::REQUIRED_PERMISSIONS]; + } } }