Skip to content

Commit

Permalink
fixes for ICPCO-169,170 and 172
Browse files Browse the repository at this point in the history
  • Loading branch information
axel committed Oct 8, 2021
1 parent 4a3e1fc commit d3fe3fb
Show file tree
Hide file tree
Showing 8 changed files with 86 additions and 85 deletions.
78 changes: 22 additions & 56 deletions Controller/GrouperGroupsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,66 +107,32 @@ public function index() {
);
}

/**
* Display of Grouper Group Information, such as Group Properties, Members and Attributes
*
*/
public function groupInfo() {
$name = urldecode($this->request->query['groupname']);

$this->set('title', _txt('pl.grouperlite.title.groupinfo'));

try {
$details = $this->GrouperGroup->groupDescriptions($name);
$this->set('groupergroupsdetail', $details[0]);

} catch (Exception $e) {
CakeLog::write('error', __METHOD__ . ': ' . var_export($e->getMessage(), true));

$this->set('groupergroupsdetail', array());
$this->Flash->set(_txt('pl.grouperlite.message.flash.info-group-failed'), array('key' => 'error'));
}

try {
$groupMembers = $this->membersInGroup();
$this->set('groupergroupssubscribers', $groupMembers);
} catch (Exception $e) {
CakeLog::write('error', __METHOD__ . ': ' . var_export($e->getMessage(), true));

$this->set('groupergroupssubscribers', array());
$this->Flash->set(_txt('pl.grouperlite.message.flash.group-detail-members-failed'), array('key' => 'error'));
}

$this->set('isuserowner', $this->GrouperGroup->isUserOwner($this->userId));
$this->set('grouperbaseurl', $this->Session->read('Plugin.Grouper.Api.grouperUrl'));
}

