diff --git a/Controller/GrouperGroupsController.php b/Controller/GrouperGroupsController.php index c0ad433..594f53b 100644 --- a/Controller/GrouperGroupsController.php +++ b/Controller/GrouperGroupsController.php @@ -528,7 +528,6 @@ function isAuthorized() { $p['emaillistsoptin'] = true; $p['emaillistsmember'] = true; $p['emaillistsmanage'] = true; - $p['emaillistsinfo'] = true; $p['groupcreate'] = true; $p['groupdelete'] = true; $p['joingroup'] = true; @@ -546,55 +545,104 @@ public function emaillistsOptin() { //Set initial settings for pagination $scope = [ 'userId' => $this->userId, - 'page' => (isset($this->passedArgs['page']) ? $this->passedArgs['page'] : $this->paginate['page']), - 'limit' => (isset($this->passedArgs['limit']) ? $this->passedArgs['limit'] : $this->paginate['limit']), + 'page' => ($this->passedArgs['page'] ?? $this->paginate['page']), + 'limit' => ($this->passedArgs['limit'] ?? $this->paginate['limit']), ]; - try { - //Add settings for optinEmailLists - $scope['method'] = 'optinEmailGroups'; + if (isset($this->request->data['search'])) { + $searchCriteria = urldecode($this->request->data['search']); + $this->set('searchcriteria', $searchCriteria); + + try { + //Add setting for Group Membership + $scope['method'] = 'getSearchedGroups'; + $scope['searchcriteria'] = $searchCriteria; + $scope['searchpage'] = 'optinEmailGroups'; + $scope['emailonly'] = true; - $data = $this->Paginator->paginate('GrouperGroup', $scope); - $this->set('emailgroups', $data); + $data = $this->Paginator->paginate('GrouperGroup', $scope); - } catch (Exception $e) { - CakeLog::write('error', __METHOD__ . ': ' . var_export($e->getMessage(), true)); - $this->Flash->set("An error occurred with the Optin Groups, please try again later.", array('key' => 'error')); - $this->set('emailgroups', array()); - return; + $this->set('emailgroups', $data); + + } catch (Exception $e) { + CakeLog::write('error', __METHOD__ . ' Search: ' . var_export($e->getMessage(), true)); + + $this->Flash->set("Your Email Optin List cannot be found, please try again later.", array('key' => 'error')); + $this->set('emailgroups', array()); + return; + } + } else { + try { + //Add setting for Group Membership + $scope['method'] = 'optinEmailGroups'; + $scope['emailonly'] = true; + + $data = $this->Paginator->paginate('GrouperGroup', $scope); + + $this->set('emailgroups', $data); + + } catch (Exception $e) { + CakeLog::write('error', __METHOD__ . ' Search: ' . var_export($e->getMessage(), true)); + + $this->Flash->set("An error occurred with the Optin Email Lists, please try again later.", array('key' => 'error')); + $this->set('emailgroups', array()); + return; + } } $this->set('isuserowner', $this->GrouperGroup->isUserOwner($this->userId)); $this->set('isTemplateUser', $this->GrouperGroup->isTemplateUser($this->userId)); } - //############################################################################################################## - //TODO - Need to finish off the email list pages, once we get direction from I2 - //############################################################################################################## - public function emaillistsMember() { $this->set('title', _txt('pl.grouperlite.title.emaillists-member')); //Set initial settings for pagination $scope = [ 'userId' => $this->userId, - 'page' => (isset($this->passedArgs['page']) ? $this->passedArgs['page'] : $this->paginate['page']), - 'limit' => (isset($this->passedArgs['limit']) ? $this->passedArgs['limit'] : $this->paginate['limit']), + 'page' => ($this->passedArgs['page'] ?? $this->paginate['page']), + 'limit' => ($this->passedArgs['limit'] ?? $this->paginate['limit']), ]; - try { - //Add setting for Group Membership - $scope['method'] = 'filteredMemberOfEmails'; + if (isset($this->request->data['search'])) { + $searchCriteria = urldecode($this->request->data['search']); + $this->set('searchcriteria', $searchCriteria); - $data = $this->Paginator->paginate('GrouperGroup', $scope); - $this->set('emailgroups', $data); + try { + //Add setting for Group Membership + $scope['method'] = 'getSearchedGroups'; + $scope['searchcriteria'] = $searchCriteria; + $scope['searchpage'] = 'filteredMemberOfEmails'; + $scope['emailonly'] = true; - } catch (Exception $e) { - CakeLog::write('error', __METHOD__ . ': ' . var_export($e->getMessage(), true)); + $data = $this->Paginator->paginate('GrouperGroup', $scope); + + $this->set('emailgroups', $data); + + } catch (Exception $e) { + CakeLog::write('error', __METHOD__ . ' Search: ' . var_export($e->getMessage(), true)); + + $this->Flash->set("Your Email Group cannot be found, please try again later.", array('key' => 'error')); + $this->set('emailgroups', array()); + return; + } + } else { + try { + //Add setting for Group Membership + $scope['method'] = 'filteredMemberOfEmails'; + $scope['emailonly'] = true; + + $data = $this->Paginator->paginate('GrouperGroup', $scope); + + $this->set('emailgroups', $data); - $this->Flash->set("Your Member Group cannot be found, please try again later.", array('key' => 'error')); - $this->set('emailgroups', array()); - return; + } catch (Exception $e) { + CakeLog::write('error', __METHOD__ . ' Search: ' . var_export($e->getMessage(), true)); + + $this->Flash->set("Your Email Group cannot be found, please try again later.", array('key' => 'error')); + $this->set('emailgroups', array()); + return; + } } $this->set('isuserowner', $this->GrouperGroup->isUserOwner($this->userId)); @@ -616,25 +664,6 @@ public function emaillistsManage() { $this->set('isTemplateUser', $this->GrouperGroup->isTemplateUser($this->userId)); } - public function emaillistInfo() { - $this->set('title', _txt('pl.grouperlite.title.emaillistsinfo')); - // mock data - $this->set('groupergroupsdetail', array( - 'member' => true, - 'domain' => 'internet2', - 'uuid' => 'abc123xyz789', - 'displayExtension' => 'email-list-1', - 'extension' => 'email-list-1', - 'displayName' => 'Email List 1', - 'typeOfGroup' => 'list', - 'name' => 'Email List 1', - 'description' => 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.', - 'enabled' => 'T', - 'attributes' => array() - )); - $this->set('grouperbaseurl', $this->Session->read('Plugin.Grouper.Api.url')); - - } private function getUserId($id) { $args = array(); diff --git a/Lib/lang.php b/Lib/lang.php index ca2c6fd..9479257 100644 --- a/Lib/lang.php +++ b/Lib/lang.php @@ -144,5 +144,6 @@ 'pl.grouperlite.pagination.counter' => 'Viewing {:start}-{:end} of {:count}', 'pl.grouperlite.attributes.zero-state' => 'No Attributes Associated to this Group.', 'pl.grouperlite.groups.zero-state' => 'No groups found.', - 'pl.grouperlite.working-groups.zero-state' => 'No working groups found.' + 'pl.grouperlite.working-groups.zero-state' => 'No working groups found.', + 'pl.grouperlite.email-lists.zero-state' => 'No email lists found.' ); \ No newline at end of file diff --git a/Model/GrouperGroup.php b/Model/GrouperGroup.php index 85dbeb2..dd22c00 100644 --- a/Model/GrouperGroup.php +++ b/Model/GrouperGroup.php @@ -61,6 +61,8 @@ class GrouperGroup extends GrouperLiteAppModel 'ref:incommon-collab' ); + private $emailStem ='app:sympa'; + // Current listing of stems that are allowed to be viewed in Comanage as AdHoc groups @@ -126,9 +128,9 @@ public function filteredMemberOfEmails(array $conditions) { $memberOfEmails = $this->filteredMemberOfGroups($conditions); - // Strip out all Groups that are not in Sympa Stem/Directory + // Strip out all Groups that are not in app:sympa Stem/Directory foreach ($memberOfEmails as $key => $value) { - if (strpos($value['name'], 'sympa') === false) { + if (strpos(strtolower($value['name']), $this->emailStem) === false) { unset($memberOfEmails[$key]); } } @@ -331,7 +333,7 @@ public function optinEmailGroups(array $conditions) { // Strip out all Groups that are not in Sympa Stem/Directory foreach ($allGroups as $key => $value) { - if (strpos($value['name'], 'sympa') === false) { + if (strpos($value['name'], $this->emailStem) === false) { unset($allGroups[$key]); } } @@ -555,6 +557,7 @@ public function getOwnedStems(string $userId) { /** * Search for Groups/Lists related to Search term. + * * Will import all records the user can see and then do search in this code rather than call Grouper WS Search * functionality. This is due to the fact that the grouperName is autogenerated and this app needs to search * attributes which the Grouper WS does not do. @@ -604,7 +607,12 @@ public function paginate($conditions) { $resultSet = $this->$method($conditions); - $friendlyResults = $this->getFriendlyWorkingGroupName($resultSet); + if (isset($conditions['emailonly']) && $conditions['emailonly']) { + $friendlyResults = $this->getFriendlyEmailName($resultSet); + } else { + $friendlyResults = $this->getFriendlyWorkingGroupName($resultSet); + } + return $this->paginateRecords($friendlyResults, $conditions); } @@ -728,6 +736,27 @@ 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 * diff --git a/View/GrouperGroups/emaillistsmember.ctp b/View/GrouperGroups/emaillistsmember.ctp index e1f61d0..d6952ec 100644 --- a/View/GrouperGroups/emaillistsmember.ctp +++ b/View/GrouperGroups/emaillistsmember.ctp @@ -18,14 +18,14 @@