From 7b26c048ffc6b53f16b6e3580743c71305222106 Mon Sep 17 00:00:00 2001 From: axman Date: Sun, 28 Mar 2021 18:30:42 -0700 Subject: [PATCH] updated for I2 Dev enviro --- Controller/GrouperGroupsController.php | 22 +++++++++++++++------- Lib/GrouperApiAccess.php | 11 ++++------- Model/GrouperGroup.php | 18 ++++++++++++++++++ 3 files changed, 37 insertions(+), 14 deletions(-) diff --git a/Controller/GrouperGroupsController.php b/Controller/GrouperGroupsController.php index 69fc296..97af3e0 100644 --- a/Controller/GrouperGroupsController.php +++ b/Controller/GrouperGroupsController.php @@ -180,8 +180,8 @@ public function groupOwner() { //Set initial settings for pagination $scope = [ 'userId' => $this->userId, - 'page' => ($this->passedArgs['page'] ? $this->passedArgs['page']: $this->paginate['page']), - 'limit' => ($this->passedArgs['limit'] ? $this->passedArgs['limit']: $this->paginate['limit']), + 'page' => (isset($this->passedArgs['page']) ? $this->passedArgs['page']: $this->paginate['page']), + 'limit' => (isset($this->passedArgs['limit']) ? $this->passedArgs['limit']: $this->paginate['limit']), ]; if (isset($this->request->data['search'])) { @@ -235,8 +235,8 @@ public function groupMember() { //Set initial settings for pagination $scope = [ 'userId' => $this->userId, - 'page' => ($this->passedArgs['page'] ? $this->passedArgs['page']: $this->paginate['page']), - 'limit' => ($this->passedArgs['limit'] ? $this->passedArgs['limit']: $this->paginate['limit']), + 'page' => (isset($this->passedArgs['page']) ? $this->passedArgs['page']: $this->paginate['page']), + 'limit' => (isset($this->passedArgs['limit']) ? $this->passedArgs['limit']: $this->paginate['limit']), ]; if (isset($this->request->data['search'])) { @@ -463,9 +463,17 @@ public function leaveGroup() { function isAuthorized() { $roles = $this->Role->calculateCMRoles(); - //Need to pull in UserID for access to Grouper + //This call just pulls in user ID from comanage but not Grouper, need the Grouper Id for API calls. + /* 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); } // Determine what operations this user can perform @@ -530,8 +538,8 @@ public function emaillistsMember() //Set initial settings for pagination $scope = [ 'userId' => $this->userId, - 'page' => ($this->passedArgs['page'] ? $this->passedArgs['page']: $this->paginate['page']), - 'limit' => ($this->passedArgs['limit'] ? $this->passedArgs['limit']: $this->paginate['limit']), + 'page' => (isset($this->passedArgs['page']) ? $this->passedArgs['page']: $this->paginate['page']), + 'limit' => (isset($this->passedArgs['limit']) ? $this->passedArgs['limit']: $this->paginate['limit']), ]; try { diff --git a/Lib/GrouperApiAccess.php b/Lib/GrouperApiAccess.php index bea20de..1d7a845 100644 --- a/Lib/GrouperApiAccess.php +++ b/Lib/GrouperApiAccess.php @@ -71,16 +71,13 @@ public function __construct() { } /** - * NOT BEING USED * Get User information from Grouper Web Service * - * @param array $queryData Array of conditions for querying - * @return array + * @return String User ID in Grouper Groups * @throws Exception */ - public function getGrouperUser(array $queryData) { + public function getGrouperUserId() { - $userId = $queryData['userId']; $this->http->setHeader(array('Content-Type' => 'application/json', 'Accept' => 'application/json')); // Create attributes want returned from call to Grouper WS @@ -94,7 +91,7 @@ public function getGrouperUser(array $queryData) { 'givenname' ), 'wsSubjectLookups' => array( - array('subjectIdentifier' => $userId) + array('subjectIdentifier' => $_SERVER['REMOTE_USER']) ) ) ); @@ -114,7 +111,7 @@ public function getGrouperUser(array $queryData) { throw $e; } - return array(); + return ''; } /** diff --git a/Model/GrouperGroup.php b/Model/GrouperGroup.php index 89bf151..bf12999 100644 --- a/Model/GrouperGroup.php +++ b/Model/GrouperGroup.php @@ -100,6 +100,24 @@ 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 Optin Groups and flag them as joined so can display Optout option in UI.