From a13eba9963f0e14d3d690e82cf4d68f496cd0c2e Mon Sep 17 00:00:00 2001 From: axman Date: Thu, 4 Mar 2021 13:36:20 -0700 Subject: [PATCH] changes needed to pull members for a group --- Controller/GrouperGroupsController.php | 29 +++++++++++++++- Lib/GrouperApiAccess.php | 47 +++++++++++++++++++++++--- Lib/lang.php | 1 + Model/GrouperGroup.php | 28 ++++++++++++--- 4 files changed, 96 insertions(+), 9 deletions(-) diff --git a/Controller/GrouperGroupsController.php b/Controller/GrouperGroupsController.php index 3f91687..3df5aca 100644 --- a/Controller/GrouperGroupsController.php +++ b/Controller/GrouperGroupsController.php @@ -125,6 +125,32 @@ public function groupInfo() { } } + /** + * Show all members of group in Grouper Group detail page + * Called from method GroupInfo + * + */ + public function membersInGroup() { + $groupName = urldecode($this->request->query['groupname']); + + //Set initial + $scope = [ + 'groupName' => $groupName + ]; + + try { + $details = $this->GrouperGroup->membersInGroup($scope); + $this->set('membersingroup', $details); + + } catch (Exception $e) { + CakeLog::write('error', __METHOD__ . ': ' . var_export($e->getMessage(), true)); + + $this->set('membersingroup', array()); + $this->Flash->set(_txt('pl.grouperlite.message.flash.group-detail-members-failed'), array('key' => 'error')); + } + } + + /** * Listing of all Grouper Groups owned/admin by User Or search those Grouper Groups */ @@ -285,7 +311,7 @@ public function groupOptin() { //TODO - Need to combine this form with code below for groupCreate public function groupCreateForm() { $this->set('title', _txt('pl.grouperlite.title.groupcreate')); - $this->set('grouperstems', $this->GrouperGroup->getOwnerStems($this->userId)); + $this->set('grouperstems', $this->GrouperGroup->getOwnedStems($this->userId)); } public function groupCreate() { @@ -377,6 +403,7 @@ function isAuthorized() { $p['index'] = true; $p['groupinfo'] = true; + $p['membersInGroup'] = true; $p['groupowner'] = true; $p['groupmember'] = true; $p['groupoptin'] = true; diff --git a/Lib/GrouperApiAccess.php b/Lib/GrouperApiAccess.php index fa05bb2..2b70e35 100644 --- a/Lib/GrouperApiAccess.php +++ b/Lib/GrouperApiAccess.php @@ -239,7 +239,7 @@ public function getOptinGroups(array $queryData) { * @throws GrouperLiteException * */ - public function getOwnerGroups(array $queryData) { + public function getOwnedGroups(array $queryData) { $queryData['groupType'] = 'Owner'; try { @@ -255,6 +255,45 @@ public function getOwnerGroups(array $queryData) { return array(); } + /** + * Get members associated to a specific Grouper Group + * + * @param array $queryData Array of conditions for querying + * @return array Listing of Members belonging to Grouper Group + * @throws GrouperLiteException + */ + public function getMembersInGroup(array $queryData) { + + //Build request logic + $usersToShow = array( + "WsRestGetMembersRequest" => array( + "wsGroupLookups" => array( + array("groupName" => $queryData['groupName']) + ), + "subjectAttributeNames" => array( + "name" + ) + ) + ); + + $this->http->setHeader(array('Content-Type' => 'application/json', 'Accept' => 'application/json')); + $connectionUrl = "{$this->config['fullUrl']}/groups"; + + try { + $results = $this->http->sendRequest('POST', $connectionUrl, json_encode($usersToShow)); + + // 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']; + } + } catch (Exception $e) { + CakeLog::write('error', __METHOD__ . ': An error occurred'); + throw $e; + } + + return array(); + } + /** * Gets all Stems/Folders where User is admin/owner * @@ -262,7 +301,7 @@ public function getOwnerGroups(array $queryData) { * @return array Array of Stems/Folders from Grouper * @throws GrouperLiteException */ - public function getOwnerStems(array $queryData) { + public function getOwnedStems(array $queryData) { $queryData['groupType'] = 'StemOwner'; try { @@ -282,8 +321,8 @@ public function getOwnerStems(array $queryData) { * Used for requests made to Membership endpoint in Grouper WS * * @see getOptinGroups() - * @see getOwnerGroups() - * @see getOwnerStems() + * @see getOwnedGroups() + * @see getOwnedStems() * * @param array $queryData Array of conditions for querying * @return array Group records associated to calling method diff --git a/Lib/lang.php b/Lib/lang.php index b464443..82bb406 100644 --- a/Lib/lang.php +++ b/Lib/lang.php @@ -43,6 +43,7 @@ 'pl.grouperlite.message.flash.member-group-failed' => 'Error occurred in viewing groups you are a member, please try again later.', 'pl.grouperlite.message.flash.optin-group-failed' => 'Error occurred in viewing Optin groups, please try again later.', + 'pl.grouperlite.message.flash.group-detail-members-failed' => 'Error in viewing the members of this group, please try again later.', 'pl.grouperlite.table.name' => 'Name', 'pl.grouperlite.table.description' => 'Description', diff --git a/Model/GrouperGroup.php b/Model/GrouperGroup.php index 3326ad3..52bd4cb 100644 --- a/Model/GrouperGroup.php +++ b/Model/GrouperGroup.php @@ -66,7 +66,7 @@ public function isUserOwner(string $userId) { $args = array(); $args['userId'] = $userId; - $ownGroups = $this->grouperAPI->getOwnerGroups($args); + $ownGroups = $this->grouperAPI->getOwnedGroups($args); if (count($ownGroups) > 0) { CakeSession::write('Plugin.Grouper.isUserOwner', 'T'); @@ -290,7 +290,7 @@ public function ownerGroups(array $conditions) { $this->initApi(); try { - $ownGroups = $this->grouperAPI->getOwnerGroups($conditions); + $ownGroups = $this->grouperAPI->getOwnedGroups($conditions); return $this->getFriendlyName($ownGroups); @@ -300,6 +300,26 @@ public function ownerGroups(array $conditions) { } } + /** + * Get members associated to a specific Grouper Group + * + * @param array $conditions Listing of conditions for display of records + * @return array Listing of members in requested Grouper Group + * @throws GrouperLiteException Captured in Controller + * + */ + public function membersInGroup(array $conditions) { + $this->initApi(); + + try { + return $this->grouperAPI->getMembersInGroup($conditions); + + } catch (Exception $e) { + CakeLog::write('error', __METHOD__ . ': An error occurred'); + throw $e; + } + } + /** * Return all Groups the User can JOIN * Get all Groups with Optin attribute set and display ones User can join. @@ -389,14 +409,14 @@ private function resetUserOwner() { * @return array Stem records * @throws GrouperLiteException */ - public function getOwnerStems(string $userId) { + public function getOwnedStems(string $userId) { $this->initApi(); try { $args = array(); $args['userId'] = $userId; - return $this->grouperAPI->getOwnerStems($args); + return $this->grouperAPI->getOwnedStems($args); } catch (Exception $e) { CakeLog::write('error', __METHOD__ . ': An error occurred');