From 0e4fbdd747d5c4db09cebfd7b16b5d4d684b2e1c Mon Sep 17 00:00:00 2001 From: axman Date: Thu, 30 Sep 2021 12:32:30 -0700 Subject: [PATCH] fixing bugs --- Controller/GrouperGroupsController.php | 6 +- Model/GrouperGroup.php | 163 ++++++++++++++++--------- 2 files changed, 109 insertions(+), 60 deletions(-) diff --git a/Controller/GrouperGroupsController.php b/Controller/GrouperGroupsController.php index 1a03e42..c02afac 100644 --- a/Controller/GrouperGroupsController.php +++ b/Controller/GrouperGroupsController.php @@ -114,8 +114,6 @@ public function index() { public function groupInfo() { $name = urldecode($this->request->query['groupname']); - $this->set('isuserowner', $this->GrouperGroup->isUserOwner($this->userId)); - $this->set('title', _txt('pl.grouperlite.title.groupinfo')); try { @@ -139,6 +137,7 @@ public function groupInfo() { $this->Flash->set(_txt('pl.grouperlite.message.flash.group-detail-members-failed'), array('key' => 'error')); } + $this->set('isuserowner', $this->GrouperGroup->isUserOwner($this->userId)); $this->set('grouperbaseurl', $this->Session->read('Plugin.Grouper.Api.grouperUrl')); } @@ -752,11 +751,10 @@ private function breakoutGroups(array $recordSet, $type = 'basic') { $wgRec['workingDesc'] = $this->hackDescription($rec['description']); //Capturing record for incommon-collab since deleting a few lines below. if ($rec['WGApp'] == 'incommon-collab') { - $recToDelete = $subCount; if ($type == 'basic') { //Removing record with stem of 'incommon-collab' since displaying on groups Member page, // will show on Admin page - unset($wgRec['Groups'][$recToDelete]); + unset($wgRec['Groups'][$subCount]); } } $subCount += 1; diff --git a/Model/GrouperGroup.php b/Model/GrouperGroup.php index dd22c00..86f5e41 100644 --- a/Model/GrouperGroup.php +++ b/Model/GrouperGroup.php @@ -47,7 +47,6 @@ class GrouperGroup extends GrouperLiteAppModel /** @var string Group whose members can create Groups via Template process */ private $templateCreationGroup = 'ref:workinggroupadmins'; - private $wgStemsTopLevel = array( 'ref:incommon-collab' ); @@ -61,9 +60,8 @@ class GrouperGroup extends GrouperLiteAppModel 'ref:incommon-collab' ); - private $emailStem ='app:sympa'; - - + //Stem for email groups, only email groups using this stem are viewable + private $emailStem = 'app:sympa'; // Current listing of stems that are allowed to be viewed in Comanage as AdHoc groups private $stemsAdHocAllowed = array( @@ -109,7 +107,6 @@ public function isUserOwner(string $userId) { } } - /** * Used to instantiate API class * @@ -124,18 +121,33 @@ private function initApi() { } } + /** + * Listing of members in an email group + * + * @param array $conditions Listing of conditions for display of records, including UserId + * @return array List of members that belong to email group + * @throws GrouperLiteException + * + */ public function filteredMemberOfEmails(array $conditions) { + $this->initApi(); - $memberOfEmails = $this->filteredMemberOfGroups($conditions); + try { + $memberOfEmails = $this->filteredMemberOfGroups($conditions); - // Strip out all Groups that are not in app:sympa Stem/Directory - foreach ($memberOfEmails as $key => $value) { - if (strpos(strtolower($value['name']), $this->emailStem) === false) { - unset($memberOfEmails[$key]); + // Strip out all Groups that are not in app:sympa Stem/Directory + foreach ($memberOfEmails as $key => $value) { + if (strpos(strtolower($value['name']), $this->emailStem) === false) { + unset($memberOfEmails[$key]); + } } + return array_values($memberOfEmails); + + } catch (Exception $e) { + CakeLog::write('error', __METHOD__ . ': An error occurred'); + throw $e; } - return array_values($memberOfEmails); } /** @@ -201,7 +213,7 @@ private function memberOfGroups(array $conditions) { * Gets the Grouper Groups params and values as well as its associated attributes. * * @param string $groupName Name of Group, do not confuse with DisplayName field! - * @return array An set of attributes associated to a specific Grouper Group + * @return array A set of attributes associated to a specific Grouper Group * @throws GrouperLiteException */ public function groupDescriptions(string $groupName) { @@ -328,17 +340,34 @@ public function membersInGroup(array $conditions) { } } + /** + * List of Email Groups a user can opt into. + * + * @param array $conditions Listing of conditions for display of records, including UserId + * @return array Listing of Optin email groups available in Groupe + * @throws GrouperLiteException Captured in Controller + * + */ public function optinEmailGroups(array $conditions) { - $allGroups = $this->optinGroups($conditions); + $this->initApi(); + + try { + $allGroups = $this->optinGroups($conditions); - // Strip out all Groups that are not in Sympa Stem/Directory - foreach ($allGroups as $key => $value) { - if (strpos($value['name'], $this->emailStem) === false) { - unset($allGroups[$key]); + // Strip out all Groups that are not in Sympa Stem/Directory + foreach ($allGroups as $key => $value) { + if (strpos($value['name'], $this->emailStem) === false) { + unset($allGroups[$key]); + } } + + return array_values($allGroups); + + } catch (Exception $e) { + CakeLog::write('error', __METHOD__ . ': An error occurred'); + throw $e; } - return array_values($allGroups); } /** @@ -598,23 +627,64 @@ public function getSearchedGroups(array $conditions) { * * @param array $conditions Listing of conditions for display of records with pagination * @return array Records requested by user with pagination support + * @throws Exception Captured in Controller * */ public function paginate($conditions) { + try { + //Pull out the method that should be run. + $method = $conditions['method']; - //Pull out the method that should be run. - $method = $conditions['method']; + $resultSet = $this->$method($conditions); - $resultSet = $this->$method($conditions); + if (isset($conditions['emailonly']) && $conditions['emailonly']) { + if ($method == 'getSearchedGroups' || $method == 'filteredMemberOfEmails') { + $friendlyResults = $this->getFriendlyEmailName($resultSet, 'member'); + } else { + $friendlyResults = $this->getFriendlyEmailName($resultSet, ''); + } - if (isset($conditions['emailonly']) && $conditions['emailonly']) { - $friendlyResults = $this->getFriendlyEmailName($resultSet); - } else { - $friendlyResults = $this->getFriendlyWorkingGroupName($resultSet); + } else { + if ($method == 'getSearchedGroups' || $method == 'filteredMemberOfGroups') { + $friendlyResults = $this->getFriendlyWorkingGroupName($resultSet, 'member'); + } else { + $friendlyResults = $this->getFriendlyWorkingGroupName($resultSet, ''); + } + } + + return $this->paginateRecords($friendlyResults, $conditions); + } catch (Exception $e) { + CakeLog::write('error', __METHOD__ . ': An error occurred'); + throw $e; } + } + + private function getFriendlyEmailName(array $groups, $method) { - return $this->paginateRecords($friendlyResults, $conditions); + $arrayIndex = 0; + foreach ($groups as &$group) { + $appName = ''; + if ($method == 'member') { + if ($group['extension'] == 'admins' || $group['extension'] == 'owners') { + unset($groups[$arrayIndex]); + } + } + $stems = explode(':', $group['name']); + $sectionCount = count($stems) - 2; + $groupName = $stems[$sectionCount]; + $domain = $stems[2]; + if (strtolower($domain) == 'incommon') { + $address = $groupName . '@lists.incommon.org'; + } elseif (strtolower($domain) == 'internet2') { + $address = $groupName . '@lists.internet2.edu'; + } else { + $address = $groupName . '@lists.' . strtolower($domain) . '.org'; + } + $group['friendlyEmail'] = $address; + $arrayIndex += 1; + } + return $groups; } /** @@ -629,7 +699,7 @@ public function paginate($conditions) { * @return array Listing of Groups in WG format for display * */ - private function getFriendlyWorkingGroupName(array $groups) { + private function getFriendlyWorkingGroupName(array $groups, $method) { $arrayIndex = 0; @@ -642,8 +712,8 @@ private function getFriendlyWorkingGroupName(array $groups) { $stemSections = explode(':', $group['name']); //Get second to last stem section $sectionCount = count($stemSections) - 2; - if (in_array($stemSections[$sectionCount], $topLevelWG) === false){ - $topLevelWG[] = $stemSections[$sectionCount]; + if (in_array($stemSections[$sectionCount], $topLevelWG) === false) { + $topLevelWG[] = $stemSections[$sectionCount]; } } } @@ -659,7 +729,7 @@ private function getFriendlyWorkingGroupName(array $groups) { //Get second to last stem section $sectionCount = count($stemSections) - 2; //If group not part of a top level WG, then do not show! - if (in_array($stemSections[$sectionCount], $topLevelWG) === false){ + if (in_array($stemSections[$sectionCount], $topLevelWG) === false) { break; } $group['WGName'] = $stemSections[$sectionCount]; @@ -694,11 +764,13 @@ private function getFriendlyWorkingGroupName(array $groups) { } $group['WGApp'] = $appName; - //TODO - FOR DEMO PURPOSE THAT LEAVES OUT ADMIN GROUPS TO SHOW WHAT AVERAGE USER SEES -// if ($group['WGRole'] !== 'admins' && $group['WGRole'] !== 'owners') { -// $workingGroups[] = $group; -// } - $workingGroups[] = $group; + if ($method == 'member') { + if ($group['WGRole'] !== 'admins' && $group['WGRole'] !== 'owners') { + $workingGroups[] = $group; + } + } else { + $workingGroups[] = $group; + } unset($groups[$arrayIndex]); } } @@ -736,27 +808,6 @@ private function getFriendlyWorkingGroupName(array $groups) { return $finalWorkingGroups; } - private function getFriendlyEmailName(array $groups) { - - foreach($groups as &$group) { - $appCount = 0; - $appName = ''; - $stems = explode(':', $group['name']); - $sectionCount = count($stems) - 2; - $groupName = $stems[$sectionCount]; - $domain = $stems[2]; - if (strtolower($domain) == 'incommon') { - $address = $groupName . '@lists.incommon.org'; - } elseif (strtolower($domain) == 'internet2') { - $address = $groupName . '@lists.internet2.edu'; - } else { - $address = $groupName . '@lists.' . strtolower($domain) . '.org'; - } - $group['friendlyEmail'] = $address; - } - return $groups; - } - /** * Verify that the AdHoc groups are only coming from stems listed in $stemsAdHocAllowed *