Skip to content

Commit

Permalink
Upsert and delete on ActAsPerson Model
Browse files Browse the repository at this point in the history
  • Loading branch information
Ioannis committed Apr 4, 2024
1 parent d4aa2fc commit 0dd1e70
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 32 deletions.
32 changes: 13 additions & 19 deletions Controller/ActAsPeopleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,8 @@ public function beforeFilter()
$this->RequestHandler->addInputType('json', ['json_decode', true]);

$this->Security->unlockedActions = [
'add',
'edit',
'delete'
'delete',
'upsert',
];

// Get the config
Expand All @@ -69,12 +68,12 @@ public function beforeFilter()
}

/**
* Add an ActAs user
* Update or Insert an ActAs user
*
* @since COmanage Registry v4.4.0
*/

public function add(): void
public function upsert(): void
{
$this->request->allowMethod('ajax');
$this->layout = 'ajax';
Expand All @@ -91,6 +90,9 @@ public function add(): void

$args = [];
$args['conditions']['ActAsPerson.co_person_id'] = $data['co_person_id'];
if(!empty($this->request->named['actrecordId'])) {
$args['conditions']['ActAsPerson.id'] = $this->request->named['actrecordId'];
}
$args['conditions']['ActAsPerson.act_as_co_person_id'] = $data['act_as_co_person_id'];
$args['contain'] = false;
if(!empty($this->ActAsPerson->find('first', $args))) {
Expand All @@ -101,9 +103,13 @@ public function add(): void
return;
}

// We will update
if(!empty($this->request->named['actrecordId'])) {
$this->ActAsPerson->id = $this->request->named['actrecordId'];
}

try {
$ret = $this->ActAsPerson->saveAll($data);
$ret = $this->ActAsPerson->save($data);
}
catch(Exception $e) {
$err = filter_var($e->getMessage(),FILTER_SANITIZE_SPECIAL_CHARS);
Expand Down Expand Up @@ -174,14 +180,6 @@ public function delete():void
throw new BadRequestException('Named Parameter missing');
}

$redirect = [
'plugin' => 'grouper_lite_widget',
'controller' => 'grouper_groups',
'action' => $this->request->named['redirect_act'] ?? 'groupmember',
'co' => $this->request->named['co'],
'glid' => $this->request->named['glid']
];

try {
$conditions = [
'ActAsPerson.co_person_id' => $this->request->named['copersonid'],
Expand Down Expand Up @@ -267,12 +265,8 @@ public function isAuthorized(): array|bool
// Construct the permission set for this user, which will also be passed to the view.
$p = [];

$p['add'] = $isActAsEligibilityGroupmember;
$p['delete'] = $isActAsEligibilityGroupmember;
$p['edit'] = $isActAsEligibilityGroupmember;
$p['index'] = $isActAsEligibilityGroupmember;
$p['view'] = $isActAsEligibilityGroupmember;
$p['patch'] = $isActAsEligibilityGroupmember;
$p['upsert'] = $isActAsEligibilityGroupmember;

$this->set('permissions', $p);

Expand Down
1 change: 1 addition & 0 deletions Controller/GrouperGroupsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ public function beforeRender() {
PeoplePickerModeEnum::All,
[$act_as_record['ActAsPerson']['act_as_co_person_id']]);
$this->set('vv_act_as_people', $act_as_person);
$this->set('vv_act_as_record_id', $act_as_record['ActAsPerson']['id']);
}
}

Expand Down
22 changes: 14 additions & 8 deletions View/Elements/ActAsPeopleAutocomplete.ctp
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,12 @@ $suffix = Configure::read('debug') > 0 ? '?time=' . time() : '';
url: "<?= $actionUrl ?? 'null' ?>",
grouperUrl: "<?= $grouperUrlBase ?>",
view: "<?= $this->action ?>",
hasActAs: <?= (int)!empty($vv_act_as_people) ?>,
actAsPerson: <?= json_encode($vv_act_as_people ?? []) ?>,
permissions: <?= json_encode($permissions, JSON_THROW_ON_ERROR) ?>,
other: {
hasActAs: <?= (int)!empty($vv_act_as_people) ?>,
actAsRecordId: <?= $vv_act_as_record_id ?? -1 ?>,
actAsPerson: <?= json_encode($vv_act_as_people ?? []) ?>,
permissions: <?= json_encode($permissions, JSON_THROW_ON_ERROR) ?>,
},
txt: {
adhocHeading: "<?= $vv_config['CoGrouperLiteWidget']['adhoc_heading'] ?? 'Ad-hoc groups' ?>",
wgHeading: "<?= $vv_config['CoGrouperLiteWidget']['wg_heading'] ?? 'Working groups' ?>",
Expand Down Expand Up @@ -88,7 +91,7 @@ $suffix = Configure::read('debug') > 0 ? '?time=' . time() : '';
leave: "<?= $this->webroot ?>grouper_lite_widget/grouper_groups/leaveGroup/co:<?= $vv_coid ?>/glid:<?= $vv_config['CoGrouperLiteWidget']['id'] ?>",
remove: "<?= $this->webroot ?>grouper_lite_widget/grouper_groups/removeSubscriber/co:<?= $vv_coid ?>/glid:<?= $vv_config['CoGrouperLiteWidget']['id'] ?>",
add: "<?= $this->webroot ?>grouper_lite_widget/grouper_groups/addSubscriber/co:<?= $vv_coid ?>/glid:<?= $vv_config['CoGrouperLiteWidget']['id'] ?>",
addActAs: "<?= $this->webroot ?>grouper_lite_widget/act_as_people/add/co:<?= $vv_coid ?>/glid:<?= $vv_config['CoGrouperLiteWidget']['id'] ?>",
addActAs: "<?= $this->webroot ?>grouper_lite_widget/act_as_people/upsert/co:<?= $vv_coid ?>/glid:<?= $vv_config['CoGrouperLiteWidget']['id'] ?>",
group: "<?= $this->webroot ?>grouper_lite_widget/grouper_groups/groupSubscribers/co:<?= $vv_coid ?>/glid:<?= $vv_config['CoGrouperLiteWidget']['id'] ?>",
memberships: "<?= $this->webroot ?>grouper_lite_widget/grouper_groups/groupmemberapi/co:<?= $vv_coid ?>/glid:<?= $vv_config['CoGrouperLiteWidget']['id'] ?>",
managing: "<?= $this->webroot ?>grouper_lite_widget/grouper_groups/usermanagerapi/co:<?= $vv_coid ?>/glid:<?= $vv_config['CoGrouperLiteWidget']['id'] ?>",
Expand All @@ -109,7 +112,7 @@ $suffix = Configure::read('debug') > 0 ? '?time=' . time() : '';
Autocomplete,
Loader
},
inject: ['txt', 'api'],
inject: ['txt', 'api', 'other'],
methods: {
async addUser(user) {
const { identifier: ident, label, value: id } = user;
Expand All @@ -123,7 +126,10 @@ $suffix = Configure::read('debug') > 0 ? '?time=' . time() : '';
formData.append("fullname", label);

// Request URL
const urlString = window.location.protocol + "//" + window.location.host + this.api.addActAs;
let urlString = window.location.protocol + "//" + window.location.host + this.api.addActAs;
if(!!this.other.hasActAs) {
urlString += `/actrecordId:${this.other.actAsRecordId}`
}
const url = new URL(urlString);

// AJAX Request
Expand All @@ -140,9 +146,9 @@ $suffix = Configure::read('debug') > 0 ? '?time=' . time() : '';
const resp = await (fetch(request).catch(error => generateFlash('Network Error', 'error')));

if (!resp.ok) {
generateFlash('Enabling ActAs User failed', 'error');
let errorResponse = await resp.json();
generateFlash(`Enabling ActAs ${label} failed`, 'error');
this.loading = false
let errorResponse = await resp.json();
generateFlash(`${errorResponse.message}`, 'error');
return
}
Expand Down
4 changes: 2 additions & 2 deletions View/Elements/ActionItem.ctp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ $suffix = Configure::read('debug') > 0 ? '?time=' . time() : '';
leave: "<?= $this->webroot ?>grouper_lite_widget/grouper_groups/leaveGroup/co:<?= $vv_coid ?>/glid:<?= $vv_config['CoGrouperLiteWidget']['id'] ?>",
remove: "<?= $this->webroot ?>grouper_lite_widget/grouper_groups/removeSubscriber/co:<?= $vv_coid ?>/glid:<?= $vv_config['CoGrouperLiteWidget']['id'] ?>",
add: "<?= $this->webroot ?>grouper_lite_widget/grouper_groups/addSubscriber/co:<?= $vv_coid ?>/glid:<?= $vv_config['CoGrouperLiteWidget']['id'] ?>",
addActAs: "<?= $this->webroot ?>grouper_lite_widget/act_as_people/add/co:<?= $vv_coid ?>/glid:<?= $vv_config['CoGrouperLiteWidget']['id'] ?>",
addActAs: "<?= $this->webroot ?>grouper_lite_widget/act_as_people/upsert/co:<?= $vv_coid ?>/glid:<?= $vv_config['CoGrouperLiteWidget']['id'] ?>",
deleteActAs: "<?= $this->webroot ?>grouper_lite_widget/act_as_people/delete/co:<?= $vv_coid ?>/glid:<?= $vv_config['CoGrouperLiteWidget']['id'] ?>",
group: "<?= $this->webroot ?>grouper_lite_widget/grouper_groups/groupSubscribers/co:<?= $vv_coid ?>/glid:<?= $vv_config['CoGrouperLiteWidget']['id'] ?>",
memberships: "<?= $this->webroot ?>grouper_lite_widget/grouper_groups/groupmemberapi/co:<?= $vv_coid ?>/glid:<?= $vv_config['CoGrouperLiteWidget']['id'] ?>",
Expand Down Expand Up @@ -138,8 +138,8 @@ $suffix = Configure::read('debug') > 0 ? '?time=' . time() : '';

if (!resp.ok) {
generateFlash(`Disable ActAs ${this.person.label} failed`, 'error');
let errorResponse = await resp.json();
this.loading = false
let errorResponse = await resp.json();
return
}
this.response = await resp.json();
Expand Down
9 changes: 6 additions & 3 deletions View/GrouperGroups/index.ctp
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,12 @@ $suffix = Configure::read('debug') > 0 ? '?time=' . time() : '';
url: "<?= $actionUrl ?? 'null' ?>",
grouperUrl: "<?= $grouperUrlBase ?>",
view: "<?= $this->action ?>",
hasActAs: <?= (int)!empty($vv_act_as_people) ?>,
actAsPerson: <?= json_encode($vv_act_as_people ?? []) ?>,
permissions: <?= json_encode($permissions, JSON_THROW_ON_ERROR) ?>,
other: {
hasActAs: <?= (int)!empty($vv_act_as_people) ?>,
actAsRecordId: <?= $vv_act_as_record_id ?? -1 ?>,
actAsPerson: <?= json_encode($vv_act_as_people ?? []) ?>,
permissions: <?= json_encode($permissions, JSON_THROW_ON_ERROR) ?>,
},
txt: {
adhocHeading: "<?= $vv_config['CoGrouperLiteWidget']['adhoc_heading'] ?? 'Ad-hoc groups' ?>",
wgHeading: "<?= $vv_config['CoGrouperLiteWidget']['wg_heading'] ?? 'Working groups' ?>",
Expand Down

0 comments on commit 0dd1e70

Please sign in to comment.