diff --git a/Controller/GrouperGroupsController.php b/Controller/GrouperGroupsController.php index 21e8a16..96df0fd 100644 --- a/Controller/GrouperGroupsController.php +++ b/Controller/GrouperGroupsController.php @@ -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(); } } @@ -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']); } /** @@ -78,7 +78,7 @@ public function groupOwner() { } else { $this->set('groupergroupsowner', $this->GrouperGroup->ownerGroups($this->userId)); } - + $this->set('isuserowner', $this->GrouperGroup->isUserOwner($this->userId)); } /** @@ -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)); + } /** @@ -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 diff --git a/Lib/GrouperApiAccess.php b/Lib/GrouperApiAccess.php index b529462..f451c5e 100644 --- a/Lib/GrouperApiAccess.php +++ b/Lib/GrouperApiAccess.php @@ -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')); } /** diff --git a/Model/GrouperAttribute.php b/Model/GrouperAttribute.php index 4d417d1..d1c865f 100644 --- a/Model/GrouperAttribute.php +++ b/Model/GrouperAttribute.php @@ -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; diff --git a/Model/GrouperGroup.php b/Model/GrouperGroup.php index 829e8bf..017677c 100644 --- a/Model/GrouperGroup.php +++ b/Model/GrouperGroup.php @@ -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 * @@ -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. @@ -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; @@ -165,6 +205,7 @@ public function joinGroup(string $userId, string $groupName) { return $this->grouperAPI->grouperGroupLeaveOrJoin($args); } + public function ownerGroups($userId) { $this->initApi(); @@ -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); }