Skip to content

Commit

Permalink
Do not allow act as duplicates in database
Browse files Browse the repository at this point in the history
  • Loading branch information
Ioannis committed Apr 3, 2024
1 parent b0042c7 commit 8e98e52
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 6 deletions.
13 changes: 13 additions & 0 deletions Controller/ActAsPeopleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
11 changes: 6 additions & 5 deletions Lib/enum.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
<?php

class ErrorsEnum {
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 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 {
Expand Down
1 change: 1 addition & 0 deletions View/Elements/ActAsPeopleAutocomplete.ctp
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ $suffix = Configure::read('debug') > 0 ? '?time=' . time() : '';
<div id="<?= $htmlId ?>-container" class="cm-autocomplete-container">
<Autocomplete @callback="(item) => addUser(item)"
action="enableActAs"
:activeBtn="loading"
icon=""/>
<Loader :active="loading"/>
</div>
2 changes: 2 additions & 0 deletions View/GrouperGroups/index.ctp
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@ $suffix = Configure::read('debug') > 0 ? '?time=' . time() : '';
<router-view></router-view>
</div>
<?php if(isset($permissions['actAsAction']) && $permissions['actAsAction']): ?>
<!-- XXX Currently the action sidebar has hardcoded staff since we only have one user case
As soon as we have more we need to refactor and generalize the implementation -->
<?= $this->element('ActionSideBar',
compact('vv_config',
'vv_act_as_people',
Expand Down
4 changes: 3 additions & 1 deletion webroot/js/autocomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`
Expand Down

0 comments on commit 8e98e52

Please sign in to comment.