diff --git a/Controller/GrouperGroupsController.php b/Controller/GrouperGroupsController.php index af237b7..e3832c6 100644 --- a/Controller/GrouperGroupsController.php +++ b/Controller/GrouperGroupsController.php @@ -56,7 +56,7 @@ public function beforeFilter() { parent::beforeFilter(); - $this->Security->unlockedActions = array('removeSubscriber', 'addSubscriber'); + $this->Security->unlockedActions = array('removeSubscriber', 'addSubscriber', 'joinGroup', 'leaveGroup'); //Need to find which plugin instance choosing, if more than one from cm_co_grouper_lites // table being used in COmanage. @@ -126,33 +126,6 @@ public function index() $this->set('config', $config); } - /** - * 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 * Called from all pages via AJAX call @@ -490,20 +463,19 @@ public function groupOwner() * This includes self-joined Optin Groups, as well as required Groups User cannot leave * */ - public function groupMember() { + 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); @@ -518,15 +490,18 @@ public function groupMember() $finalData = $this->breakoutGroups($data); - $this->set('groupmemberships', $finalData['adHocGroups']); - $this->set('wgmemberships', $finalData['workingGroups']); + $groupmemberships = $finalData['adHocGroups']; + $wgmemberships = $finalData['workingGroups']; } catch (Exception $e) { CakeLog::write('error', __METHOD__ . ' Search: ' . var_export($e->getMessage(), true)); - - $this->Flash->set("Your Search Group cannot be found, please try again later.", array('key' => 'error')); + $this->response->type('json'); + $this->response->statusCode(500); + $this->response->send(); $this->set('groupmemberships', array()); $this->set('wgmemberships', array()); + + $this->Flash->set("Your Search Group cannot be found, please try again later.", array('key' => 'error')); return; } } else { @@ -538,29 +513,26 @@ public function groupMember() $finalData = $this->breakoutGroups($data); - $this->set('groupmemberships', $finalData['adHocGroups']); - $this->set('wgmemberships', $finalData['workingGroups']); + $groupmemberships = $finalData['adHocGroups']; + $wgmemberships = $finalData['workingGroups']; } catch (Exception $e) { CakeLog::write('error', __METHOD__ . ': ' . var_export($e->getMessage(), true)); - - $this->Flash->set("Your Member Group cannot be found, please try again later.", array('key' => 'error')); + $this->response->type('json'); + $this->response->statusCode(500); + $this->response->send(); $this->set('groupmemberships', array()); $this->set('wgmemberships', array()); + + $this->Flash->set("Your Member Group cannot be found, please try again later.", 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('groupmemberships')); + $this->set(compact('wgmemberships')); + $this->set('_serialize', 'groupmemberships'); + $this->set('_serialize', 'wgmemberships'); } /** @@ -568,18 +540,17 @@ public function groupMember() */ public function groupOptin() { + 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); @@ -589,16 +560,16 @@ public function groupOptin() $scope['searchcriteria'] = $searchCriteria; $scope['searchpage'] = 'optinGroups'; - $data = $this->GrouperGroup->getSearchedGroups($scope); - - $this->set('groupoptins', $data); + $groupoptins = $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('groupoptins', array()); $this->Flash->set("Your Optin Group Search cannot be found, please try again later.", array('key' => 'error')); - $this->set('groupoptins', array()); - $this->set('wgoptins', array()); return; } } else { @@ -606,28 +577,21 @@ public function groupOptin() //Add settings for optinGroups $scope['method'] = 'optinGroups'; - $data = $this->GrouperGroup->optinGroups($scope); - - $this->set('groupoptins', $data); + $groupoptins = $this->GrouperGroup->optinGroups($scope); } catch (Exception $e) { CakeLog::write('error', __METHOD__ . ': ' . var_export($e->getMessage(), true)); - $this->Flash->set("An error occurred with the Optin Groups, please try again later.", array('key' => 'error')); + $this->response->type('json'); + $this->response->statusCode(500); + $this->response->send(); $this->set('groupoptins', array()); - $this->set('wgoptins', array()); + + $this->Flash->set("An error occurred with the Optin Groups, please try again later.", array('key' => 'error')); return; } } - $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('groupoptins')); + $this->set('_serialize', 'groupoptins'); } @@ -668,28 +632,38 @@ public function groupCreateTemplate() */ public function joinGroup() { - if ($this->request->is('post')) { - $name = $this->request->data['GroupName']; - $display = $this->request->data['GroupDisplayName']; + $name = urldecode($this->request->query['GroupName']); + $display = urldecode($this->request->query['GroupDisplayName']); - try { - if ($this->GrouperGroup->joinGroup($this->userId, $name)) { - $this->Flash->set( - _txt('pl.grouperlite.message.flash.join-group-success', array(filter_var($display, FILTER_SANITIZE_SPECIAL_CHARS))), - array('key' => 'success') - ); - } else { - $this->Flash->set(_txt('pl.grouperlite.message.flash.join-group-failed', array(filter_var($display, FILTER_SANITIZE_SPECIAL_CHARS))), array('key' => 'error')); - } - } catch (Exception $e) { - CakeLog::write('error', __METHOD__ . ': ' . var_export($e->getMessage(), true)); - $this->Flash->set(_txt('pl.grouperlite.message.flash.join-group-error'), array('key' => 'error')); + if ($this->request->is('ajax')) { + $this->response->disableCache(); + } + + try { + if ($this->GrouperGroup->joinGroup($this->userId, $name)) { + $this->Flash->set( + _txt('pl.grouperlite.message.flash.join-group-success', array(filter_var($display, FILTER_SANITIZE_SPECIAL_CHARS))), + array('key' => 'success') + ); + $resultAdd = "Success"; + } else { + $this->response->type('json'); + $this->response->statusCode(401); + $this->response->body(json_encode(array('status' => 'ERROR', 'message' => 'NOT ADDED'))); + $this->response->send(); + $resultAdd = ''; } - } else { - $this->Flash->set(_txt('pl.grouperlite.message.flash.join-group-error')); + } catch (Exception $e) { + CakeLog::write('error', __METHOD__ . ': ' . var_export($e->getMessage(), true)); + $this->response->type('json'); + $this->response->statusCode(404); + $this->response->body(json_encode(array('status' => 'ERROR', 'message' => 'EXCEPTION'))); + $this->response->send(); + $resultAdd = ''; } - return $this->redirect(array('action' => 'groupoptin')); + $this->set(compact('resultAdd')); + $this->set('_serialize', 'resultAdd'); } /** @@ -699,29 +673,34 @@ public function joinGroup() */ public function leaveGroup() { - if ($this->request->is('post')) { - $name = $this->request->data['GroupName']; - $display = $this->request->data['GroupDisplayName']; + $name = urldecode($this->request->query['GroupName']); + $display = urldecode($this->request->query['GroupDisplayName']); - try { - if ($this->GrouperGroup->leaveGroup($this->userId, $name)) { - $this->Flash->set( - _txt('pl.grouperlite.message.flash.leave-group-success', array(filter_var($display, FILTER_SANITIZE_SPECIAL_CHARS))), - array('key' => 'success') - ); - } else { - $this->Flash->set(_txt('pl.grouperlite.message.flash.leave-group-failed', array(filter_var($display, FILTER_SANITIZE_SPECIAL_CHARS))), array('key' => 'error')); - } - } catch (Exception $e) { - CakeLog::write('error', __METHOD__ . ': ' . var_export($e->getMessage(), true)); - $this->Flash->set(_txt('pl.grouperlite.message.flash.leave-group-error'), array('key' => 'error')); - } + if ($this->request->is('ajax')) { + $this->response->disableCache(); + } - } else { - $this->Flash->set(_txt('pl.grouperlite.message.flash.leave-group-error'), array('key' => 'error')); + try { + if ($this->GrouperGroup->leaveGroup($this->userId, $name)) { + $resultRemove = "Success"; + } else { + $this->response->type('json'); + $this->response->statusCode(401); + $this->response->body(json_encode(array('status' => 'ERROR', 'message' => 'NOT DELETED'))); + $this->response->send(); + $resultRemove = ''; + } + } catch (Exception $e) { + CakeLog::write('error', __METHOD__ . ': ' . var_export($e->getMessage(), true)); + $this->response->type('json'); + $this->response->statusCode(404); + $this->response->body(json_encode(array('status' => 'ERROR', 'message' => 'EXCEPTION'))); + $this->response->send(); + $resultRemove = ''; } - return $this->redirect(array('action' => 'groupmember')); + $this->set(compact('resultRemove')); + $this->set('_serialize', 'resultRemove'); } /** @@ -802,18 +781,17 @@ function isAuthorized() $p = array(); $p['index'] = true; - $p['membersingroup'] = true; - $p['groupowner'] = true; - $p['groupmember'] = 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['joingroup'] = true; - $p['leavegroup'] = true; + $p['groupOptin'] = true; + $p['groupCreate'] = true; + $p['joinGroup'] = true; + $p['leaveGroup'] = true; $p['groupcreatetemplate'] = true; $this->set('permissions', $p); diff --git a/Model/GrouperGroup.php b/Model/GrouperGroup.php index 90ee0f7..21e2157 100644 --- a/Model/GrouperGroup.php +++ b/Model/GrouperGroup.php @@ -154,7 +154,6 @@ public function isGrouperVisible(string $userId) } } - /** * Used to instantiate API class * @@ -170,37 +169,6 @@ private function initApi() } } - /** - * NOT BEING USED - * Listing of members in an email group - * - * @param array $conditions Listing of conditions for display of records, including UserId - * @return array List of members that belong to email group - * @throws GrouperLiteException - * - */ -// public function filteredMemberOfEmails(array $conditions) -// { -// $this->initApi(); -// -// try { -// $memberOfEmails = $this->filteredMemberOfGroups($conditions); -// -// // Strip out all Groups that are not in app:sympa Stem/Directory -// foreach ($memberOfEmails as $key => $value) { -// if (strpos(strtolower($value['name']), $this->emailStem) === false) { -// unset($memberOfEmails[$key]); -// } -// } -// return array_values($memberOfEmails); -// -// } 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 OptOut Groups and flag them as joined so can display Optout option in UI. @@ -614,7 +582,6 @@ public function getSearchedGroups(array $conditions) } } - /** * Return array of Working Groups for display on coManage site. * Logic is for each WG to have one key=>value of main WG name, then array of all associated