From 0866077fc6d0aa17996f8ca45dffafa79a119709 Mon Sep 17 00:00:00 2001 From: mokaddem Date: Tue, 20 Aug 2019 10:06:15 +0200 Subject: [PATCH] chg: [decaying] Improved ACL integration for the UI --- app/Controller/DecayingModelController.php | 2 +- app/Model/DecayingModel.php | 6 ++++++ app/View/DecayingModel/decaying_tool.ctp | 1 + app/View/DecayingModel/index.ctp | 15 +++++++++++++++ app/webroot/js/decayingTool.js | 13 ++++++++----- 5 files changed, 31 insertions(+), 6 deletions(-) diff --git a/app/Controller/DecayingModelController.php b/app/Controller/DecayingModelController.php index 51b82e1eb..989b575e9 100644 --- a/app/Controller/DecayingModelController.php +++ b/app/Controller/DecayingModelController.php @@ -172,7 +172,7 @@ class DecayingModelController extends AppController $this->set('mayModify', true); $restrictedEdition = $this->DecayingModel->isDefaultModel($decayingModel); if (!$this->_isSiteAdmin() && $decayingModel['DecayingModel']['org_id'] != $this->Auth->user('Organisation')['id']) { - throw new MethodNotAllowedException(__("The model does not belong to your organisation")); + throw new UnauthorizedException(__("The model does not belong to your organisation")); } if ($this->request->is('post') || $this->request->is('put')) { diff --git a/app/Model/DecayingModel.php b/app/Model/DecayingModel.php index 2ba1bc3f3..3ab78f900 100644 --- a/app/Model/DecayingModel.php +++ b/app/Model/DecayingModel.php @@ -169,6 +169,11 @@ class DecayingModel extends AppModel return !is_null($decaying_model['DecayingModel']['uuid']); } + public function isEditableByCurrentUser($user, $decaying_model) + { + return !$this->isDefaultModel($decaying_model) && $decaying_model['DecayingModel']['org_id'] == $user['org_id']; + } + public function fetchAllAllowedModels($user, $full=true, $filters=array()) { $conditions = array(); @@ -194,6 +199,7 @@ class DecayingModel extends AppModel $decayingModels[$i]['DecayingModel']['attribute_types'] = $decayingModels[$i]['DecayingModel']['attribute_types'] + Hash::extract($decayingModels[$i]['DecayingModelMapping'], '{n}.attribute_type'); unset($decayingModels[$i]['DecayingModelMapping']); } + $decayingModels[$i]['DecayingModel']['isEditable'] = $this->isEditableByCurrentUser($user, $decayingModels[$i]); } return $decayingModels; diff --git a/app/View/DecayingModel/decaying_tool.ctp b/app/View/DecayingModel/decaying_tool.ctp index 94899a013..0eb14c881 100644 --- a/app/View/DecayingModel/decaying_tool.ctp +++ b/app/View/DecayingModel/decaying_tool.ctp @@ -171,6 +171,7 @@ ?>