Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #15 from Ioannis/Fix_empty_groupoptins_list
Fix buggy optin list of groups
aaschenbrener committed Mar 6, 2024
2 parents 70b6458 + f2774dd commit 636c3ba
Showing 4 changed files with 21 additions and 27 deletions.
6 changes: 6 additions & 0 deletions Controller/GrouperGroupsController.php
@@ -174,6 +174,8 @@ public function findSubscriber(): void
}

/**
* GroupMember vue route for rendering groupmemberapi results
*
* @return void
*/
public function groupMember(): void
@@ -182,6 +184,8 @@ public function groupMember(): void
}

/**
* GroupOptin vue route for rendering groupoptinapi results
*
* @return void
*/
public function groupOptin(): void
@@ -190,6 +194,8 @@ public function groupOptin(): void
}

/**
* GroupOwner vue route for rendering groupownerapi results
*
* @return void
*/
public function groupOwner(): void
12 changes: 11 additions & 1 deletion Model/GrouperGroup.php
@@ -455,10 +455,20 @@ public function optinGroups(string $userId, array $cfg): array
throw $e;
}

// I am currently not a member to any Group. Return everything
if(empty($userGroups)) {
return $joinOrLeave;
}

// Extract the names of the Groups the user is a member of
$userGroupsNames = Hash::extract($userGroups, '{n}.name');
// Return the groups the user can join and is not a member of
return array_filter($joinOrLeave, static fn($value) => !in_array($value['name'], $userGroupsNames));
return array_values( // Restart indexing from 0(zero) on the final array
array_filter( // Return the groups I am currently not a member
$joinOrLeave,
static fn($value) => !in_array($value['name'], $userGroupsNames)
)
);
}

/**
27 changes: 3 additions & 24 deletions View/GrouperGroups/index.ctp
@@ -117,30 +117,9 @@
glid: <?= $vv_config['CoGrouperLiteWidget']['id'] ?>,
mode: "<?= PeoplePickerModeEnum::All ?>",
base: "<?= $this->webroot ?>grouper_lite_widget/grouper_groups",
find: "<?= $this->Html->url(
array(
'controller' => 'grouper_groups',
'action' => 'findSubscriber',
'co' => $vv_coid,
'glid' => $vv_config['CoGrouperLiteWidget']['id'],
)
) ?>",
join: "<?= $this->Html->url(
array(
'controller' => 'grouper_groups',
'action' => 'joinGroup',
'co' => $vv_coid,
'glid' => $vv_config['CoGrouperLiteWidget']['id'],
)
) ?>",
leave: "<?= $this->Html->url(
array(
'controller' => 'grouper_groups',
'action' => 'leaveGroup',
'co' => $vv_coid,
'glid' => $vv_config['CoGrouperLiteWidget']['id'],
)
) ?>",
find: "<?= $this->webroot ?>grouper_lite_widget/grouper_groups/findSubscriber/co:<?= $vv_coid ?>/glid:<?= $vv_config['CoGrouperLiteWidget']['id'] ?>",
join: "<?= $this->webroot ?>grouper_lite_widget/grouper_groups/joinGroup/co:<?= $vv_coid ?>/glid:<?= $vv_config['CoGrouperLiteWidget']['id'] ?>",
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'] ?>",
group: "<?= $this->webroot ?>grouper_lite_widget/grouper_groups/groupSubscribers/co:<?= $vv_coid ?>/glid:<?= $vv_config['CoGrouperLiteWidget']['id'] ?>",
3 changes: 1 addition & 2 deletions webroot/js/groups.js
@@ -57,8 +57,7 @@ export default {
group.loading = true;
const resp = await fetch(`${this.api.leave}?GroupName=${group.name}&GroupDisplayName=${group.displayName}`, {
headers: {
"Accept": "application/json",
// 'Content-Type': 'application/x-www-form-urlencoded',
"Accept": "application/json"
},
method: "DELETE"
});

0 comments on commit 636c3ba

Please sign in to comment.