diff --git a/Controller/GrouperGroupsController.php b/Controller/GrouperGroupsController.php index ccba290..9a611fe 100644 --- a/Controller/GrouperGroupsController.php +++ b/Controller/GrouperGroupsController.php @@ -116,6 +116,32 @@ public function index() ); } + /** + * Gets basic configuration for user/app via AJAX call access + * @return void + */ + public function getBaseConfig() { + + if ($this->request->is('ajax')) { + $this->response->disableCache(); + } + + $config = [ + "grouperbaseurl" => $this->Session->read('Plugin.Grouper.Api.grouperUrl'), + "isuserowner" => $this->GrouperGroup->isUserOwner($this->userId), + "isTemplateUser" => $this->GrouperGroup->isTemplateUser($this->userId), + "isGrouperVisible" => $this->GrouperGroup->isGrouperVisible($this->userId), + "defaultCollapse" => CakeSession::read('Plugin.Grouper.Api.defaultCollapse'), + "adHocHeading" => CakeSession::read('Plugin.Grouper.Api.adHocHeading'), + "wgHeading" => CakeSession::read('Plugin.Grouper.Api.wgHeading'), + 'co' => CakeSession::read('Plugin.Grouper.Api.co') + ]; + + $this->response->type('json'); + $this->set(compact('config')); + $this->set('_serialize', 'config'); + } + /** * Show all members of a group @@ -150,6 +176,7 @@ public function groupSubscribers() $this->Flash->set(_txt('pl.grouperlite.message.flash.group-detail-members-failed'), array('key' => 'error')); } + if(count($subscribers) < 1){ $this->response->type('json'); $this->response->statusCode(404); @@ -395,18 +422,17 @@ public function removeSubscriber() */ public function groupOwner() { + if ($this->request->is('ajax')) { + $this->response->disableCache(); + } //Set initial setting $scope = [ 'userId' => $this->userId ]; - if (isset($this->request->data['search']) || isset($this->request->query['search'])) { - if(isset($this->request->data['search'])){ - $searchCriteria = urldecode($this->request->data['search']); - } else { - $searchCriteria = urldecode($this->request->query['search']); - } + if (isset($this->request->query['search'])) { + $searchCriteria = urldecode($this->request->query['search']); $this->set('searchcriteria', $searchCriteria); @@ -416,14 +442,15 @@ public function groupOwner() $scope['searchcriteria'] = $searchCriteria; $scope['searchpage'] = 'ownerGroups'; - $data = $this->GrouperGroup->getSearchedGroups($scope); - - $this->set('groupsowners', $data); + $groupowners = $this->GrouperGroup->getSearchedGroups($scope); } catch (Exception $e) { CakeLog::write('error', __METHOD__ . ' Search: ' . var_export($e->getMessage(), true)); - + $this->response->type('json'); + $this->response->statusCode(500); + $this->response->send(); $this->set('groupsowners', array()); + $this->Flash->set(_txt('pl.grouperlite.message.flash.owner-group-failed'), array('key' => 'error')); return; } @@ -431,32 +458,21 @@ public function groupOwner() try { $scope['method'] = 'ownerGroups'; - $data = $this->GrouperGroup->ownerGroups($scope); - - $this->set('groupsowners', $data); + $groupowners = $this->GrouperGroup->ownerGroups($scope); } catch (Exception $e) { CakeLog::write('error', __METHOD__ . ': ' . var_export($e->getMessage(), true)); - + $this->response->type('json'); + $this->response->statusCode(500); + $this->response->send(); $this->set('groupsowners', array()); - $this->set('wgowners', array()); + $this->Flash->set(_txt('pl.grouperlite.message.flash.owner-group-failed'), array('key' => 'error')); return; } - } - - $this->set('grouperbaseurl', $this->Session->read('Plugin.Grouper.Api.grouperUrl')); - $this->set('isuserowner', $this->GrouperGroup->isUserOwner($this->userId)); - $this->set('isTemplateUser', $this->GrouperGroup->isTemplateUser($this->userId)); - $this->set('isGrouperVisible', $this->GrouperGroup->isGrouperVisible($this->userId)); - $config = [ - "defaultCollapse" => CakeSession::read('Plugin.Grouper.Api.defaultCollapse'), - "adHocHeading" => CakeSession::read('Plugin.Grouper.Api.adHocHeading'), - "wgHeading" => CakeSession::read('Plugin.Grouper.Api.wgHeading'), - 'co' => CakeSession::read('Plugin.Grouper.Api.co') - ]; - $this->set('config', $config); + $this->set(compact('groupowners')); + $this->set('_serialize', 'groupowners'); } @@ -775,17 +791,16 @@ function isAuthorized() $p = array(); $p['index'] = true; - $p['groupinfo'] = true; $p['membersingroup'] = true; $p['groupowner'] = true; $p['groupmember'] = true; + $p['getBaseConfig'] = true; $p['groupSubscribers'] = true; $p['addSubscriber'] = true; $p['findSubscriber'] = true; $p['removeSubscriber'] = true; $p['groupoptin'] = true; $p['groupcreate'] = true; - $p['groupdelete'] = true; $p['joingroup'] = true; $p['leavegroup'] = true; $p['groupcreatetemplate'] = true; @@ -838,21 +853,5 @@ private function breakoutGroups(array $recordSet, $type = 'basic') ); } - /** - * Eliminating canned description added by Grouper on creation of a WG in Grouper - * - * @param $description - * @return string - * - */ - private function hackDescription($description) - { - //Verify description has period in it. - if (strpos($description, ".") === false) { - return $description; - } - $newString = substr($description, strpos($description, ".") + 1); - return trim($newString); - } } \ No newline at end of file