From dbaa2ba7b320ce3f9511155ab7b9b960e26e67fc Mon Sep 17 00:00:00 2001 From: iglocska Date: Tue, 18 Jan 2022 16:56:38 +0100 Subject: [PATCH 1/2] fix: [encryption keys] several fixes - fix the user view to correctly point to the list of related encryption keys - fix the lookup on the index to be based on owner_model + owner_id combo - fix the filtering of the dropdown in the encryption key add form to only valid options --- src/Controller/EncryptionKeysController.php | 9 ++++++++- templates/Users/view.php | 4 ++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/Controller/EncryptionKeysController.php b/src/Controller/EncryptionKeysController.php index 324decb..803f180 100644 --- a/src/Controller/EncryptionKeysController.php +++ b/src/Controller/EncryptionKeysController.php @@ -14,7 +14,7 @@ use Cake\Error\Debugger; class EncryptionKeysController extends AppController { - public $filterFields = ['owner_model', 'organisation_id', 'individual_id', 'encryption_key']; + public $filterFields = ['owner_model', 'owner_id', 'encryption_key']; public $quickFilterFields = ['encryption_key']; public $containFields = ['Individuals', 'Organisations']; @@ -65,6 +65,13 @@ class EncryptionKeysController extends AppController $individualConditions = [ 'id' => $currentUser['individual_id'] ]; + } else { + $this->loadModel('Alignments'); + $individualConditions = ['id IN' => $this->Alignments->find('list', [ + 'keyField' => 'id', + 'valueField' => 'individual_id', + 'conditions' => ['organisation_id' => $currentUser['organisation_id']] + ])->toArray()]; } $params['beforeSave'] = function($entity) use($currentUser) { if ($entity['owner_model'] === 'organisation') { diff --git a/templates/Users/view.php b/templates/Users/view.php index 26c3c25..fbddf52 100644 --- a/templates/Users/view.php +++ b/templates/Users/view.php @@ -56,8 +56,8 @@ echo $this->element( 'title' => __('Authentication keys') ], [ - 'url' => '/EncryptionKeys/index?Users.id={{0}}', - 'url_params' => ['id'], + 'url' => '/EncryptionKeys/index?owner_id={{0}}', + 'url_params' => ['individual_id'], 'title' => __('Encryption keys') ], [ From f75d0829d1a98e2c686beb89d993df5ac824883f Mon Sep 17 00:00:00 2001 From: iglocska Date: Tue, 18 Jan 2022 17:52:59 +0100 Subject: [PATCH 2/2] fix: [user edit] fixed for non admins --- src/Controller/UsersController.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Controller/UsersController.php b/src/Controller/UsersController.php index a5065db..9ffb2fe 100644 --- a/src/Controller/UsersController.php +++ b/src/Controller/UsersController.php @@ -7,6 +7,7 @@ use Cake\Utility\Text; use Cake\ORM\TableRegistry; use \Cake\Database\Expression\QueryExpression; use Cake\Http\Exception\UnauthorizedException; +use Cake\Http\Exception\MethodNotAllowedException; use Cake\Core\Configure; class UsersController extends AppController @@ -100,11 +101,10 @@ class UsersController extends AppController if (empty($id)) { $id = $currentUser['id']; } else { + $id = intval($id); if ((empty($currentUser['role']['perm_org_admin']) && empty($currentUser['role']['perm_admin']))) { if ($id !== $currentUser['id']) { throw new MethodNotAllowedException(__('You are not authorised to edit that user.')); - } else { - $id = $currentUser['id']; } } }