From 579c98dcdb3a5995a54d90b40918745211bad980 Mon Sep 17 00:00:00 2001 From: Axel Stohn Date: Sun, 14 May 2023 10:02:13 -0700 Subject: [PATCH] Removed unused code and removed pagination --- Controller/GrouperGroupsController.php | 242 ++---------------- Model/GrouperGroup.php | 331 +++---------------------- 2 files changed, 48 insertions(+), 525 deletions(-) diff --git a/Controller/GrouperGroupsController.php b/Controller/GrouperGroupsController.php index b024ef6..ccba290 100644 --- a/Controller/GrouperGroupsController.php +++ b/Controller/GrouperGroupsController.php @@ -46,15 +46,6 @@ class GrouperGroupsController extends GrouperLiteAppController public $name = 'GrouperGroups'; - //Unfortunately we cannot go below 20 since that is the default and if change to below 20 will not show - //page navigation unless change record count and go back to lower number on Display record selection!! Sucks! - public $paginate = array( - //Default records per page. - 'limit' => 20, - 'maxlimit' => 100, - 'page' => 1 - ); - /** * Overrides parent beforeFilter to verify that Session contains the correct API settings. * @@ -404,13 +395,10 @@ public function removeSubscriber() */ public function groupOwner() { - $this->set('title', _txt('pl.grouperlite.title.groupowner')); - //Set initial settings for pagination + //Set initial setting $scope = [ - 'userId' => $this->userId, - 'page' => ($this->passedArgs['page'] ?? $this->paginate['page']), - 'limit' => ($this->passedArgs['limit'] ?? $this->paginate['limit']), + 'userId' => $this->userId ]; if (isset($this->request->data['search']) || isset($this->request->query['search'])) { @@ -428,7 +416,7 @@ public function groupOwner() $scope['searchcriteria'] = $searchCriteria; $scope['searchpage'] = 'ownerGroups'; - $data = $this->Paginator->paginate('GrouperGroup', $scope); + $data = $this->GrouperGroup->getSearchedGroups($scope); $this->set('groupsowners', $data); @@ -443,7 +431,7 @@ public function groupOwner() try { $scope['method'] = 'ownerGroups'; - $data = $this->Paginator->paginate('GrouperGroup', $scope); + $data = $this->GrouperGroup->ownerGroups($scope); $this->set('groupsowners', $data); @@ -479,13 +467,9 @@ public function groupOwner() */ public function groupMember() { - $this->set('title', _txt('pl.grouperlite.title.groupmember')); - - //Set initial settings for pagination + //Set initial setting $scope = [ - 'userId' => $this->userId, - 'page' => ($this->passedArgs['page'] ?? $this->paginate['page']), - 'limit' => ($this->passedArgs['limit'] ?? $this->paginate['limit']), + 'userId' => $this->userId ]; if (isset($this->request->data['search']) || isset($this->request->query['search'])) { @@ -504,7 +488,7 @@ public function groupMember() $scope['searchpage'] = 'filteredMemberOfGroups'; $scope['ContainsWG'] = true; - $data = $this->Paginator->paginate('GrouperGroup', $scope); + $data = $this->GrouperGroup->getSearchedGroups($scope); $finalData = $this->breakoutGroups($data); @@ -524,7 +508,7 @@ public function groupMember() //Add setting for Group Membership $scope['method'] = 'filteredMemberOfGroups'; - $data = $this->Paginator->paginate('GrouperGroup', $scope); + $data = $this->GrouperGroup->filteredMemberOfGroups($scope); $finalData = $this->breakoutGroups($data); @@ -558,14 +542,10 @@ public function groupMember() */ public function groupOptin() { - $this->set('title', _txt('pl.grouperlite.title.groupoptin')); - - //Set initial settings for pagination + //Set initial setting $scope = [ - 'userId' => $this->userId, - 'page' => ($this->passedArgs['page'] ?? $this->paginate['page']), - 'limit' => ($this->passedArgs['limit'] ?? $this->paginate['limit']), + 'userId' => $this->userId ]; if (isset($this->request->data['search']) || isset($this->request->query['search'])) { @@ -583,7 +563,7 @@ public function groupOptin() $scope['searchcriteria'] = $searchCriteria; $scope['searchpage'] = 'optinGroups'; - $data = $this->Paginator->paginate('GrouperGroup', $scope); + $data = $this->GrouperGroup->getSearchedGroups($scope); $this->set('groupoptins', $data); @@ -600,7 +580,7 @@ public function groupOptin() //Add settings for optinGroups $scope['method'] = 'optinGroups'; - $data = $this->Paginator->paginate('GrouperGroup', $scope); + $data = $this->GrouperGroup->optinGroups($scope); $this->set('groupoptins', $data); @@ -624,6 +604,7 @@ public function groupOptin() $this->set('config', $config); } + /** * Create a new Grouper Group via Grouper Template * Note: This is tightly coupled code to requirements, so view is hardcoded to reflect current reqs. Will need @@ -653,61 +634,6 @@ public function groupCreateTemplate() $this->set('title', _txt('pl.grouperlite.title.templatecreate')); } - /** - * ======================== NOT BEING USED ======================== - * - * Delete a Grouper Group via Grouper Template - */ - public function groupDeleteTemplate() - { - if (!$this->GrouperGroup->deleteGroupWithTemplate($this->userId, $this->request->data)) { - $this->Flash->set("Error in deleting group!", array('key' => 'error')); - return $this->redirect(array('action' => 'groupoptin')); - } - - $this->set('title', _txt('pl.grouperlite.title.templatecreate')); - } - - /** - * ======================== NOT BEING USED ======================== - * - * @return CakeResponse|void|null - * @deprecated - * - */ - public function groupCreate() - { - if ($this->request->is('post')) { - if (!$this->GrouperGroup->createUpdateGroup($this->userId, $this->request->data)) { - $this->Flash->set("Error in creating group!", array('key' => 'error')); - } else { - $this->Flash->set("Your Group has been created!", array('key' => 'success')); - } - return $this->redirect(array('action' => 'groupOwner')); - } - - $this->set('title', _txt('pl.grouperlite.title.groupcreate')); - $this->set('grouperstems', $this->GrouperGroup->getOwnedStems($this->userId)); - } - - - /** - * ======================== NOT BEING USED ======================== - * - * @return CakeResponse|null - */ - public function groupDelete() - { - if (!$this->GrouperGroup->deleteGroup($this->userId, $this->request->data)) { - $this->Flash->set("Error in deleting group!", array('key' => 'error')); - } else { - $this->Flash->set("Your Group has been deleted!", array('key' => 'success')); - } - - $this->set('grouperstems', $this->GrouperGroup->getOwnedStems($this->userId)); - return $this->redirect(array('action' => 'groupOwner')); - } - /** * Process to join a group displayed on the "Optin" page @@ -789,18 +715,18 @@ function isAuthorized() //TODO - This is needed for my dev enviro since I do not log in via I2 IdP // BEGIN =============================================== - /* + if ($this->Session->check('Auth.User.username')) { $this->userId = $this->Session->read('Auth.User.username'); } - */ + // END =============================================== //TODO - Need to make the following code configurable in getting the user ID. In this case the code is // specific to the needs of I2. // BEGIN =============================================== - + /* $uid=$this->Session->read('Auth.User.co_person_id'); $username=$this->Session->read('Auth.User.username'); error_log("HUBING ================ " . $username); @@ -839,7 +765,7 @@ function isAuthorized() } else { $this->userId = $this->getUserId($uid); $this->Session->write('Plugin.Grouper.UserId', $this->userId); - } + } */ // END =============================================== @@ -858,9 +784,6 @@ function isAuthorized() $p['findSubscriber'] = true; $p['removeSubscriber'] = true; $p['groupoptin'] = true; - $p['emaillistsoptin'] = true; - $p['emaillistsmember'] = true; - $p['emaillistsmanage'] = true; $p['groupcreate'] = true; $p['groupdelete'] = true; $p['joingroup'] = true; @@ -872,137 +795,6 @@ function isAuthorized() return ($p[$this->action]); } - public function emaillistsOptin() - { - $this->set('title', _txt('pl.grouperlite.title.emaillists-join')); - - //Set initial settings for pagination - $scope = [ - 'userId' => $this->userId, - 'page' => ($this->passedArgs['page'] ?? $this->paginate['page']), - 'limit' => ($this->passedArgs['limit'] ?? $this->paginate['limit']), - ]; - - 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); - - } 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)); - $this->set('isGrouperVisible', $this->GrouperGroup->isGrouperVisible($this->userId)); - } - - public function emaillistsMember() - { - $this->set('title', _txt('pl.grouperlite.title.emaillists-member')); - - //Set initial settings for pagination - $scope = [ - 'userId' => $this->userId, - 'page' => ($this->passedArgs['page'] ?? $this->paginate['page']), - 'limit' => ($this->passedArgs['limit'] ?? $this->paginate['limit']), - ]; - - 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'] = 'filteredMemberOfEmails'; - $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("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); - - } 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)); - $this->set('isTemplateUser', $this->GrouperGroup->isTemplateUser($this->userId)); - $this->set('isGrouperVisible', $this->GrouperGroup->isGrouperVisible($this->userId)); - } - - public function emaillistsManage() - { - $this->set('title', _txt('pl.grouperlite.title.emaillists-manage')); - // mock data - $this->set('group', array( - 'member' => true, - 'name' => 'Email List 1', - 'domain' => 'internet2', - 'description' => 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.', - 'enabled' => 'T' - )); - - $this->set('isuserowner', $this->GrouperGroup->isUserOwner($this->userId)); - $this->set('isTemplateUser', $this->GrouperGroup->isTemplateUser($this->userId)); - $this->set('isGrouperVisible', $this->GrouperGroup->isGrouperVisible($this->userId)); - } - private function getUserId($id) { diff --git a/Model/GrouperGroup.php b/Model/GrouperGroup.php index 2a390d1..90ee0f7 100644 --- a/Model/GrouperGroup.php +++ b/Model/GrouperGroup.php @@ -171,6 +171,7 @@ private function initApi() } /** + * NOT BEING USED * Listing of members in an email group * * @param array $conditions Listing of conditions for display of records, including UserId @@ -178,27 +179,27 @@ private function initApi() * @throws GrouperLiteException * */ - public function filteredMemberOfEmails(array $conditions) - { - $this->initApi(); - - 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]); - } - } - return array_values($memberOfEmails); - - } catch (Exception $e) { - CakeLog::write('error', __METHOD__ . ': An error occurred'); - throw $e; - } - - } +// public function filteredMemberOfEmails(array $conditions) +// { +// $this->initApi(); +// +// 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]); +// } +// } +// return array_values($memberOfEmails); +// +// } catch (Exception $e) { +// CakeLog::write('error', __METHOD__ . ': An error occurred'); +// throw $e; +// } +// +// } /** * Return all Groups that a User belongs to in Grouper. @@ -234,7 +235,8 @@ public function filteredMemberOfGroups(array $conditions) } } - return array_values($memberOfGroups); + $groupResults = array_values($memberOfGroups); + return $this->getFriendlyWorkingGroupName($groupResults, 'member'); } catch (Exception $e) { CakeLog::write('error', __METHOD__ . ': An error occurred'); @@ -330,7 +332,8 @@ public function ownerGroups(array $conditions) $this->initApi(); try { - return $this->grouperAPI->getOwnedGroups($conditions); + $resultSet = $this->grouperAPI->getOwnedGroups($conditions); + return $this->getFriendlyName(array_values($resultSet)); } catch (Exception $e) { CakeLog::write('error', __METHOD__ . ': An error occurred'); @@ -460,9 +463,8 @@ public function optinGroups(array $conditions) } } } - //$finalSet = $this->paginateRecords($joinOrLeave, $conditions); - return array_values($joinOrLeave); + return $this->getFriendlyName(array_values($joinOrLeave)); } catch (Exception $e) { CakeLog::write('error', __METHOD__ . ': An error occurred'); @@ -600,56 +602,19 @@ public function getSearchedGroups(array $conditions) } } - return $returnResults; - - } catch (Exception $e) { - CakeLog::write('error', __METHOD__ . ': An error occurred'); - throw $e; - } - } - - /** - * Method needed to support Pagination - * Adjusted to fit the data source being the Grouper API vs DB calls - * - * @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']; - - $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['']) && $conditions['getSearchedGroups']){ + return $this->getFriendlyWorkingGroupName($returnResults, 'member'); } else { - if (isset($conditions['ContainsWG']) && $method == 'getSearchedGroups') { - $friendlyResults = $this->getFriendlyWorkingGroupName($resultSet, 'member'); - } elseif ($method == 'filteredMemberOfGroups') { - $friendlyResults = $this->getFriendlyWorkingGroupName($resultSet, 'member'); - } else { - $friendlyResults = $this->getFriendlyName(array_values($resultSet)); - } + return $returnResults; } - return $this->paginateRecords($friendlyResults, $conditions); } catch (Exception $e) { CakeLog::write('error', __METHOD__ . ': An error occurred'); throw $e; } - } + /** * Return array of Working Groups for display on coManage site. * Logic is for each WG to have one key=>value of main WG name, then array of all associated @@ -812,238 +777,4 @@ private function getFriendlyName(array $groups) return $groups; } - /** - * Parses returned records to display only requested records for pagination. - * - * @param array $recSet All Grouper Records associated to User's request - * @param array $conditions Listing of conditions for display of records with pagination - * @return array Records requested by user with pagination support - * - */ - private function paginateRecords(array $recSet, array $conditions) - { - - //set for pagination record count - $this->totalRecords = count($recSet); - - //Return all, if requested - if (strtolower($conditions['limit']) == 'all') { - return $recSet; - } - - //Now slice recordset to return correct set of records. - $page = $conditions['page'] - 1; - $limit = $conditions['limit']; - if ($page == 0) { - $start = 0; - } else { - $start = $page * $limit; - } - $end = $start + $limit; - - return array_slice($recSet, $start, $end); - } - - /** - * Needed method to support Cake's pagination in the views - * - * @param null $conditions Listing of conditions for display of records with pagination - * @param int $recursive - * @param array $extra - * @return int Total number of Grouper Records returned by Grouper API call - * - */ - public function paginateCount($conditions = null, $recursive = 0, $extra = array()) - { - return $this->totalRecords; - } - - /** - * ======================== NOT BEING USED ======================== - * - * This is specifically for email listings only tabs/pages, that are now not being used. - * - * Process that parses the email list and makes it more user friendly - * @lists. - * - * @param array $groups - Array of email lists - * @param $method - User who is accessing, if plain member remove admin and owner email lists. - * @return array - Array of friendly email lists - */ - private function getFriendlyEmailName(array $groups, $method) - { - - $arrayIndex = 0; - foreach ($groups as &$group) { - 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; - } - - /** - * ======================== NOT BEING USED ======================== - * - * Used to be used for Grouper group information page. leaving in case want to reincorporate. - * - * 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 A set of attributes associated to a specific Grouper Group - * @throws GrouperLiteException - */ - public function groupDescriptions(string $groupName) - { - $this->initApi(); - - try { - $args = array(); - $args['groupName'] = $groupName; - - $groupDescription = $this->grouperAPI->getGrouperGroupInfo($args); - $groupDescription[0]['friendlyName'] = $groupDescription[0]['displayName']; - - return $groupDescription; - - } catch (Exception $e) { - CakeLog::write('error', __METHOD__ . ': An error occurred'); - throw $e; - } - - } - - /** - * ======================== NOT BEING USED ======================== - * - * 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) - { - $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]); - } - } - - return array_values($allGroups); - - } catch (Exception $e) { - CakeLog::write('error', __METHOD__ . ': An error occurred'); - throw $e; - } - } - - /** - * ======================== NOT BEING USED ======================== - * - * Delete a Grouper Group using the Template methodology in Grouper - * - * @param string $userId Id of User - * @param array $groupData Data needed to delete a Grouper Group via Template - * @return bool True if successfully deleted record - * @throws GrouperLiteException - * - */ - public function deleteGroupWithTemplate(string $userId, array $groupData) - { - $this->initApi(); - - try { - $args = array(); - $args['userId'] = $userId; - $args['workingGroupExt'] = $groupData['workingGroupExt']; - - // Reset Session variable that shows if User is an owner or not - $this->resetUserOwner(); - - return $this->grouperAPI->deleteGroupWithTemplate($args); - - } catch (Exception $e) { - CakeLog::write('error', __METHOD__ . ': An error occurred'); - throw $e; - } - - } - - /** - * ======================== NOT BEING USED ======================== - * - * Creates/Updates a new Grouper Group not WG Template related - * - * @param string $userId Id of user - * @param array $data Data from form to Save in Grouper as a Group - * @return bool True if saved | False if already created - * @throws GrouperLiteException - * - */ - public function createUpdateGroup(string $userId, array $data) - { - $this->initApi(); - - try { - $args = $data; - $args['userId'] = $userId; - - // Reset Session variable that shows if User is an owner or not - $this->resetUserOwner(); - - return $this->grouperAPI->createUpdateGroup($args); - - } catch (Exception $e) { - CakeLog::write('error', __METHOD__ . ': An error occurred'); - throw $e; - } - } - - /** - * ======================== NOT BEING USED ======================== - * - * Get Grouper Stems where User has authority to create a Grouper Group - * - * @param string $userId Id of User - * @return array Stem records - * @throws GrouperLiteException - */ - public function getOwnedStems(string $userId) - { - $this->initApi(); - - try { - $args = array(); - $args['userId'] = $userId; - - return $this->grouperAPI->getOwnedStems($args); - - } catch (Exception $e) { - CakeLog::write('error', __METHOD__ . ': An error occurred'); - throw $e; - } - } }