diff --git a/Controller/GrouperGroupsController.php b/Controller/GrouperGroupsController.php index 871a95b..a5e1787 100644 --- a/Controller/GrouperGroupsController.php +++ b/Controller/GrouperGroupsController.php @@ -76,6 +76,8 @@ public function beforeFilter() { } $this->setConnection(); } + + //Need to verify if user is part of } /** @@ -217,6 +219,7 @@ public function groupOwner() { } $this->set('isuserowner', $this->GrouperGroup->isUserOwner($this->userId)); + $this->set('isTemplateUser', $this->GrouperGroup->isTemplateUser($this->userId)); } /** @@ -271,6 +274,7 @@ public function groupMember() { } } $this->set('isuserowner', $this->GrouperGroup->isUserOwner($this->userId)); + $this->set('isTemplateUser', $this->GrouperGroup->isTemplateUser($this->userId)); } /** @@ -322,6 +326,7 @@ public function groupOptin() { } } $this->set('isuserowner', $this->GrouperGroup->isUserOwner($this->userId)); + $this->set('isTemplateUser', $this->GrouperGroup->isTemplateUser($this->userId)); } //TODO - Need to combine this form with code below for groupCreate @@ -448,6 +453,7 @@ public function emaillistsOptin() { )); $this->set('isuserowner', $this->GrouperGroup->isUserOwner($this->userId)); + $this->set('isTemplateUser', $this->GrouperGroup->isTemplateUser($this->userId)); } public function emaillistsMember() @@ -463,6 +469,7 @@ public function emaillistsMember() )); $this->set('isuserowner', $this->GrouperGroup->isUserOwner($this->userId)); + $this->set('isTemplateUser', $this->GrouperGroup->isTemplateUser($this->userId)); } public function emaillistsManage() { @@ -477,6 +484,7 @@ public function emaillistsManage() { )); $this->set('isuserowner', $this->GrouperGroup->isUserOwner($this->userId)); + $this->set('isTemplateUser', $this->GrouperGroup->isTemplateUser($this->userId)); } public function emaillistInfo() { diff --git a/Lib/GrouperApiAccess.php b/Lib/GrouperApiAccess.php index 2b70e35..7fa0ff4 100644 --- a/Lib/GrouperApiAccess.php +++ b/Lib/GrouperApiAccess.php @@ -255,6 +255,30 @@ public function getOwnedGroups(array $queryData) { return array(); } + /** + * Gets all groups in Grouper where user is an admin/owner + * + * @param array $queryData Array of conditions for querying + * @return array Array of groups from Grouper + * @throws GrouperLiteException + * + */ + public function getUserTemplateAuth(array $queryData) { + $queryData['groupType'] = 'Owner'; + + try { + $results = $this->useMembershipUrl($queryData); + + if (isset($results['WsGetMembershipsResults']['wsGroups']) && $results['WsGetMembershipsResults']['wsGroups'] != NULL) { + return $results['WsGetMembershipsResults']['wsGroups']; + } + } catch (Exception $e) { + CakeLog::write('error', __METHOD__ . ': An error occurred'); + throw $e; + } + return array(); + } + /** * Get members associated to a specific Grouper Group * diff --git a/Model/GrouperGroup.php b/Model/GrouperGroup.php index 52bd4cb..1ef04ee 100644 --- a/Model/GrouperGroup.php +++ b/Model/GrouperGroup.php @@ -44,6 +44,8 @@ class GrouperGroup extends GrouperLiteAppModel private $totalRecords = 0; + private $templateGroup = 'ref:workinggroupadmins'; + /** * 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 @@ -81,6 +83,42 @@ public function isUserOwner(string $userId) { } } + public function isTemplateUser() { + if (CakeSession::check('Plugin.Grouper.isTemplateUser')) { + return CakeSession::read('Plugin.Grouper.isTemplateUser'); + } + + $this->initApi(); + + try { + $args = array(); + $args['userId'] = $userId; + + $memberOfGroups = $this->grouperAPI->getGrouperMemberOfGroups($args); + + //now cycle through and see if part of correct group to be able to use template + $member = 'F'; + foreach ($memberOfGroups as $memberOfGroup) { + if ($memberOfGroup['name'] == $this->templateGroup) { + $member = 'T'; + break; + } + } + + if ($member == 'T') { + CakeSession::write('Plugin.Grouper.isTemplateUser', 'T'); + return 'T'; + } + CakeSession::write('Plugin.Grouper.isTemplateUser', 'F'); + return 'F'; + + } catch (Exception $e) { + CakeLog::write('error', __METHOD__ . ': An error occurred'); + throw $e; + } + + } + /** * Used to instantiate API class *