Skip to content

Commit

Permalink
Grouper button visibility code
Browse files Browse the repository at this point in the history
  • Loading branch information
Axel Stohn authored and Axel Stohn committed Sep 29, 2022
1 parent 4875d33 commit cdc28ea
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 1 deletion.
7 changes: 7 additions & 0 deletions Controller/GrouperGroupsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down Expand Up @@ -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'),
Expand Down Expand Up @@ -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'),
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand All @@ -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));
}


Expand Down
52 changes: 51 additions & 1 deletion Model/GrouperGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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
*
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit cdc28ea

Please sign in to comment.