/**
* 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
];

$details = [];

try {
$details = $this->GrouperGroup->membersInGroup($scope);

} catch (Exception $e) {
CakeLog::write('error', __METHOD__ . ': ' . var_export($e->getMessage(), true));

$this->Flash->set(_txt('pl.grouperlite.message.flash.group-detail-members-failed'), array('key' => 'error'));
}

return $details;
}
// public function membersInGroup() {
// $groupName = urldecode($this->request->query['groupname']);
//
// //Set initial
// $scope = [
// 'groupName' => $groupName
// ];
//
// $details = [];
//
// try {
// $details = $this->GrouperGroup->membersInGroup($scope, $this->userId);
//
// } catch (Exception $e) {
// CakeLog::write('error', __METHOD__ . ': ' . var_export($e->getMessage(), true));
//
// $this->Flash->set(_txt('pl.grouperlite.message.flash.group-detail-members-failed'), array('key' => 'error'));
// }
//
// return $details;
// }

/**
* Show all members of group in Grouper Group detail page
Expand All @@ -193,7 +159,7 @@ public function groupSubscribers() {
];

try {
$subscribers = $this->GrouperGroup->membersInGroup($scope);
$subscribers = $this->GrouperGroup->membersInGroup($scope, $this->userId);

} catch (Exception $e) {
CakeLog::write('error', __METHOD__ . ': ' . var_export($e->getMessage(), true));
Expand Down
43 changes: 43 additions & 0 deletions Lib/GrouperApiAccess.php
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,16 @@ public function removeDuplicates(array $arrOne, array $arrTwo) {
*/
public function getMembersInGroup(array $queryData) {

// First verify that user has read access to group
if ($this->verifyPrivileges($queryData, 'read') === false) {
return array(
array(
"sourceId" => "ldap",
"name" => "You do not have access to memberships"
)
);
}

//Build request logic
$usersToShow = array(
"WsRestGetMembersRequest" => array(
Expand Down Expand Up @@ -294,6 +304,39 @@ public function getMembersInGroup(array $queryData) {
return array();
}

public function verifyPrivileges(array $queryData, string $privilege) {
//Build request logic
$verifyPrivs = array(
"WsRestGetGrouperPrivilegesLiteRequest" => array(
"privilegeName" => $privilege,
"groupName" => $queryData['groupName'],
"subjectId" => $queryData['userId']
)
);

$this->http->setHeader(array('Content-Type' => 'application/json', 'Accept' => 'application/json'));
$connectionUrl = "{$this->config['fullUrl']}/grouperPrivileges";

try {
$results = $this->http->sendRequest('POST', $connectionUrl, json_encode($verifyPrivs));

// Parse out relevant records to send front end
if (isset($results['WsGetGrouperPrivilegesLiteResult']['resultMetadata']['resultCode']) && $results['WsGetGrouperPrivilegesLiteResult']['resultMetadata']['resultCode'] != NULL) {
if ($results['WsGetGrouperPrivilegesLiteResult']['resultMetadata']['resultCode'] == 'SUCCESS_ALLOWED') {
return true;
} else {
return false;
}
}
} catch (Exception $e) {
CakeLog::write('error', __METHOD__ . ': An error occurred');
throw $e;
}

return array();

}

/**
* Gets all Stems/Folders where User is admin/owner
*
Expand Down
3 changes: 2 additions & 1 deletion Lib/GrouperHTTPWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,8 @@ private function _verifyResults(HttpSocketResponse $apiResults): array {
$mainKey = key($resBody);
$apiSuccess = $resBody[$mainKey]['resultMetadata']['resultCode'];

if ($apiSuccess != 'SUCCESS') {
// Had to add SUCCESS_NOT_ALLOWED and SUCCESS_ALLOWED for checking privs on a group for a user
if ($apiSuccess != 'SUCCESS' && $apiSuccess != 'SUCCESS_NOT_ALLOWED' && $apiSuccess != 'SUCCESS_ALLOWED') {
CakeLog::write('error', __METHOD__ . ': Result Code was ' . var_export($apiSuccess, true));
CakeLog::write('error', __METHOD__ . ': Error of ' . var_export($apiResults->body(), true));
throw new GrouperLiteException('Result from Grouper WS was' . var_export($apiSuccess, true));
Expand Down
9 changes: 8 additions & 1 deletion Model/GrouperGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -315,16 +315,23 @@ public function ownerGroups(array $conditions) {
* members
*
* @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
* @throws GrouperLiteException Captured in Controller
*
*/
public function membersInGroup(array $conditions) {
public function membersInGroup(array $conditions, string $userId) {
$this->initApi();

$conditions['userId'] = $userId;

try {
$groupMembers = $this->grouperAPI->getMembersInGroup($conditions);

if (count($groupMembers) < 1){
return $groupMembers;
}

$finalMembers = array();
foreach ($groupMembers as $member) {
if ($member['sourceId'] !== 'g:gsa') {
Expand Down
4 changes: 2 additions & 2 deletions View/CoGrouperLites/display.ctp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ echo $this->element('GrouperLite.base-styles');
array(
'plugin' => "grouper_lite",
'controller' => 'grouper_groups',
'action' => 'emaillistsMember',
'action' => 'emaillistsmember',
'co' => $coid,
'glid' => $glid
)
Expand All @@ -117,7 +117,7 @@ echo $this->element('GrouperLite.base-styles');
array(
'plugin' => "grouper_lite",
'controller' => 'grouper_groups',
'action' => 'emaillistsManage',
'action' => 'emaillistsmanage',
'co' => $coid,
'glid' => $glid
)
Expand Down
11 changes: 3 additions & 8 deletions View/GrouperGroups/emaillistsmanage.ctp
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,9 @@
</thead>
<tbody>
<tr>
<td><?php echo $this->Html->link(
isset($group['name']) ? $group['domain'] . ':' . $group['name'] : "--",
array(
'controller' => 'grouper_groups',
'action' => 'emaillistinfo',
'?' => array('groupname' => urlencode($group['name']))
)
) ?></td>
<td>
<?php echo $group['friendlyEmail'] ?? "No Name"; ?>
</td>
<td><?php echo isset($group['description']) ? $group['description'] : "--"; ?></td>
<td>
<a href="#"><?php echo _txt('pl.grouperlite.table.user-type-members'); ?> (10)</a> |
Expand Down
12 changes: 3 additions & 9 deletions View/GrouperGroups/emaillistsmember.ctp
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,9 @@
<tbody>
<?php foreach ($emailgroups as $key => $group) : ?>
<tr>
<td><?php echo $this->Html->link(

$group['friendlyEmail'] ?? "No Name",
array(
'controller' => 'grouper_groups',
'action' => 'emaillistinfo',
'?' => array('groupname' => urlencode($group['name']))
)
) ?></td>
<td>
<?php echo $group['friendlyEmail'] ?? "No Name"; ?>
</td>
<td><?php echo $group['description'] ?? _txt('pl.grouperlite.value.descr.zerostate'); ?></td>
<td>
<?php echo $group['optedin'] ? $this->element('GrouperLite.Components/optAction', array(
Expand Down
11 changes: 3 additions & 8 deletions View/GrouperGroups/emaillistsoptin.ctp
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,9 @@
<tbody>
<?php foreach ($emailgroups as $group) : ?>
<tr>
<td><?php echo $this->Html->link(
$group['friendlyEmail'] ?? "No Name",
array(
'controller' => 'grouper_groups',
'action' => 'emaillistinfo',
'?' => array('groupname' => urlencode($group['name']))
)
) ?></td>
<td>
<?php echo $group['friendlyEmail'] ?? "No Name"; ?>
</td>
<td><?php echo $group['description'] ?? _txt('pl.grouperlite.value.descr.zerostate'); ?></td>
<td class="text-center">
<button class="btn btn-raised btn-success" type="submit">
Expand Down

0 comments on commit d3fe3fb

Please sign in to comment.