Skip to content

the plugin has to parseCOID #4

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
115 changes: 50 additions & 65 deletions Controller/GrouperGroupsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,15 @@
*/
class GrouperGroupsController extends GrouperLiteAppController
{
// Dynamic properties are deprecated so we will define the property here
protected $userId = null;

public $helpers = array('Html', 'Form', 'Flash');
public $uses = array('GrouperLite.GrouperGroup', 'CoPerson');
public $uses = array(
'GrouperLite.GrouperGroup',
'GrouperLite.CoGrouperLite',
'CoPerson'
);
public $components = array('Flash', 'Paginator', 'RequestHandler', 'Security' => array(
'validatePost' => false,
'csrfUseOnce' => false
Expand Down Expand Up @@ -797,40 +804,17 @@ function isAuthorized()
{
$roles = $this->Role->calculateCMRoles();

/**
* The following code displays a few custom implementations of the
* login process used to crosswalk a user for Grouper authentication.
*
* You may need to further customize this section to meet your organization
* crosswalk needs.
*/

/**
* Default when login-id is the same as grouper id
*/
// Default Begin ===============================================
/*
if ($this->Session->check('Auth.User.username')) {
$this->userId = $this->Session->read('Auth.User.username');
}
*/
// Default End ===============================================

/**
* Customized Crosswalk from login-id to Grouper Username
*/
// Custom Begin ===============================================
$username = $this->Session->read('Auth.User.username');

if ($this->Session->check('Plugin.Grouper.UserId')) {
$this->userId = $this->Session->read('Plugin.Grouper.UserId');
} else {
$uid = $this->getPersonIdFromUsername($username);
$this->userId = $this->getUserId($uid);
$this->Session->write('Plugin.Grouper.UserId', $this->userId);
}
// Custom End ===============================================
// Find the identifier
$args = array();
// XXX This should become configuration
$args['conditions']['Identifier.type'] = 'I2CollabPN';
$args['conditions']['Identifier.status'] = SuspendableStatusEnum::Active;
$args['conditions']['Identifier.co_person_id'] = $roles["copersonid"];
$args['contain'] = false;

$Identifier = ClassRegistry::init('Identifier');
$identifiers = $Identifier->find('all', $args);
$this->userId = $identifiers[0]["Identifier"]["identifier"];

// 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 @@ -992,37 +976,6 @@ public function emaillistsManage()
$this->set('isGrouperVisible', $this->GrouperGroup->isGrouperVisible($this->userId));
}

private function getPersonIdFromUsername($username)
{
$args = array();
$args['conditions']['Identifier.identifier'] = $username;
$args['conditions']['Identifier.status'] = SuspendableStatusEnum::Active;
$args['conditions']['Identifier.deleted'] = false;
$args['conditions']['Identifier.identifier_id'] = null;
$args['conditions']['NOT']['Identifier.co_person_id'] = null;
$args['conditions']['Identifier.type'] = 'eppn';
$args['contain'] = false;

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

return $co_person_id['Identifier']['co_person_id'];
}

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'];
}

/**
* Breakout Working Groups from AdHoc Groups for display purposes in UI.
*
Expand Down Expand Up @@ -1068,4 +1021,36 @@ private function hackDescription($description)
$newString = substr($description, strpos($description, ".") + 1);
return trim($newString);
}

/**
* Override the default sanity check performed in AppController
*
* @since COmanage Registry v4.3.0
* @return Boolean True if sanity check is successful
*/

public function verifyRequestedId() {
return true;
}


/**
* For Models that accept a CO ID, find the provided CO ID.
* - precondition: A coid must be provided in $this->request (params or data)
*
* @since COmanage Registry v4.3.0
* @return Integer The CO ID if found, or -1 if not
*/

public function parseCOID($data = null) {
$connectionInfo = $this->CoGrouperLite->findById($this->passedArgs['glid']);
$this->CoGrouperLite->CoDashboardWidget->CoDashboard->id = $connectionInfo["CoDashboardWidget"]["co_dashboard_id"];
$co_id = $this->CoGrouperLite->CoDashboardWidget->CoDashboard->field('co_id');

if(!empty($co_id)) {
return $co_id;
}

return -1;
}
}