Skip to content

Commit

Permalink
Fixed merge conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
rmathis committed Aug 24, 2021
2 parents c187be1 + c332d71 commit 5780b82
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 83 deletions.
41 changes: 32 additions & 9 deletions Controller/GrouperGroupsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

App::uses('Validator', 'Vendor/cakephp/Validation');
App::uses('CoGrouperLite', 'GrouperLite.Model/');
App::uses('Identifier', 'Model');

/**
* Class GrouperGroupsController
Expand Down Expand Up @@ -566,19 +567,25 @@ public function leaveGroup() {
function isAuthorized() {
$roles = $this->Role->calculateCMRoles();

//This call just pulls in user ID from comanage but not Grouper, need the Grouper Id for API calls.
//TODO - This is needed for my dev enviro since I do not log in via I2 IdP

if ($this->Session->check('Auth.User.username')) {
$this->userId = $this->Session->read('Auth.User.username');
}
/*
if ($this->Session->check('Plugin.Grouper.UserId')) {
$this->userId = $this->Session->read('Plugin.Grouper.UserId');
} else {
$this->userId = $this->GrouperGroup->getGrouperUserId();
$this->Session->write('Plugin.Grouper.UserId', $this->userId);
}
*/


/*
* 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.
*/
//
// if ($this->Session->check('Plugin.Grouper.UserId')) {
// $this->userId = $this->Session->read('Plugin.Grouper.UserId');
// } else {
// $this->userId = $this->getUserId($this->Session->read('Auth.User.co_person_id'));
// $this->Session->write('Plugin.Grouper.UserId', $this->userId);
// }

// Determine what operations this user can perform

// Construct the permission set for this user, which will also be passed to the view.
Expand Down Expand Up @@ -606,6 +613,22 @@ function isAuthorized() {
return ($p[$this->action]);
}

private function getUserId($id) {
$args = array();
$args['conditions']['Identifier.co_person_id'] = $id;
$args['conditions']['Identifier.type'] = 'I2CollabPN';
$args['conditions']['Identifier.status'] = SuspendableStatusEnum::Active;
$args['contain'] = false;

$Identifier = new Identifier();
$grouper_identifier = $Identifier->find('first', $args);

return $grouper_identifier['Identifier']['identifier'];
}

