From f2774dda1564974689db437131e26c1ae585e5af Mon Sep 17 00:00:00 2001 From: Ioannis Igoumenos Date: Wed, 6 Mar 2024 18:17:27 +0200 Subject: [PATCH] Fix buggy optin list of groups --- Controller/GrouperGroupsController.php | 6 ++++++ Model/GrouperGroup.php | 12 +++++++++++- View/GrouperGroups/index.ctp | 27 +++----------------------- webroot/js/groups.js | 3 +-- 4 files changed, 21 insertions(+), 27 deletions(-) diff --git a/Controller/GrouperGroupsController.php b/Controller/GrouperGroupsController.php index f4c65cf..76bedd8 100644 --- a/Controller/GrouperGroupsController.php +++ b/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 diff --git a/Model/GrouperGroup.php b/Model/GrouperGroup.php index 5420743..49172c6 100644 --- a/Model/GrouperGroup.php +++ b/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) + ) + ); } /** diff --git a/View/GrouperGroups/index.ctp b/View/GrouperGroups/index.ctp index b05e647..48ed270 100644 --- a/View/GrouperGroups/index.ctp +++ b/View/GrouperGroups/index.ctp @@ -117,30 +117,9 @@ glid: , mode: "", base: "webroot ?>grouper_lite_widget/grouper_groups", - find: "Html->url( - array( - 'controller' => 'grouper_groups', - 'action' => 'findSubscriber', - 'co' => $vv_coid, - 'glid' => $vv_config['CoGrouperLiteWidget']['id'], - ) - ) ?>", - join: "Html->url( - array( - 'controller' => 'grouper_groups', - 'action' => 'joinGroup', - 'co' => $vv_coid, - 'glid' => $vv_config['CoGrouperLiteWidget']['id'], - ) - ) ?>", - leave: "Html->url( - array( - 'controller' => 'grouper_groups', - 'action' => 'leaveGroup', - 'co' => $vv_coid, - 'glid' => $vv_config['CoGrouperLiteWidget']['id'], - ) - ) ?>", + find: "webroot ?>grouper_lite_widget/grouper_groups/findSubscriber/co:/glid:", + join: "webroot ?>grouper_lite_widget/grouper_groups/joinGroup/co:/glid:", + leave: "webroot ?>grouper_lite_widget/grouper_groups/leaveGroup/co:/glid:", remove: "webroot ?>grouper_lite_widget/grouper_groups/removeSubscriber/co:/glid:", add: "webroot ?>grouper_lite_widget/grouper_groups/addSubscriber/co:/glid:", group: "webroot ?>grouper_lite_widget/grouper_groups/groupSubscribers/co:/glid:", diff --git a/webroot/js/groups.js b/webroot/js/groups.js index dae157a..35f910d 100644 --- a/webroot/js/groups.js +++ b/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" });