From 707895b1c7f0dc30e71344eb0d5f917e1798487a Mon Sep 17 00:00:00 2001 From: Axel Stohn Date: Sat, 19 Mar 2022 10:26:56 -0700 Subject: [PATCH] Delete and Add members --- Controller/GrouperGroupsController.php | 117 +++++-- Lib/GrouperApiAccess.php | 130 ++++--- Model/GrouperGroup.php | 456 +++++++++++++------------ 3 files changed, 397 insertions(+), 306 deletions(-) diff --git a/Controller/GrouperGroupsController.php b/Controller/GrouperGroupsController.php index eccc6e6..263381a 100644 --- a/Controller/GrouperGroupsController.php +++ b/Controller/GrouperGroupsController.php @@ -56,7 +56,8 @@ class GrouperGroupsController extends GrouperLiteAppController * @return CakeResponse|void|null * */ - public function beforeFilter() { + public function beforeFilter() + { parent::beforeFilter(); //Need to find which plugin instance choosing, if more than one from cm_co_grouper_lites @@ -82,7 +83,8 @@ public function beforeFilter() { /** * Adding Grouper Conn info to SESSION for use in Lib/GrouperApiAccess.php */ - private function setConnection() { + private function setConnection() + { $this->Session->write('Plugin.Grouper.Api.id', $this->passedArgs['glid']); //Now get the setup Dasboard instance from db for connection info. @@ -104,7 +106,8 @@ private function setConnection() { * * @return CakeResponse Redirect to MyMembership page */ - public function index() { + public function index() + { return $this->redirect( array('controller' => 'grouper_groups', 'action' => 'groupmember') ); @@ -116,15 +119,16 @@ public function index() { * Called from all pages via AJAX call * */ - public function groupSubscribers() { + public function groupSubscribers() + { $groupName = urldecode($this->request->query['groupname']); if ($this->request->is('ajax')) { - $ajax = true; + $this->response->disableCache(); } //Need to see if coming from AdHoc or from a WG (Working Group) - if (strpos($groupName, ':') === false ) { + if (strpos($groupName, ':') === false) { $groupNameFormatted = 'ref:incommon-collab:' . $groupName . ':users'; } else { $groupNameFormatted = $groupName; @@ -153,16 +157,17 @@ public function groupSubscribers() { * Called from all pages via AJAX call * */ - public function addSubscriber() { + public function addSubscriber() + { $groupName = urldecode($this->request->query['group']); $addUserId = urldecode($this->request->query['userId']); if ($this->request->is('ajax')) { - $ajax = true; + $this->response->disableCache(); } //Need to see if coming from AdHoc or from a WG (Working Group) - if (strpos($groupName, ':') === false ) { + if (strpos($groupName, ':') === false) { $groupNameFormatted = 'ref:incommon-collab:' . $groupName . ':users'; } else { $groupNameFormatted = $groupName; @@ -175,16 +180,31 @@ public function addSubscriber() { ]; try { - $subscribers = $this->GrouperGroup->addMemberToGroup($scope, $this->userId); + $resultAdd = $this->GrouperGroup->addMemberToGroup($scope, $this->userId); } catch (Exception $e) { CakeLog::write('error', __METHOD__ . ': ' . var_export($e->getMessage(), true)); + $subscribers = 'ERROR'; $this->Flash->set(_txt('pl.grouperlite.message.flash.group-detail-members-failed'), array('key' => 'error')); } - $this->set(compact('subscribers')); - $this->set('_serialize', 'subscribers'); + if ($resultAdd == 'SUCCESS') { + // Do nothing + } elseif ($resultAdd == 'EXCEPTION') { + $this->response->type('json'); + $this->response->statusCode(404); + $this->response->body(json_encode(array('status' => 'ERROR', 'message' => 'EXCEPTION'))); + $this->response->send(); + } else { + $this->response->type('json'); + $this->response->statusCode(401); + $this->response->body(json_encode(array('status' => 'ERROR', 'message' => 'ERROR'))); + $this->response->send(); + } + $this->set(compact('resultAdd')); + $this->set('_serialize', 'resultAdd'); + } /** @@ -192,16 +212,17 @@ public function addSubscriber() { * Called from all pages via AJAX call * */ - public function removeSubscriber() { + public function removeSubscriber() + { $groupName = urldecode($this->request->query['group']); $remUserId = urldecode($this->request->query['userId']); if ($this->request->is('ajax')) { - $ajax = true; + $this->response->disableCache(); } //Need to see if coming from AdHoc or from a WG (Working Group) - if (strpos($groupName, ':') === false ) { + if (strpos($groupName, ':') === false) { $groupNameFormatted = 'ref:incommon-collab:' . $groupName . ':users'; } else { $groupNameFormatted = $groupName; @@ -214,7 +235,7 @@ public function removeSubscriber() { ]; try { - $subscribers = $this->GrouperGroup->removeMemberToGroup($scope, $this->userId); + $resultRemove = $this->GrouperGroup->removeMemberToGroup($scope, $this->userId); } catch (Exception $e) { CakeLog::write('error', __METHOD__ . ': ' . var_export($e->getMessage(), true)); @@ -222,14 +243,23 @@ public function removeSubscriber() { $this->Flash->set(_txt('pl.grouperlite.message.flash.group-detail-members-failed'), array('key' => 'error')); } - $this->set(compact('subscribers')); - $this->set('_serialize', 'subscribers'); + if ($resultRemove == 'SUCCESS') { + // Do nothing + } else { + $this->response->type('json'); + $this->response->statusCode(404); + $this->response->body(json_encode(array('status' => 'ERROR', 'message' => 'ERROR'))); + $this->response->send(); + } + $this->set(compact('resultRemove')); + $this->set('_serialize', 'resultRemove'); } /** * Listing of all Grouper Groups owned/admin by User Or search those Grouper Groups */ - public function groupOwner() { + public function groupOwner() + { $this->set('title', _txt('pl.grouperlite.title.groupowner')); //Set initial settings for pagination @@ -301,7 +331,8 @@ public function groupOwner() { * This includes self-joined Optin Groups, as well as required Groups User cannot leave * */ - public function groupMember() { + public function groupMember() + { $this->set('title', _txt('pl.grouperlite.title.groupmember')); //Set initial settings for pagination @@ -371,7 +402,8 @@ public function groupMember() { /** * Display all Groups a User can Join */ - public function groupOptin() { + public function groupOptin() + { $this->set('title', _txt('pl.grouperlite.title.groupoptin')); @@ -435,7 +467,7 @@ public function groupOptin() { "defaultCollapse" => CakeSession::read('Plugin.Grouper.Api.defaultCollapse'), "adHocHeading" => CakeSession::read('Plugin.Grouper.Api.adHocHeading'), "wgHeading" => CakeSession::read('Plugin.Grouper.Api.wgHeading') - ]; + ]; $this->set('config', $config); } @@ -447,7 +479,8 @@ public function groupOptin() { * Editing via a template will not be supported in this version of the plugin - Bill Kaufman * */ - public function groupCreateTemplate() { + public function groupCreateTemplate() + { if ($this->request->is('post')) { try { $status = $this->GrouperGroup->createGroupWithTemplate($this->userId, $this->request->data); @@ -471,7 +504,8 @@ public function groupCreateTemplate() { * Delete a Grouper Group via Grouper Template * NOT USED IN CODE */ - public function groupDeleteTemplate() { + 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')); @@ -481,12 +515,13 @@ public function groupDeleteTemplate() { } /** + * @return CakeResponse|void|null * @deprecated * NOT USED IN CODE * - * @return CakeResponse|void|null */ - public function groupCreate() { + 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')); @@ -505,7 +540,8 @@ public function groupCreate() { * This method is currently not used. * @return CakeResponse|null */ - public function groupDelete() { + public function groupDelete() + { if (!$this->GrouperGroup->deleteGroup($this->userId, $this->request->data)) { $this->Flash->set("Error in deleting group!", array('key' => 'error')); } else { @@ -522,7 +558,8 @@ public function groupDelete() { * * @return CakeResponse Redirect back to "Optin" page */ - public function joinGroup() { + public function joinGroup() + { if ($this->request->is('post')) { $name = $this->request->data['GroupName']; @@ -548,7 +585,8 @@ public function joinGroup() { * * @return CakeResponse Redirect back to "Member Of" page */ - public function leaveGroup() { + public function leaveGroup() + { if ($this->request->is('post')) { $name = $this->request->data['GroupName']; @@ -581,7 +619,8 @@ public function leaveGroup() { * @return Array Permissions * @since COmanage Registry v3.2.0 */ - function isAuthorized() { + function isAuthorized() + { $roles = $this->Role->calculateCMRoles(); //TODO - This is needed for my dev enviro since I do not log in via I2 IdP @@ -632,7 +671,8 @@ function isAuthorized() { return ($p[$this->action]); } - public function emaillistsOptin() { + public function emaillistsOptin() + { $this->set('title', _txt('pl.grouperlite.title.emaillists-join')); //Set initial settings for pagination @@ -687,7 +727,8 @@ public function emaillistsOptin() { $this->set('isTemplateUser', $this->GrouperGroup->isTemplateUser($this->userId)); } - public function emaillistsMember() { + public function emaillistsMember() + { $this->set('title', _txt('pl.grouperlite.title.emaillists-member')); //Set initial settings for pagination @@ -742,7 +783,8 @@ public function emaillistsMember() { $this->set('isTemplateUser', $this->GrouperGroup->isTemplateUser($this->userId)); } - public function emaillistsManage() { + public function emaillistsManage() + { $this->set('title', _txt('pl.grouperlite.title.emaillists-manage')); // mock data $this->set('group', array( @@ -758,7 +800,8 @@ public function emaillistsManage() { } - private function getUserId($id) { + private function getUserId($id) + { $args = array(); $args['conditions']['Identifier.co_person_id'] = $id; $args['conditions']['Identifier.type'] = 'I2CollabPN'; @@ -779,7 +822,8 @@ private function getUserId($id) { * @return array[] * */ - private function breakoutGroups(array $recordSet, $type = 'basic') { + private function breakoutGroups(array $recordSet, $type = 'basic') + { //TODO - May move this logic down into the GrouperGroup model file, once all is agreed upon. $wgData = array(); $notWGData = array(); @@ -834,7 +878,8 @@ private function breakoutGroups(array $recordSet, $type = 'basic') { * @return string * */ - private function hackDescription($description) { + private function hackDescription($description) + { //Verify description has period in it. if (strpos($description, ".") === false) { return $description; diff --git a/Lib/GrouperApiAccess.php b/Lib/GrouperApiAccess.php index d52c26c..d6b1d58 100644 --- a/Lib/GrouperApiAccess.php +++ b/Lib/GrouperApiAccess.php @@ -52,7 +52,8 @@ class GrouperApiAccess * * @throws GrouperLiteException If issue with Grouper WS connection */ - public function __construct() { + public function __construct() + { $this->http = new GrouperHTTPWrapper(); @@ -80,7 +81,8 @@ public function __construct() { * @return array Membership records that User is a member of in Grouper * @throws GrouperLiteException */ - public function getGrouperMemberOfGroups(array $queryData) { + public function getGrouperMemberOfGroups(array $queryData) + { //Build request logic $userId = $queryData['userId']; @@ -109,7 +111,8 @@ public function getGrouperMemberOfGroups(array $queryData) { * @return bool True if join or leave successful, False if not * @throws GrouperLiteException */ - public function grouperGroupLeaveOrJoin(array $queryData) { + public function grouperGroupLeaveOrJoin(array $queryData) + { $groupName = $queryData['groupName']; $userId = $queryData['userId']; @@ -172,7 +175,8 @@ public function grouperGroupLeaveOrJoin(array $queryData) { * @throws GrouperLiteException * */ - public function getOptionalGroups(array $queryData) { + public function getOptionalGroups(array $queryData) + { try { $results = $this->useMembershipUrl($queryData); @@ -195,7 +199,8 @@ public function getOptionalGroups(array $queryData) { * @throws GrouperLiteException * */ - public function getOwnedGroups(array $queryData) { + public function getOwnedGroups(array $queryData) + { try { $queryData['groupType'] = 'admin'; @@ -230,7 +235,8 @@ public function getOwnedGroups(array $queryData) { * @param array $arrTwo * @return array */ - public function removeDuplicates(array $arrOne, array $arrTwo) { + public function removeDuplicates(array $arrOne, array $arrTwo) + { //Determine which array is bigger and use as base $countOne = count($arrOne); @@ -261,7 +267,8 @@ public function removeDuplicates(array $arrOne, array $arrTwo) { * @return array Listing of Members belonging to Grouper Group * @throws GrouperLiteException */ - public function getMembersInGroup(array $queryData) { + public function getMembersInGroup(array $queryData) + { try { //Build request logic @@ -300,16 +307,17 @@ public function getMembersInGroup(array $queryData) { * Add a member to a specific Grouper Group * * @param array $queryData Array of conditions for querying - * @return array Listing of Members belonging to Grouper Group + * @return string Requests success or not * @throws GrouperLiteException */ - public function addMemberToGroup(array $queryData) { + public function addMemberToGroup(array $queryData) + { try { $groupName = $queryData['groupName']; //Build request logic - $usersToShow = array( + $usersToAdd = array( "WsRestAddMemberRequest" => array( "subjectLookups" => array( array("subjectId" => $queryData['addUserId']), @@ -324,7 +332,7 @@ public function addMemberToGroup(array $queryData) { $this->http->setHeader(array('Content-Type' => 'application/json', 'Accept' => 'application/json')); $connectionUrl = "{$this->config['fullUrl']}/groups/$groupName/members"; - $results = $this->http->sendRequest('PUT', $connectionUrl, json_encode($usersToShow)); + $results = $this->http->sendRequest('PUT', $connectionUrl, json_encode($usersToAdd)); // Parse out relevant records to send front end if (isset($results['WsAddMemberResults']['results'][0]['resultMetadata']) && $results['WsAddMemberResults']['results'][0]['resultMetadata'] != NULL) { @@ -335,63 +343,48 @@ public function addMemberToGroup(array $queryData) { throw $e; } - return array(); + return ""; } /** * Remove a member from a specific Grouper Group * * @param array $queryData Array of conditions for querying - * @return array Listing of Members belonging to Grouper Group + * @return string Requests success or not * @throws GrouperLiteException */ - public function removeMemberToGroup(array $queryData) { + public function removeMemberToGroup(array $queryData) + { try { $groupName = $queryData['groupName']; - $remUserId = $queryData['remUserId']; + + //Build request logic + $userToDelete = array( + "WsRestDeleteMemberRequest" => array( + "subjectLookups" => array( + array("subjectId" => $queryData['remUserId']), + ), + "actAsSubjectLookup" => array( + "subjectId" => $queryData['userId'] + ) + ) + ); $this->http->setHeader(array('Content-Type' => 'application/json', 'Accept' => 'application/json')); - $connectionUrl = "{$this->config['fullUrl']}/groups/$groupName/members/$remUserId"; - $results = $this->http->sendRequest('PUT', $connectionUrl); + $connectionUrl = "{$this->config['fullUrl']}/groups/$groupName/members"; + $results = $this->http->sendRequest('POST', $connectionUrl, json_encode($userToDelete)); // Parse out relevant records to send front end - if (isset($results['WsGetMembersResults']['results'][0]['wsSubjects']) && $results['WsGetMembersResults']['results'][0]['wsSubjects'] != NULL) { - return $results['WsGetMembersResults']['results'][0]['wsSubjects']; + if (isset($results['WsDeleteMemberResults']['results'][0]['resultMetadata']) && $results['WsDeleteMemberResults']['results'][0]['resultMetadata'] != NULL) { + return $results['WsDeleteMemberResults']['results'][0]['resultMetadata']['resultCode']; } } catch (Exception $e) { CakeLog::write('error', __METHOD__ . ': An error occurred'); throw $e; } - return array(); - } - - /** - * ======================== NOT BEING USED ======================== - * - * Potential use was for creating adhoc group by a user, not associated to WG. - * - * Gets all Stems/Folders where User is admin/owner - * - * @param array $queryData Array of conditions for querying - * @return array Array of Stems/Folders from Grouper - * @throws GrouperLiteException - */ - public function getOwnedStems(array $queryData) { - $queryData['groupType'] = 'stemAdmin'; - - try { - $results = $this->useMembershipUrl($queryData); - - if (isset($results['WsGetMembershipsResults']['wsStems']) && $results['WsGetMembershipsResults']['wsStems'] != NULL) { - return $results['WsGetMembershipsResults']['wsStems']; - } - } catch (Exception $e) { - CakeLog::write('error', __METHOD__ . ': An error occurred'); - throw $e; - } - return array(); + return ""; } /** @@ -406,7 +399,8 @@ public function getOwnedStems(array $queryData) { * @see getOptOutGroups() * @see getOwnedGroups() */ - private function useMembershipUrl(array $queryData) { + private function useMembershipUrl(array $queryData) + { $groupType = $queryData['groupType']; $userId = $queryData['userId']; @@ -461,7 +455,8 @@ private function useMembershipUrl(array $queryData) { * @throws GrouperLiteException * */ - public function createGroupWithTemplate(array $queryData) { + public function createGroupWithTemplate(array $queryData) + { //Currently, only supporting create group, need to test if update a group will work! $data = $queryData['data']; @@ -544,7 +539,8 @@ public function createGroupWithTemplate(array $queryData) { * @throws GrouperLiteException * */ - public function deleteGroupWithTemplate(array $queryData) { + public function deleteGroupWithTemplate(array $queryData) + { $workingGroupExt = $queryData['workingGroupExt']; $userId = $queryData['userId']; @@ -598,7 +594,8 @@ public function deleteGroupWithTemplate(array $queryData) { * @return bool True if added or updated successful * @throws GrouperLiteException */ - public function createUpdateGroup(array $queryData) { + public function createUpdateGroup(array $queryData) + { $groupName = htmlentities($queryData['name']); $stemName = htmlentities($queryData['stem']); @@ -660,7 +657,8 @@ public function createUpdateGroup(array $queryData) { * @return array Record of Grouper attributes for given GroupName * @throws GrouperLiteException */ - public function getGrouperGroupInfo(array $queryData) { + public function getGrouperGroupInfo(array $queryData) + { $groupName = $queryData['groupName']; $groupInfo = array(); @@ -701,4 +699,32 @@ public function getGrouperGroupInfo(array $queryData) { } } + /** + * ======================== NOT BEING USED ======================== + * + * Potential use was for creating adhoc group by a user, not associated to WG. + * + * Gets all Stems/Folders where User is admin/owner + * + * @param array $queryData Array of conditions for querying + * @return array Array of Stems/Folders from Grouper + * @throws GrouperLiteException + */ + public function getOwnedStems(array $queryData) + { + $queryData['groupType'] = 'stemAdmin'; + + try { + $results = $this->useMembershipUrl($queryData); + + if (isset($results['WsGetMembershipsResults']['wsStems']) && $results['WsGetMembershipsResults']['wsStems'] != NULL) { + return $results['WsGetMembershipsResults']['wsStems']; + } + } catch (Exception $e) { + CakeLog::write('error', __METHOD__ . ': An error occurred'); + throw $e; + } + return array(); + } + } diff --git a/Model/GrouperGroup.php b/Model/GrouperGroup.php index 3b32fbd..980259f 100644 --- a/Model/GrouperGroup.php +++ b/Model/GrouperGroup.php @@ -75,7 +75,8 @@ class GrouperGroup extends GrouperLiteAppModel * @see GrouperGroup::resetUserOwner() * */ - public function isUserOwner(string $userId) { + public function isUserOwner(string $userId) + { if (CakeSession::check('Plugin.Grouper.isUserOwner')) { return CakeSession::read('Plugin.Grouper.isUserOwner'); } @@ -109,7 +110,8 @@ public function isUserOwner(string $userId) { * so error was being thrown. * Now will call this before each function call to verify set. */ - private function initApi() { + private function initApi() + { if ($this->grouperAPI == null) { $this->grouperAPI = new GrouperApiAccess(); } @@ -123,7 +125,8 @@ private function initApi() { * @throws GrouperLiteException * */ - public function filteredMemberOfEmails(array $conditions) { + public function filteredMemberOfEmails(array $conditions) + { $this->initApi(); try { @@ -153,7 +156,8 @@ public function filteredMemberOfEmails(array $conditions) { * @throws GrouperLiteException * */ - public function filteredMemberOfGroups(array $conditions) { + public function filteredMemberOfGroups(array $conditions) + { $this->initApi(); try { @@ -193,7 +197,8 @@ public function filteredMemberOfGroups(array $conditions) { * @throws GrouperLiteException * */ - private function memberOfGroups(array $conditions) { + private function memberOfGroups(array $conditions) + { try { return $this->grouperAPI->getGrouperMemberOfGroups($conditions); @@ -204,35 +209,6 @@ private function memberOfGroups(array $conditions) { } } - /** - * ======================== 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; - } - - } /** * Process for User to Leave a Group @@ -243,7 +219,8 @@ public function groupDescriptions(string $groupName) { * @throws GrouperLiteException * */ - public function leaveGroup(string $userId, string $groupName) { + public function leaveGroup(string $userId, string $groupName) + { $this->initApi(); try { @@ -269,7 +246,8 @@ public function leaveGroup(string $userId, string $groupName) { * @throws GrouperLiteException * */ - public function joinGroup(string $userId, string $groupName) { + public function joinGroup(string $userId, string $groupName) + { $this->initApi(); try { @@ -294,7 +272,8 @@ public function joinGroup(string $userId, string $groupName) { * @throws GrouperLiteException * */ - public function ownerGroups(array $conditions) { + public function ownerGroups(array $conditions) + { $this->initApi(); try { @@ -317,7 +296,8 @@ public function ownerGroups(array $conditions) { * @throws GrouperLiteException Captured in Controller * */ - public function membersInGroup(array $conditions, string $userId) { + public function membersInGroup(array $conditions, string $userId) + { $this->initApi(); $conditions['userId'] = $userId; @@ -325,7 +305,7 @@ public function membersInGroup(array $conditions, string $userId) { try { $groupMembers = $this->grouperAPI->getMembersInGroup($conditions); - if (count($groupMembers) < 1){ + if (count($groupMembers) < 1) { return $groupMembers; } @@ -349,23 +329,20 @@ public function membersInGroup(array $conditions, string $userId) { * * @param array $conditions Listing of conditions for display of records * @param string $userId Id of User - * @return array Listing of members in requested Grouper Group + * @return string success of Request * @throws GrouperLiteException Captured in Controller * */ - public function addMemberToGroup(array $conditions, string $userId) { + public function addMemberToGroup(array $conditions, string $userId) + { $this->initApi(); $conditions['userId'] = $userId; try { - $groupMembers = $this->grouperAPI->addMemberToGroup($conditions); + $resultAdd = $this->grouperAPI->addMemberToGroup($conditions); - if ($groupMembers != 'SUCCESS'){ - return []; - } - - return $groupMembers; + return $resultAdd; } catch (Exception $e) { CakeLog::write('error', __METHOD__ . ': An error occurred'); @@ -378,23 +355,20 @@ public function addMemberToGroup(array $conditions, string $userId) { * * @param array $conditions Listing of conditions for display of records * @param string $userId Id of User - * @return array Listing of members in requested Grouper Group + * @return string success of Request * @throws GrouperLiteException Captured in Controller * */ - public function removeMemberToGroup(array $conditions, string $userId) { + public function removeMemberToGroup(array $conditions, string $userId) + { $this->initApi(); $conditions['userId'] = $userId; try { - $groupMembers = $this->grouperAPI->removeMemberToGroup($conditions); - - if (count($groupMembers) < 1){ - return $groupMembers; - } + $resultRemove = $this->grouperAPI->removeMemberToGroup($conditions); - return $groupMembers['resultCode']; + return $resultRemove; } catch (Exception $e) { CakeLog::write('error', __METHOD__ . ': An error occurred'); @@ -402,37 +376,6 @@ public function removeMemberToGroup(array $conditions, string $userId) { } } - /** - * ======================== 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; - } - - } /** * Return all Groups the User can JOIN @@ -443,7 +386,8 @@ public function optinEmailGroups(array $conditions) { * @return array Listing of Optin groups available in Grouper * @throws GrouperLiteException Captured in Controller */ - public function optinGroups(array $conditions) { + public function optinGroups(array $conditions) + { $this->initApi(); try { @@ -480,7 +424,8 @@ public function optinGroups(array $conditions) { * @return string T for True and F for False * @throws GrouperLiteException */ - public function isTemplateUser(string $userId) { + public function isTemplateUser(string $userId) + { if (CakeSession::check('Plugin.Grouper.isTemplateUser')) { return CakeSession::read('Plugin.Grouper.isTemplateUser'); } @@ -525,7 +470,8 @@ public function isTemplateUser(string $userId) { * @throws GrouperLiteException * */ - public function createGroupWithTemplate(string $userId, array $groupData) { + public function createGroupWithTemplate(string $userId, array $groupData) + { $this->initApi(); try { @@ -564,96 +510,13 @@ public function createGroupWithTemplate(string $userId, array $groupData) { * * @see GrouperGroup::isUserOwner() */ - private function resetUserOwner() { + private function resetUserOwner() + { if (CakeSession::check('Plugin.Grouper.isUserOwner')) { CakeSession::delete('Plugin.Grouper.isUserOwner'); } } - /** - * ======================== 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; - } - } - /** * Search for Groups/Lists related to Search term. * @@ -665,7 +528,8 @@ public function getOwnedStems(string $userId) { * @return array Records that meet search criteria * @throws Exception Captured in Controller */ - public function getSearchedGroups(array $conditions) { + public function getSearchedGroups(array $conditions) + { $this->initApi(); try { @@ -700,7 +564,8 @@ public function getSearchedGroups(array $conditions) { * @throws Exception Captured in Controller * */ - public function paginate($conditions) { + public function paginate($conditions) + { try { //Pull out the method that should be run. $method = $conditions['method']; @@ -730,44 +595,6 @@ public function paginate($conditions) { } - /** - * ======================== 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; - } - /** * 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 @@ -780,7 +607,8 @@ private function getFriendlyEmailName(array $groups, $method) { * @return array Listing of Groups in WG format for display * */ - private function getFriendlyWorkingGroupName(array $groups, $method) { + private function getFriendlyWorkingGroupName(array $groups, $method) + { $arrayIndex = 0; $workingGroups = array(); @@ -897,7 +725,8 @@ private function getFriendlyWorkingGroupName(array $groups, $method) { * @return array Same result set with added param for friendly name * */ - private function getFriendlyName(array $groups) { + private function getFriendlyName(array $groups) + { //According to Jira ICPCO-200, will only display the last section of the stem in UI and then hover over for rest. foreach ($groups as &$group) { @@ -916,7 +745,8 @@ private function getFriendlyName(array $groups) { * @return array Records requested by user with pagination support * */ - private function paginateRecords(array $recSet, array $conditions) { + private function paginateRecords(array $recSet, array $conditions) + { //set for pagination record count $this->totalRecords = count($recSet); @@ -948,7 +778,197 @@ private function paginateRecords(array $recSet, array $conditions) { * @return int Total number of Grouper Records returned by Grouper API call * */ - public function paginateCount($conditions = null, $recursive = 0, $extra = array()) { + 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; + } + } }