//##############################################################################################################
//TODO - Need to finish off the email list pages, once we get direction from I2
//##############################################################################################################
public function emaillistsOptin() {
$this->set('title', _txt('pl.grouperlite.title.emaillists-join'));

Expand Down
75 changes: 23 additions & 52 deletions Lib/GrouperApiAccess.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,50 +70,6 @@ public function __construct() {
$this->http->setPassword(CakeSession::read('Plugin.Grouper.Api.pass'));
}

/**
* Get User information from Grouper Web Service
*
* @return String User ID in Grouper Groups
* @throws Exception
*/
public function getGrouperUserId() {

$this->http->setHeader(array('Content-Type' => 'application/json', 'Accept' => 'application/json'));

// Create attributes want returned from call to Grouper WS
$formArray = array(
'WsRestGetSubjectsRequest' => array(
'subjectAttributeNames' => array(
'edupersonprincipalname',
'uid',
'mail',
'cn',
'givenname'
),
'wsSubjectLookups' => array(
array('subjectIdentifier' => $_SERVER['REMOTE_USER'])
)
)
);
$formData = json_encode($formArray);
$connectionUrl = $this->config['fullUrl'] . '/subjects';

try {
$results = $this->http->sendRequest('GET', $connectionUrl, $formData);

// Parse out relevant records to send front end
if (isset($results['WsGetSubjectsResults']['wsSubjects'][0]['id']) && $results['WsGetSubjectsResults']['wsSubjects'][0]['id'] != NULL) {
return $results['WsGetSubjectsResults']['wsSubjects'][0]['id'];
}

} catch (Exception $e) {
CakeLog::write('error', __METHOD__ . ': An error occurred');
throw $e;
}

return '';
}

/**
* Get Groups that User is a member of from Grouper.
*
Expand Down Expand Up @@ -347,15 +303,30 @@ private function useMembershipUrl(array $queryData) {
throw new GrouperLiteException("Option of $groupType is not supported");
}

//Build request logic
$groupsToShow = array(
"WsRestGetMembershipsRequest" => array(
"fieldName" => $fieldName,
"wsSubjectLookups" => array(
array("subjectId" => $subjectId)
if ($groupType == 'Optins' || $groupType == 'Optouts') {
//Build request logic, 2 subjectId's, second is for when user in "Secret" Optin/Optout Group
$groupsToShow = array(
"WsRestGetMembershipsRequest" => array(
"fieldName" => $fieldName,
"wsSubjectLookups" => array(
array("subjectId" => $subjectId),
array("subjectId" => $userId)
)
)
)
);
);
} else {
//Build request logic
$groupsToShow = array(
"WsRestGetMembershipsRequest" => array(
"fieldName" => $fieldName,
"wsSubjectLookups" => array(
array("subjectId" => $subjectId)
)
)
);
}


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

Expand Down
2 changes: 1 addition & 1 deletion Lib/lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
'pl.grouperlite.value.enabled' => 'Enabled',
'pl.grouperlite.value.disabled' => 'Disabled',

'pl.grouperlite.value.sympa - internet2' => 'A collection of email addresses to be used by the members of the group for communication purposes.',
'pl.grouperlite.value.email' => 'Email address of Working Group List',
'pl.grouperlite.value.jira' => 'For this Group, Jira provides a place to plan, track, and manage your agile and software development projects.',
'pl.grouperlite.value.confluence' => 'The Confluence group is a team workspace, specifically for this Group, where knowledge and collaboration meet allowing for the ability to Create, collaborate, and organize content in one place.',
'pl.grouperlite.value.incommon-collab' => '',
Expand Down
27 changes: 9 additions & 18 deletions Model/GrouperGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,24 +108,6 @@ private function initApi() {
}
}

/**
* Gets the users Id from Grouper since can be different than what is in Comanage.
*
* @return String User's Id in Grouper
* @throws Exception
*/
public function getGrouperUserId() {
$this->initApi();

try {
return $this->grouperAPI->getGrouperUserId();

} catch (Exception $e) {
CakeLog::write('error', __METHOD__ . ': An error occurred');
throw $e;
}
}

/**
* Return all Groups that a User belongs to in Grouper.
* Will also add OptOut Groups and flag them as joined so can display Optout option in UI.
Expand Down Expand Up @@ -245,6 +227,15 @@ private function getFriendlyWorkingGroupName(array $groups) {
}
$appCount += 1;
}
//changed the way email list are displayed to actually show lists email address.
if ($appName == 'sympa - internet2' || $appName == 'sympa - incommon'){
if ($appName == 'sympa - internet2'){
$appName = $group['WGName'] . '@lists.' . 'internet2.edu';
} else {
$appName = $group['WGName'] . '@lists.' . 'incommon.org';
}

}
$group['WGApp'] = $appName;
//TODO - FOR DEMO PURPOSE THAT LEAVES OUT ADMIN GROUPS TO SHOW WHAT AVERAGE USER SEES
if ($group['WGRole'] !== 'admins' && $group['WGRole'] !== 'owners') {
Expand Down
10 changes: 7 additions & 3 deletions View/GrouperGroups/groupmember.ctp
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,14 @@ $numColumns = count($columns);
) ?>" title="<?php echo $group['name']; ?>">
<?php echo $group['WGApp'] ?? "No Name"; ?></a>
</td>
<?php if ($isuserowner === 'T') { ?>
<?php if ($isuserowner === 'T') : ?>
<td><?php echo $group['WGRole'] ?? _txt('pl.grouperlite.value.descr.zerostate'); ?></td>
<?php } ?>
<td><?php echo _txt('pl.grouperlite.value.' . $group['WGApp']) ?? _txt('pl.grouperlite.value.descr.zerostate'); ?></td>
<?php endif; ?>
<?php if (strpos($group['WGApp'], '@lists') !== false) : ?>
<td><?php echo _txt('pl.grouperlite.value.email'); ?></td>
<?php else : ?>
<td><?php echo _txt('pl.grouperlite.value.' . $group['WGApp']) ?? _txt('pl.grouperlite.value.descr.zerostate'); ?></td>
<?php endif; ?>
<td>

</td>
Expand Down

0 comments on commit 5780b82

Please sign in to comment.