From ce8b675e4dba90239011259ae260bfa8efef817c Mon Sep 17 00:00:00 2001 From: axman Date: Fri, 16 Jul 2021 12:06:55 -0700 Subject: [PATCH] changes for leave/join buttons at WG level --- Controller/GrouperGroupsController.php | 126 ++++++++++++------------- Model/GrouperGroup.php | 6 +- 2 files changed, 65 insertions(+), 67 deletions(-) diff --git a/Controller/GrouperGroupsController.php b/Controller/GrouperGroupsController.php index 5257ba8..5e2a01c 100644 --- a/Controller/GrouperGroupsController.php +++ b/Controller/GrouperGroupsController.php @@ -195,18 +195,10 @@ public function groupOwner() { $data = $this->Paginator->paginate('GrouperGroup', $scope); - $wgData = array(); - $notWGData = array(); - foreach($data as $group) { - if(isset($group['WGName'])) { - $wgData[] = $group; - } else { - $notWGData[] = $group; - } - } + $finalData = $this->breakoutGroups($data); - $this->set('groupsowners', $notWGData); - $this->set('wgowners', $wgData); + $this->set('groupsowners', $finalData['adHocGroups']); + $this->set('wgowners', $finalData['workingGroups']); } catch (Exception $e) { CakeLog::write('error', __METHOD__ . ' Search: ' . var_export($e->getMessage(), true)); @@ -221,18 +213,10 @@ public function groupOwner() { $data = $this->Paginator->paginate('GrouperGroup', $scope); - $wgData = array(); - $notWGData = array(); - foreach($data as $group) { - if(isset($group['WGName'])) { - $wgData[] = $group; - } else { - $notWGData[] = $group; - } - } + $finalData = $this->breakoutGroups($data); - $this->set('groupsowners', $notWGData); - $this->set('wgowners', $wgData); + $this->set('groupsowners', $finalData['adHocGroups']); + $this->set('wgowners', $finalData['workingGroups']); } catch (Exception $e) { CakeLog::write('error', __METHOD__ . ': ' . var_export($e->getMessage(), true)); @@ -248,6 +232,48 @@ public function groupOwner() { $this->set('isTemplateUser', $this->GrouperGroup->isTemplateUser($this->userId)); } + /** + * Breakout Working Groups from AdHoc Groups for display purposes in UI. + * + * @param array $recordSet + * @return array[] + * + */ + public function breakoutGroups(array $recordSet, $type='basic') { + + $wgData = array(); + $notWGData = array(); + foreach($recordSet as $record) { + if(isset($record['WGName'])) { + $wgData[] = $record; + } else { + $notWGData[] = $record; + } + } + + if ($type == 'basic') { + //Need to surface Optout flag to top level of a Working Group + foreach($wgData as &$wgRec) { + foreach($wgRec['Groups'] as $rec){ + if(isset($rec['optOut'])) { + $wgRec['optOut'] = true; + $wgRec['workingGroupId'] = $rec['name']; + } + } + } + } elseif ($type == 'optin') { + foreach($wgData as &$wgRec) { + $wgRec['workingGroupId'] = $wgRec['Groups'][0]['name']; + } + } + + + return array( + 'adHocGroups' => $notWGData, + 'workingGroups' => $wgData + ); + } + /** * Returns all Groups that the User is a member of in Grouper * This includes self-joined Optin Groups, as well as required Groups User cannot leave @@ -275,18 +301,10 @@ public function groupMember() { $data = $this->Paginator->paginate('GrouperGroup', $scope); - $wgData = array(); - $notWGData = array(); - foreach($data as $group) { - if(isset($group['WGName'])) { - $wgData[] = $group; - } else { - $notWGData[] = $group; - } - } + $finalData = $this->breakoutGroups($data); - $this->set('groupmemberships', $notWGData); - $this->set('wgmemberships', $wgData); + $this->set('groupmemberships', $finalData['adHocGroups']); + $this->set('wgmemberships', $finalData['workingGroups']); } catch (Exception $e) { CakeLog::write('error', __METHOD__ . ' Search: ' . var_export($e->getMessage(), true)); @@ -303,18 +321,10 @@ public function groupMember() { $data = $this->Paginator->paginate('GrouperGroup', $scope); - $wgData = array(); - $notWGData = array(); - foreach($data as $group) { - if(isset($group['WGName'])) { - $wgData[] = $group; - } else { - $notWGData[] = $group; - } - } + $finalData = $this->breakoutGroups($data); - $this->set('groupmemberships', $notWGData); - $this->set('wgmemberships', $wgData); + $this->set('groupmemberships', $finalData['adHocGroups']); + $this->set('wgmemberships', $finalData['workingGroups']); } catch (Exception $e) { CakeLog::write('error', __METHOD__ . ': ' . var_export($e->getMessage(), true)); @@ -355,18 +365,10 @@ public function groupOptin() { $data = $this->Paginator->paginate('GrouperGroup', $scope); //$this->set('groupoptin', $data); - $wgData = array(); - $notWGData = array(); - foreach($data as $group) { - if(isset($group['WGName'])) { - $wgData[] = $group; - } else { - $notWGData[] = $group; - } - } + $finalData = $this->breakoutGroups($data, 'optin'); - $this->set('groupoptins', $notWGData); - $this->set('wgoptins', $wgData); + $this->set('groupoptins', $finalData['adHocGroups']); + $this->set('wgoptins', $finalData['workingGroups']); } catch (Exception $e) { CakeLog::write('error', __METHOD__ . 'Search: ' . var_export($e->getMessage(), true)); @@ -384,18 +386,10 @@ public function groupOptin() { $data = $this->Paginator->paginate('GrouperGroup', $scope); //$this->set('groupoptin', $data); - $wgData = array(); - $notWGData = array(); - foreach($data as $group) { - if(isset($group['WGName'])) { - $wgData[] = $group; - } else { - $notWGData[] = $group; - } - } + $finalData = $this->breakoutGroups($data,'optin'); - $this->set('groupoptins', $notWGData); - $this->set('wgoptins', $wgData); + $this->set('groupoptins', $finalData['adHocGroups']); + $this->set('wgoptins', $finalData['workingGroups']); } catch (Exception $e) { CakeLog::write('error', __METHOD__ . ': ' . var_export($e->getMessage(), true)); diff --git a/Model/GrouperGroup.php b/Model/GrouperGroup.php index 4e12b1c..e1be79f 100644 --- a/Model/GrouperGroup.php +++ b/Model/GrouperGroup.php @@ -231,7 +231,11 @@ private function getFriendlyWorkingGroupName(array $groups) { $appCount += 1; } $group['WGApp'] = $appName; - $workingGroups[] = $group; + //TODO - FOR DISPLAY PURPOSE + if ($group['WGRole'] !== 'admins' && $group['WGRole'] !== 'owners') { + $workingGroups[] = $group; + } + //$workingGroups[] = $group; unset($groups[$arrayIndex]); } }