Skip to content

Commit

Permalink
WIP - added Ajax call for config and also Ajax'd owned groups method
Browse files Browse the repository at this point in the history
  • Loading branch information
Axel Stohn authored and Axel Stohn committed May 14, 2023
1 parent 579c98d commit 30c423d
Showing 1 changed file with 45 additions and 46 deletions.
91 changes: 45 additions & 46 deletions Controller/GrouperGroupsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);

Expand All @@ -416,47 +442,37 @@ 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;
}
} else {
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');
}


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

0 comments on commit 30c423d

Please sign in to comment.