Skip to content

Commit

Permalink
changes needed to pull members for a group
Browse files Browse the repository at this point in the history
  • Loading branch information
axel committed Mar 4, 2021
1 parent e49555a commit a13eba9
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 9 deletions.
29 changes: 28 additions & 1 deletion Controller/GrouperGroupsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -377,6 +403,7 @@ function isAuthorized() {

$p['index'] = true;
$p['groupinfo'] = true;
$p['membersInGroup'] = true;
$p['groupowner'] = true;
$p['groupmember'] = true;
$p['groupoptin'] = true;
Expand Down
47 changes: 43 additions & 4 deletions Lib/GrouperApiAccess.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -255,14 +255,53 @@ 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
*
* @param array $queryData Array of conditions for querying
* @return array Array of Stems/Folders from Grouper
* @throws GrouperLiteException
*/
public function getOwnerStems(array $queryData) {
public function getOwnedStems(array $queryData) {
$queryData['groupType'] = 'StemOwner';

try {
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions Lib/lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
28 changes: 24 additions & 4 deletions Model/GrouperGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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);

Expand All @@ -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.
Expand Down Expand Up @@ -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');
Expand Down

0 comments on commit a13eba9

Please sign in to comment.