Skip to content

Commit

Permalink
work complete
Browse files Browse the repository at this point in the history
  • Loading branch information
axel committed Jan 25, 2021
1 parent a135e21 commit 271a34b
Show file tree
Hide file tree
Showing 7 changed files with 92 additions and 87 deletions.
19 changes: 0 additions & 19 deletions Config/bootstrap.php

This file was deleted.

7 changes: 3 additions & 4 deletions Controller/CoGrouperLitesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ class CoGrouperLitesController extends SDWController {
* @since COmanage Registry v3.2.0
*/

function beforeRender()
{
function beforeRender() {
$this->set('title_for_layout', _txt('pl.grouperlite.config.edit.title'));

parent::beforeRender();
Expand All @@ -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);
Expand Down
73 changes: 48 additions & 25 deletions Controller/GrouperGroupsController.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

App::uses('Validator', 'Vendor/cakephp/Validation');
App::uses('CoGrouperLite', 'GrouperLite.Model/');


class GrouperGroupsController extends GrouperLiteAppController
Expand All @@ -10,23 +11,54 @@ class GrouperGroupsController extends GrouperLiteAppController

public $name = 'GrouperGroups';

public function beforeFilter() {
parent::beforeFilter();

//Need to find which plugin instance choosing, if more than one from cm_co_grouper_lites
// table being used in COmanage.
$grouperConnData = $this->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);

Expand All @@ -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']);
Expand All @@ -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']);
Expand All @@ -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'])){
Expand All @@ -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(
Expand All @@ -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(
Expand All @@ -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(
Expand All @@ -120,17 +146,15 @@ 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']);
// Debugger::dump($this->request->data);
$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)) {
Expand All @@ -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)) {
Expand Down Expand Up @@ -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;
Expand Down
47 changes: 30 additions & 17 deletions Lib/GrouperApiAccess.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand Down Expand Up @@ -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";
Expand All @@ -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'];
Expand Down Expand Up @@ -129,8 +144,7 @@ public function getOwnerGroups($queryData) {

}

private function getGrouperGroups($queryData)
{
private function getGrouperGroups($queryData) {
$groupType = $queryData['conditions']['groupType'];
$subjectID = $queryData['conditions']['userId'];

Expand Down Expand Up @@ -171,8 +185,7 @@ private function getGrouperGroups($queryData)
}


public function getGrouperGroupDescription($queryData)
{
public function getGrouperGroupDescription($queryData) {
$groupName = $queryData['conditions']['groupName'];

$groupName = urlencode($groupName);
Expand Down
21 changes: 7 additions & 14 deletions Lib/GrouperHTTPWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions Model/CoGrouperLite.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class CoGrouperLite extends CoDashboardWidgetBackend {
'rule' => 'numeric',
'required' => true,
'allowEmpty' => false
)/*,
),
'connUrl' => array(
'rule' => 'alphaNumeric',
'required' => true,
Expand All @@ -50,7 +50,7 @@ class CoGrouperLite extends CoDashboardWidgetBackend {
'rule' => 'alphaNumeric',
'required' => true,
'allowEmpty' => false
),*/
),
);

}
8 changes: 2 additions & 6 deletions Model/GrouperAttribute.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}



}

0 comments on commit 271a34b

Please sign in to comment.