Skip to content

Fix buggy optin list of groups #15

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Controller/GrouperGroupsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,8 @@ public function findSubscriber(): void
}

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

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

/**
* GroupOwner vue route for rendering groupownerapi results
*
* @return void
*/
public function groupOwner(): void
Expand Down
12 changes: 11 additions & 1 deletion Model/GrouperGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
)
);
}

/**
Expand Down
27 changes: 3 additions & 24 deletions View/GrouperGroups/index.ctp
Original file line number Diff line number Diff line change
Expand Up @@ -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'] ?>",
Expand Down
3 changes: 1 addition & 2 deletions webroot/js/groups.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"
});
Expand Down