diff --git a/Controller/GrouperGroupsController.php b/Controller/GrouperGroupsController.php index 4900424..9ca510f 100644 --- a/Controller/GrouperGroupsController.php +++ b/Controller/GrouperGroupsController.php @@ -443,9 +443,11 @@ public function groupOwner() } } + $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'), @@ -521,6 +523,7 @@ public function groupMember() $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'), @@ -594,6 +597,7 @@ public function groupOptin() } $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'), @@ -893,6 +897,7 @@ public function emaillistsOptin() $this->set('isuserowner', $this->GrouperGroup->isUserOwner($this->userId)); $this->set('isTemplateUser', $this->GrouperGroup->isTemplateUser($this->userId)); + $this->set('isGrouperVisible', $this->GrouperGroup->isGrouperVisible($this->userId)); } public function emaillistsMember() @@ -949,6 +954,7 @@ public function emaillistsMember() $this->set('isuserowner', $this->GrouperGroup->isUserOwner($this->userId)); $this->set('isTemplateUser', $this->GrouperGroup->isTemplateUser($this->userId)); + $this->set('isGrouperVisible', $this->GrouperGroup->isGrouperVisible($this->userId)); } public function emaillistsManage() @@ -965,6 +971,7 @@ public function emaillistsManage() $this->set('isuserowner', $this->GrouperGroup->isUserOwner($this->userId)); $this->set('isTemplateUser', $this->GrouperGroup->isTemplateUser($this->userId)); + $this->set('isGrouperVisible', $this->GrouperGroup->isGrouperVisible($this->userId)); } diff --git a/Model/GrouperGroup.php b/Model/GrouperGroup.php index d286cf3..86381ab 100644 --- a/Model/GrouperGroup.php +++ b/Model/GrouperGroup.php @@ -47,6 +47,9 @@ class GrouperGroup extends GrouperLiteAppModel /** @var string Group whose members can create Groups via Template process */ private $templateCreationGroup = 'ref:workinggroupadmins'; + /** @var string Group whose members cannot see Grouper button, even if admin */ + private $grouperVisibleGroup = 'app:comanage:LiteUI:grouperNotVisible'; + private $wgStemsTopLevel = array( 'ref:incommon-collab', 'ref:internet2-collab' @@ -104,6 +107,53 @@ public function isUserOwner(string $userId) } } + /** + * Verifies if user can see the Grouper link button. Even if owner, may be not allowed to see it. + * + * @param string $userId Id of User + * @return String T or F + * @throws GrouperLiteException + * + */ + public function isGrouperVisible(string $userId) + { + if (CakeSession::check('Plugin.Grouper.isGrouperVisible')) { + return CakeSession::read('Plugin.Grouper.isGrouperVisible'); + } + + $this->initApi(); + + try { + $args = array(); + $args['userId'] = $userId; + + $memberOfGroups = $this->grouperAPI->getGrouperMemberOfGroups($args); + + $memberOfGroups = $this->grouperAPI->getGrouperMemberOfGroups($args); + + //now cycle through and see if part of correct group to be able to use template + $member = 'T'; + foreach ($memberOfGroups as $memberOfGroup) { + if ($memberOfGroup['name'] == $this->grouperVisibleGroup) { + $member = 'F'; + break; + } + } + + if ($member == 'T') { + CakeSession::write('Plugin.Grouper.isGrouperVisible', 'T'); + return 'T'; + } + CakeSession::write('Plugin.Grouper.isGrouperVisible', 'F'); + return 'F'; + + } catch (Exception $e) { + CakeLog::write('error', __METHOD__ . ': An error occurred'); + throw $e; + } + } + + /** * Used to instantiate API class * @@ -678,7 +728,7 @@ private function getFriendlyWorkingGroupName(array $groups, $method) } $group['WGApp'] = $appName; if ($method == 'member') { - if ($group['WGRole'] !== 'admins' && $group['WGRole'] !== 'owners') { + if ($group['WGRole'] !== 'admins' && $group['WGRole'] !== 'owner') { $workingGroups[] = $group; } } else {