From 2f18f0f79a10671759ec03505b5e9f5f9d1fd349 Mon Sep 17 00:00:00 2001 From: Ioannis Igoumenos Date: Tue, 27 Jun 2023 19:09:59 +0300 Subject: [PATCH] the plugin has to parseCOID --- Controller/GrouperGroupsController.php | 115 +++++++++++-------------- 1 file changed, 50 insertions(+), 65 deletions(-) diff --git a/Controller/GrouperGroupsController.php b/Controller/GrouperGroupsController.php index b0537e2..2375a38 100644 --- a/Controller/GrouperGroupsController.php +++ b/Controller/GrouperGroupsController.php @@ -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 @@ -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. @@ -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. * @@ -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; + } } \ No newline at end of file