From 8e98e525d7dd5cceec624ae7a967d99a07faf709 Mon Sep 17 00:00:00 2001 From: Ioannis Igoumenos Date: Wed, 3 Apr 2024 19:22:35 +0300 Subject: [PATCH] Do not allow act as duplicates in database --- Controller/ActAsPeopleController.php | 13 +++++++++++++ Lib/enum.php | 11 ++++++----- View/Elements/ActAsPeopleAutocomplete.ctp | 1 + View/GrouperGroups/index.ctp | 2 ++ webroot/js/autocomplete.js | 4 +++- 5 files changed, 25 insertions(+), 6 deletions(-) diff --git a/Controller/ActAsPeopleController.php b/Controller/ActAsPeopleController.php index 71e5b07..aafa563 100644 --- a/Controller/ActAsPeopleController.php +++ b/Controller/ActAsPeopleController.php @@ -89,6 +89,19 @@ public function add(): void $fullName = $data['fullname']; unset($data['fullname']); + $args = []; + $args['conditions']['ActAsPerson.co_person_id'] = $data['co_person_id']; + $args['conditions']['ActAsPerson.act_as_co_person_id'] = $data['act_as_co_person_id']; + $args['contain'] = false; + if(!empty($this->ActAsPerson->find('first', $args))) { + $this->Api->restResultHeader(HttpStatusCodesEnum::HTTP_CONFLICT, 'Already Exists'); + $error = ErrorsEnum::Conflict; + $this->set(compact('error')); + $this->set('_serialize', 'error'); + return; + } + + try { $ret = $this->ActAsPerson->saveAll($data); } diff --git a/Lib/enum.php b/Lib/enum.php index c496330..dd8185b 100644 --- a/Lib/enum.php +++ b/Lib/enum.php @@ -1,11 +1,12 @@ 'ERROR', 'message' => 'ERROR']; - const Exception = ['status' => 'ERROR', 'message' => 'EXCEPTION']; - const NoAccess = ['status' => 'ERROR', 'message' => 'NO ACCESS']; - const NotAdded = ['status' => 'ERROR', 'message' => 'NOT ADDED']; - const NotDeleted = ['status' => 'ERROR', 'message' => 'NOT DELETED']; + const Error = ['status' => 'ERROR', 'message' => 'Error']; + const Exception = ['status' => 'ERROR', 'message' => 'Exception']; + const NoAccess = ['status' => 'ERROR', 'message' => 'No Access']; + const NotAdded = ['status' => 'ERROR', 'message' => 'Not Added']; + const Conflict = ['status' => 'ERROR', 'message' => 'Already Exists']; + const NotDeleted = ['status' => 'ERROR', 'message' => 'Not Deleted']; } class GrouperSpecialGroups { diff --git a/View/Elements/ActAsPeopleAutocomplete.ctp b/View/Elements/ActAsPeopleAutocomplete.ctp index d147ae9..4e650f9 100644 --- a/View/Elements/ActAsPeopleAutocomplete.ctp +++ b/View/Elements/ActAsPeopleAutocomplete.ctp @@ -167,6 +167,7 @@ $suffix = Configure::read('debug') > 0 ? '?time=' . time() : '';
diff --git a/View/GrouperGroups/index.ctp b/View/GrouperGroups/index.ctp index 0dc3b5e..a16062d 100644 --- a/View/GrouperGroups/index.ctp +++ b/View/GrouperGroups/index.ctp @@ -160,6 +160,8 @@ $suffix = Configure::read('debug') > 0 ? '?time=' . time() : ''; + element('ActionSideBar', compact('vv_config', 'vv_act_as_people', diff --git a/webroot/js/autocomplete.js b/webroot/js/autocomplete.js index f6e05b5..ed0eb84 100644 --- a/webroot/js/autocomplete.js +++ b/webroot/js/autocomplete.js @@ -49,7 +49,9 @@ export default { isBtnDisabled() { // The minimum length that i start search is 3. So we only enable the button when // the input text value has at least three characters - return this.activeBtn || (this.search.length < 3) + // debugger + console.log('is disabled', (this.activeBtn && (this.search.length < 3)).toString()) + return this.activeBtn && (this.search.length < 3) }, autcompleteId() { return `autocomplete-search-container-${this.action}`