Skip to content

Commit

Permalink
Merged feature/ICPCO-89 into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
axel committed Feb 8, 2021
2 parents f6e2716 + d82995d commit badec4a
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 19 deletions.
21 changes: 12 additions & 9 deletions Controller/GrouperGroupsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ public function 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) {
$grouperConnData = $this->Session->read('Plugin.Grouper.Api');
if ($this->Session->check('Plugin.Grouper.Api.id') && count($grouperConnData) == 5) {
if (isset($this->passedArgs['glid'])) {
if ($this->Session->read('Plugin.Grouper.id') !== $this->passedArgs['glid']) {
if ($this->Session->read('Plugin.Grouper.Api.id') !== $this->passedArgs['glid']) {
$this->setConnection();
}
}
Expand All @@ -37,15 +37,15 @@ public function beforeFilter() {
* Adding Grouper Conn info to SESSION for use in Lib/GrouperApiAccess.php
*/
private function setConnection() {
$this->Session->write('Plugin.Grouper.id', $this->passedArgs['glid']);
$this->Session->write('Plugin.Grouper.Api.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']);
$this->Session->write('Plugin.Grouper.Api.url', $connectionInfo['CoGrouperLite']['connUrl']);
$this->Session->write('Plugin.Grouper.Api.version', $connectionInfo['CoGrouperLite']['connVer']);
$this->Session->write('Plugin.Grouper.Api.user', $connectionInfo['CoGrouperLite']['connUser']);
$this->Session->write('Plugin.Grouper.Api.pass', $connectionInfo['CoGrouperLite']['connPass']);
}

/**
Expand Down Expand Up @@ -78,7 +78,7 @@ public function groupOwner() {
} else {
$this->set('groupergroupsowner', $this->GrouperGroup->ownerGroups($this->userId));
}

$this->set('isuserowner', $this->GrouperGroup->isUserOwner($this->userId));
}

/**
Expand All @@ -102,6 +102,8 @@ public function groupMember() {
$this->Flash->set("Your Membership Groups cannot be found currently, please try again later.", array('key' => 'error'));
$this->set('groupergroupmemberships', array());
}
$this->set('isuserowner', $this->GrouperGroup->isUserOwner($this->userId));

}

/**
Expand Down Expand Up @@ -130,6 +132,7 @@ public function groupOptin() {
$this->set('groupergroupoptin', array());
}
}
$this->set('isuserowner', $this->GrouperGroup->isUserOwner($this->userId));
}

//TODO - Need to combine this form with code below for groupCreate
Expand Down
10 changes: 5 additions & 5 deletions Lib/GrouperApiAccess.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,18 +56,18 @@ public function __construct() {

$this->http = new GrouperHTTPWrapper();

if (!CakeSession::check('Plugin.Grouper.id')) {
if (!CakeSession::check('Plugin.Grouper.Api.id')) {
CakeLog::write('error', 'GrouperLite API: No Widget record in Session');
throw new GrouperLiteException("No GrouperLite instance captured");
}

$connUrl = CakeSession::read('Plugin.Grouper.url');
$connVer = CakeSession::read('Plugin.Grouper.version');
$connUrl = CakeSession::read('Plugin.Grouper.Api.url');
$connVer = CakeSession::read('Plugin.Grouper.Api.version');

$this->config['fullUrl'] = $connUrl . $this->_urlServlet . $connVer;

$this->http->setUser(CakeSession::read('Plugin.Grouper.user'));
$this->http->setPassword(CakeSession::read('Plugin.Grouper.pass'));
$this->http->setUser(CakeSession::read('Plugin.Grouper.Api.user'));
$this->http->setPassword(CakeSession::read('Plugin.Grouper.Api.pass'));
}

/**
Expand Down
2 changes: 1 addition & 1 deletion Model/GrouperAttribute.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ private function initApi() {
* @return array Attributes in Grouper for this Group
* @throws GrouperLiteException
*/
public function groupAttributes(string $groupName) {
public function getGroupAttributes(string $groupName) {
$args = array();
$args['conditions']['groupName'] = $groupName;

Expand Down
52 changes: 48 additions & 4 deletions Model/GrouperGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,6 @@ class GrouperGroup extends GrouperLiteAppModel
/** @var GrouperApiAccess $grouperAPI */
public $grouperAPI = null;

//TODO - get name of Friendly name attribute that can be used for pulling the friendly name
private $friendly = 'sandbox:testAttributeName';

/**
* Used to instantiate API class
*
Expand All @@ -59,6 +56,49 @@ private function initApi() {
}
}

/**
* Verifies if user is an owner/admin of a group and then stores results in Session.
* Session variable is reset on Group Creation and Group Deletion
*
* @see GrouperGroup::resetUserOwner()
*
* @param string $userId Id of User
* @return String T or F
* @throws GrouperLiteException
*
*/
public function isUserOwner(string $userId) {
if (CakeSession::check('Plugin.Grouper.isUserOwner')) {
return CakeSession::read('Plugin.Grouper.isUserOwner');
}

$this->initApi();

$args = array();
$args['conditions']['userId'] = $userId;

$ownGroups = $this->grouperAPI->getOwnerGroups($args);

if (count($ownGroups) > 0) {
CakeSession::write('Plugin.Grouper.isUserOwner', 'T');
return 'T';
}
CakeSession::write('Plugin.Grouper.isUserOwner', 'F');
return 'F';
}

/**
* Private function used to reset the IsUserOwner Session variable,
* that maintains the status of a user being an owner/admin of a group
*
* @see GrouperGroup::isUserOwner()
*/
private function resetUserOwner() {
if (CakeSession::check('Plugin.Grouper.isUserOwner')) {
CakeSession::delete('Plugin.Grouper.isUserOwner');
}
}

/**
* Return all Groups that a User belongs to in Grouper.
* Will also add Optin Groups and flag them as joined so can display Optout option in UI.
Expand Down Expand Up @@ -118,7 +158,7 @@ public function groupDescriptions($groupName) {
$groupDescription = $this->grouperAPI->getGrouperGroupDescription($args);
//make call to get attributes for group
$grouperAtt = new GrouperAttribute();
$groupAttributes = $grouperAtt->groupAttributes($groupName);
$groupAttributes = $grouperAtt->getGroupAttributes($groupName);

$groupDescription[0]["attributes"] = $groupAttributes;

Expand Down Expand Up @@ -165,6 +205,7 @@ public function joinGroup(string $userId, string $groupName) {
return $this->grouperAPI->grouperGroupLeaveOrJoin($args);
}


public function ownerGroups($userId) {
$this->initApi();

Expand Down Expand Up @@ -221,6 +262,9 @@ public function createGroup($userId, $groupName, $stemName, $groupDesc) {
$args['conditions']['stemName'] = $stemName;
$args['conditions']['groupDescription'] = $groupDesc;

// Reset Session variable holding if User is an owner
$this->resetUserOwner();

return $this->grouperAPI->createUpdateGroup($args);
}

Expand Down

0 comments on commit badec4a

Please sign in to comment.