diff --git a/Config/bootstrap.php b/Config/bootstrap.php deleted file mode 100644 index e47d4e3..0000000 --- a/Config/bootstrap.php +++ /dev/null @@ -1,19 +0,0 @@ -set('title_for_layout', _txt('pl.grouperlite.config.edit.title')); parent::beforeRender(); @@ -32,9 +31,9 @@ public function display($id) { $services_url = Router::url([ 'plugin' => "grouper_lite", 'controller' => 'GrouperGroups', - 'action' => 'groupoptin', + 'action' => 'index', 'co' => $this->cur_co['Co']['id'], - 'gdId' => $id + 'glid' => $id ]); $this->set('vv_services_url', $services_url); diff --git a/Controller/GrouperGroupsController.php b/Controller/GrouperGroupsController.php index c27a6aa..b673022 100644 --- a/Controller/GrouperGroupsController.php +++ b/Controller/GrouperGroupsController.php @@ -1,6 +1,7 @@ Session->read('Plugin.Grouper'); + if ($this->Session->check('Plugin.Grouper.id') && count($grouperConnData) == 5) { + if (isset($this->passedArgs['glid'])) { + if ($this->Session->read('Plugin.Grouper.id') !== $this->passedArgs['glid']) { + $this->setConnection(); + } + } + } else { + if (!isset($this->passedArgs['glid'])) { + //If user goes directly to GrouperLite url, will be sent to main index since they did not choose an + //appropriate Dashboard Widget. + return $this->redirect('/'); + } + $this->setConnection(); + } + } + + private function setConnection() { + $this->Session->write('Plugin.Grouper.id', $this->passedArgs['glid']); + + //Now get the setup Dasboard instance from db for connection info. + $getConnInfo = new CoGrouperLite(); + $connectionInfo = $getConnInfo->findById($this->passedArgs['glid']); + $this->Session->write('Plugin.Grouper.url', $connectionInfo['CoGrouperLite']['connUrl']); + $this->Session->write('Plugin.Grouper.version', $connectionInfo['CoGrouperLite']['connVer']); + $this->Session->write('Plugin.Grouper.user', $connectionInfo['CoGrouperLite']['connUser']); + $this->Session->write('Plugin.Grouper.pass', $connectionInfo['CoGrouperLite']['connPass']); + } + public function index() { return $this->redirect( - array('controller' => 'GrouperGroups', 'action' => 'groupoptin') + array('controller' => 'GrouperGroups', 'action' => 'groupoptin') ); } - - public function groupUser() - { + public function groupUser() { //TODO - Not being used, can delete? $this->set('title', _txt('pl.grouperlite.title.root')); $this->set('groupergroupsmember', $this->GrouperGroup->optinGroups($this->userId)); } - public function groupInfo() - { + public function groupInfo() { $name = urldecode($this->request->query['groupname']); $details = $this->GrouperGroup->groupDescriptions($name); @@ -35,8 +67,7 @@ public function groupInfo() $this->set('groupergroupsdetail', $details[0]); } - public function groupOwner() - { + public function groupOwner() { $this->set('title', _txt('pl.grouperlite.title.groupowner')); if (isset($this->request->data['search'])){ $searchCriteria = urldecode($this->request->data['search']); @@ -48,8 +79,7 @@ public function groupOwner() } - public function groupMember() - { + public function groupMember() { $this->set('title', _txt('pl.grouperlite.title.groupmember')); if (isset($this->request->data['search'])){ $searchCriteria = urldecode($this->request->data['search']); @@ -61,8 +91,7 @@ public function groupMember() } - public function groupOptin() - { + public function groupOptin() { $this->set('title', _txt('pl.grouperlite.title.groupoptin')); if (isset($this->request->data['search'])){ @@ -74,8 +103,7 @@ public function groupOptin() } } - public function emailListsOptin() - { + public function emailListsOptin() { $this->set('title', _txt('pl.grouperlite.title.emaillists')); // mock data $this->set('group', array( @@ -86,8 +114,7 @@ public function emailListsOptin() )); } - public function emailListsManaged() - { + public function emailListsManaged() { $this->set('title', _txt('pl.grouperlite.title.emaillistsmanaged')); // mock data $this->set('group', array( @@ -98,8 +125,7 @@ public function emailListsManaged() )); } - public function emailListInfo() - { + public function emailListInfo() { $this->set('title', _txt('pl.grouperlite.title.emaillistsinfo')); // mock data $this->set('groupergroupsdetail', array( @@ -120,8 +146,7 @@ public function groupCreateForm() { $this->set('title', _txt('pl.grouperlite.title.groupcreate')); } - public function groupCreate() - { + public function groupCreate() { $name = urldecode($this->request->data['name']); $set = urldecode($this->request->data['set']); $descr = urldecode($this->request->data['description']); @@ -129,8 +154,7 @@ public function groupCreate() $this->set('groupergroupadded', $this->GrouperGroup->createGroup($this->userId, $name, $set, $descr)); } - public function joinGroup() - { + public function joinGroup() { if ($this->request->is('post')) { $name = $this->request->data['GroupName']; if($this->GrouperGroup->joinGroup($this->userId, $name)) { @@ -144,8 +168,7 @@ public function joinGroup() } - public function leaveGroup() - { + public function leaveGroup() { if ($this->request->is('post')) { $name = $this->request->data['GroupName']; if($this->GrouperGroup->leaveGroup($this->userId, $name)) { @@ -180,7 +203,7 @@ function isAuthorized() { // Determine what operations this user can perform // Construct the permission set for this user, which will also be passed to the view. - //Note: Leaving in this format, in case need to restrict certain pages, can just remove true and add params. + //Note: Leaving in current format, in case need to restrict certain pages, can just remove true and add params. $p = array(); $p['index'] = true; diff --git a/Lib/GrouperApiAccess.php b/Lib/GrouperApiAccess.php index 8b39e70..d796052 100644 --- a/Lib/GrouperApiAccess.php +++ b/Lib/GrouperApiAccess.php @@ -10,24 +10,41 @@ class GrouperApiAccess private $_urlServlet = '/grouper-ws/servicesRest/'; - public function __construct() - { + /** + * GrouperApiAccess constructor. + * Setting up connection saved in Session from the GrouperLite record being + * used to access this plugin via Dashboard Widget + * + */ + public function __construct() { $this->http = new GrouperHTTPWrapper(); + if (!CakeSession::check('Plugin.Grouper.id')) { + //TODO throw error of some sort + } + + $connUrl = CakeSession::read('Plugin.Grouper.url'); + $connVer = CakeSession::read('Plugin.Grouper.version'); + + $this->config['fullUrl'] = $connUrl. $this->_urlServlet . $connVer; + + $this->http->setUser(CakeSession::read('Plugin.Grouper.user')); + $this->http->setPassword(CakeSession::read('Plugin.Grouper.pass')); + //$connections = ConnectionManager::enumConnectionObjects(); //var_dump($connections); //$this->config = $connections['grouperapi']; - $connUrl = Configure::read('GrouperLite.connUrl'); - $connVer = Configure::read('GrouperLite.connVer'); + //$connUrl = Configure::read('GrouperLite.connUrl'); + //$connVer = Configure::read('GrouperLite.connVer'); - $this->config['fullUrl'] = $connUrl. $this->_urlServlet . $connVer; + //$this->config['fullUrl'] = $connUrl. $this->_urlServlet . $connVer; + + //$this->http->setUser(Configure::read('GrouperLite.connUser')); + //$this->http->setPassword(Configure::read('GrouperLite.connPass')); - $this->http->setUser(Configure::read('GrouperLite.connUser')); - $this->http->setPassword(Configure::read('GrouperLite.connPass')); } - public function getGrouperUser($queryData) - { + public function getGrouperUser($queryData) { $userId = $queryData['conditions']['userId']; $this->http->setHeader(array('Content-Type' => 'application/json', 'Accept' => 'application/json')); @@ -58,8 +75,7 @@ public function getGrouperUser($queryData) } - public function getGrouperMemberOfGroups($queryData) - { + public function getGrouperMemberOfGroups($queryData) { $userId = $queryData['conditions']['userId']; $connectionUrl = "{$this->config['fullUrl']}/subjects/{$userId}/groups"; @@ -73,8 +89,7 @@ public function getGrouperMemberOfGroups($queryData) return array(); } - public function grouperGroupLeaveOrJoin($queryData) - { + public function grouperGroupLeaveOrJoin($queryData) { $groupName = $queryData['conditions']['groupName']; $subjectId = $queryData['conditions']['userId']; $groupLeaveOrJoin = $queryData['conditions']['LeaveJoin']; @@ -129,8 +144,7 @@ public function getOwnerGroups($queryData) { } - private function getGrouperGroups($queryData) - { + private function getGrouperGroups($queryData) { $groupType = $queryData['conditions']['groupType']; $subjectID = $queryData['conditions']['userId']; @@ -171,8 +185,7 @@ private function getGrouperGroups($queryData) } - public function getGrouperGroupDescription($queryData) - { + public function getGrouperGroupDescription($queryData) { $groupName = $queryData['conditions']['groupName']; $groupName = urlencode($groupName); diff --git a/Lib/GrouperHTTPWrapper.php b/Lib/GrouperHTTPWrapper.php index 860dd3e..9872a74 100644 --- a/Lib/GrouperHTTPWrapper.php +++ b/Lib/GrouperHTTPWrapper.php @@ -9,35 +9,29 @@ class GrouperHTTPWrapper extends HttpSocket private $_user; private $_password; - public function __construct($config = array()) - { + public function __construct($config = array()) { parent::__construct($config); //Setting to default to false, can change with the setter below $this->config['ssl_verify_peer'] = false; } - public function setSSLVerify($val) - { + public function setSSLVerify($val) { $this->config['ssl_verify_peer'] = $val; } - public function setUser($user) - { + public function setUser($user) { $this->_user = $user; } - public function setPassword($password) - { + public function setPassword($password) { $this->_password = $password; } - public function setHeader($headerSetting) - { + public function setHeader($headerSetting) { $this->_request['header'] = $headerSetting; } - public function sendRequest($method, $uri, $body = '') - { + public function sendRequest($method, $uri, $body = '') { $this->_request['method'] = $method; $this->_request['uri'] = $this->_parseUri($uri); $this->_request['uri']['user'] = $this->_user; @@ -58,8 +52,7 @@ public function sendRequest($method, $uri, $body = '') return $this->_verifyResults($results); } - private function _verifyResults($apiResults) - { + private function _verifyResults($apiResults) { $resBody = array(); if ($apiResults->isOk()) { $resBody = json_decode($apiResults->body(), true); diff --git a/Model/CoGrouperLite.php b/Model/CoGrouperLite.php index 62e2796..f276be6 100644 --- a/Model/CoGrouperLite.php +++ b/Model/CoGrouperLite.php @@ -30,7 +30,7 @@ class CoGrouperLite extends CoDashboardWidgetBackend { 'rule' => 'numeric', 'required' => true, 'allowEmpty' => false - )/*, + ), 'connUrl' => array( 'rule' => 'alphaNumeric', 'required' => true, @@ -50,7 +50,7 @@ class CoGrouperLite extends CoDashboardWidgetBackend { 'rule' => 'alphaNumeric', 'required' => true, 'allowEmpty' => false - ),*/ + ), ); } \ No newline at end of file diff --git a/Model/GrouperAttribute.php b/Model/GrouperAttribute.php index 74f3610..817fb3c 100644 --- a/Model/GrouperAttribute.php +++ b/Model/GrouperAttribute.php @@ -9,19 +9,15 @@ class GrouperAttribute extends GrouperLiteAppModel public $name = "GrouperAttribute"; public $grouperAPI; - public function __construct() - { + public function __construct() { $this->grouperAPI = new GrouperApiAccess(); } - public function groupAttributes($groupName) - { + public function groupAttributes($groupName) { $args = array(); $args['conditions']['groupName'] = $groupName; return $this->grouperAPI->getGroupAttributes($args); } - - }