Skip to content

Commit

Permalink
Changed major calls to AJAX
Browse files Browse the repository at this point in the history
  • Loading branch information
Axel Stohn authored and Axel Stohn committed May 15, 2023
1 parent b5bf4ef commit 4656fe1
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 157 deletions.
226 changes: 102 additions & 124 deletions Controller/GrouperGroupsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);

Expand All @@ -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 {
Expand All @@ -538,48 +513,44 @@ 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');
}

/**
* Display all Groups a User can Join
*/
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);

Expand All @@ -589,45 +560,38 @@ 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 {
try {
//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');
}


Expand Down Expand Up @@ -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');
}

/**
Expand All @@ -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');
}

/**
Expand Down Expand Up @@ -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);
Expand Down
Loading

0 comments on commit 4656fe1

Please sign in to comment.