Skip to content

Commit

Permalink
Refactored call to get userId via I2CollabPN field for I2 Grouper use…
Browse files Browse the repository at this point in the history
…r synch
  • Loading branch information
axel committed Aug 3, 2021
1 parent 1bac620 commit f19d90b
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 67 deletions.
33 changes: 28 additions & 5 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');
}
/*
*/

/*
* 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->GrouperGroup->getGrouperUserId();
$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
44 changes: 0 additions & 44 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
18 changes: 0 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

0 comments on commit f19d90b

Please sign in to comment.