From 9ab198d83aa71fc3e53450ed04a0efd9882be8fa Mon Sep 17 00:00:00 2001 From: Ioannis Igoumenos Date: Wed, 21 Feb 2024 12:46:26 +0200 Subject: [PATCH] Remove GrouperWidget folder.Add missing glid and coid url named parameters.Remove duplicate code. --- Controller/GrouperGroupsController.php | 134 ++++++++-------- GrouperWidget/Config/Schema/empty | 0 GrouperWidget/Console/Command/Task/empty | 0 GrouperWidget/Console/Templates/empty | 0 .../Controller/CoGrouperWidgetController.php | 71 --------- GrouperWidget/Controller/Component/empty | 0 .../Controller/GrouperWidgetAppController.php | 7 - GrouperWidget/Lib/empty | 0 GrouperWidget/Locale/eng/LC_MESSAGES/empty | 0 GrouperWidget/Model/Behavior/empty | 0 GrouperWidget/Model/CoGrouperWidget.php | 9 -- GrouperWidget/Model/Datasource/empty | 0 GrouperWidget/Model/GrouperWidget.php | 11 -- GrouperWidget/Model/GrouperWidgetAppModel.php | 7 - .../Test/Case/Controller/Component/empty | 0 GrouperWidget/Test/Case/Lib/empty | 0 GrouperWidget/Test/Case/Model/Behavior/empty | 0 .../Test/Case/Model/Datasource/empty | 0 GrouperWidget/Test/Case/View/Helper/empty | 0 GrouperWidget/Test/Fixture/empty | 0 GrouperWidget/View/Elements/empty | 0 GrouperWidget/View/Helper/empty | 0 GrouperWidget/View/Layouts/empty | 0 GrouperWidget/webroot/css/empty | 0 GrouperWidget/webroot/img/empty | 0 GrouperWidget/webroot/js/empty | 0 Lib/GrouperApiAccess.php | 148 ++++++------------ Lib/GrouperHTTPWrapper.php | 2 + Model/GrouperGroup.php | 51 +++--- .../Components/navigation-emaillists.ctp | 20 ++- .../Elements/Components/navigation-groups.ctp | 24 ++- View/Elements/Components/subscriberList.ctp | 21 ++- View/Elements/Components/vue-table.ctp | 4 +- View/GrouperGroups/groupmember.ctp | 5 +- View/GrouperGroups/groupoptin.ctp | 5 +- View/GrouperGroups/index.ctp | 12 +- 36 files changed, 199 insertions(+), 332 deletions(-) delete mode 100644 GrouperWidget/Config/Schema/empty delete mode 100644 GrouperWidget/Console/Command/Task/empty delete mode 100644 GrouperWidget/Console/Templates/empty delete mode 100644 GrouperWidget/Controller/CoGrouperWidgetController.php delete mode 100644 GrouperWidget/Controller/Component/empty delete mode 100644 GrouperWidget/Controller/GrouperWidgetAppController.php delete mode 100644 GrouperWidget/Lib/empty delete mode 100644 GrouperWidget/Locale/eng/LC_MESSAGES/empty delete mode 100644 GrouperWidget/Model/Behavior/empty delete mode 100644 GrouperWidget/Model/CoGrouperWidget.php delete mode 100644 GrouperWidget/Model/Datasource/empty delete mode 100644 GrouperWidget/Model/GrouperWidget.php delete mode 100644 GrouperWidget/Model/GrouperWidgetAppModel.php delete mode 100644 GrouperWidget/Test/Case/Controller/Component/empty delete mode 100644 GrouperWidget/Test/Case/Lib/empty delete mode 100644 GrouperWidget/Test/Case/Model/Behavior/empty delete mode 100644 GrouperWidget/Test/Case/Model/Datasource/empty delete mode 100644 GrouperWidget/Test/Case/View/Helper/empty delete mode 100644 GrouperWidget/Test/Fixture/empty delete mode 100644 GrouperWidget/View/Elements/empty delete mode 100644 GrouperWidget/View/Helper/empty delete mode 100644 GrouperWidget/View/Layouts/empty delete mode 100644 GrouperWidget/webroot/css/empty delete mode 100644 GrouperWidget/webroot/img/empty delete mode 100644 GrouperWidget/webroot/js/empty diff --git a/Controller/GrouperGroupsController.php b/Controller/GrouperGroupsController.php index 1967991..21dfedd 100644 --- a/Controller/GrouperGroupsController.php +++ b/Controller/GrouperGroupsController.php @@ -39,7 +39,7 @@ class GrouperGroupsController extends GrouperLiteWidgetAppController { public $helpers = array('Html', 'Form', 'Flash'); - // Dynamic properties are deprecated so we will define the property here + // Dynamic properties are deprecated, so we will define the property here protected $userId = null; public $uses = array( @@ -108,8 +108,8 @@ public function beforeRender() { $this->set('title', _txt('pl.grouperlite.title.groupmember')); $this->set('vv_is_user_owner', $this->GrouperGroup->isUserOwner($this->userId ?? '', $cfg) ); - $this->set('vv_is_template_user', $this->GrouperGroup->isTemplateUser($this->userId ?? '', $cfg) ); - $this->set('vv_is_grouper_visible', $this->GrouperGroup->isGrouperVisible($this->userId ?? '', $cfg)); +// $this->set('vv_is_template_user', $this->GrouperGroup->isTemplateUser($this->userId ?? '', $cfg) ); +// $this->set('vv_is_grouper_visible', $this->GrouperGroup->isGrouperVisible($this->userId ?? '', $cfg)); $this->set('vv_coid', $this->cur_co['Co']['id']); } @@ -118,12 +118,13 @@ public function beforeRender() { * * @return CakeResponse Redirect to MyMembership page */ - public function index() {} + public function index(): void + {} /** * @return void */ - public function groupMember() + public function groupMember(): void { $this->render('index'); } @@ -131,7 +132,7 @@ public function groupMember() /** * @return void */ - public function groupOptin() + public function groupOptin(): void { $this->render('index'); } @@ -139,7 +140,7 @@ public function groupOptin() /** * @return void */ - public function groupOwner() + public function groupOwner(): void { $this->render('index'); } @@ -149,7 +150,7 @@ public function groupOwner() * Called from all pages via AJAX call * */ - public function groupSubscribers() + public function groupSubscribers(): void { $groupName = urldecode($this->request->query['groupname']); $subscribers = 0; @@ -190,35 +191,29 @@ public function groupSubscribers() * Called from all pages via AJAX call * */ - public function addSubscriber() { + public function addSubscriber(): void + { $groupName = urldecode($this->request->query['group']); $addUserId = urldecode($this->request->query['userId']); - $resultAdd = ''; + $resultAdd = false; //Need to see if coming from AdHoc or from a WG (Working Group) $groupNameFormatted = strpos($groupName, ':') === false ? 'ref:incommon-collab:' . $groupName . ':users' : $groupName; - //Set initial - $scope = [ - 'groupName' => $groupNameFormatted, - 'addUserId' => $addUserId - ]; try { - $resultAdd = $this->GrouperGroup->addGrouperGroupMember($scope, - $this->userId, + $resultAdd = $this->GrouperGroup->addGrouperGroupMember($this->userId, + $groupNameFormatted, + $addUserId, $this->CoGrouperLiteWidget->getConfig()); CakeLog::write('debug', __METHOD__ . '::response: ' . var_export($resultAdd, true)); } catch (Exception $e) { +// $this->restResponse(HttpStatusCodesEnum::HTTP_UNAUTHORIZED, ErrorsEnum::NotAdded); CakeLog::write('error', __METHOD__ . ': ' . var_export($e->getMessage(), true)); + $this->restResponse(HttpStatusCodesEnum::HTTP_NOT_FOUND, ErrorsEnum::Exception); } - if ($resultAdd !== 'SUCCESS') { - $this->restResponse(HttpStatusCodesEnum::HTTP_UNAUTHORIZED, ErrorsEnum::Error); - $resultAdd = ''; - } - - $this->set(compact('resultAdd')); + $this->set(compact($resultAdd ? GrouperResultCodesEnum::SUCCESS : '')); $this->set('_serialize', 'resultAdd'); } @@ -336,24 +331,24 @@ public function findSubscriber() { * Remove a member from a group * Called from all pages via AJAX call * + * TODO: We should probably save extra metadata in a data attribute and then pass that attribute to the request and not + * the Human Readable name + * TODO: We need to appropriately handle Unathenticated call. We have to bubble up the response and do something. */ - public function removeSubscriber() { + public function removeSubscriber(): void + { $groupName = urldecode($this->request->query['group']); $remUserId = urldecode($this->request->query['userId']); - $resultRemove = ''; + $resultRemove = false; //Need to see if coming from AdHoc or from a WG (Working Group) $groupNameFormatted = (strpos($groupName, ':') === false) ? 'ref:incommon-collab:' . $groupName . ':users' : $groupName; - //Set initial - $scope = [ - 'groupName' => $groupNameFormatted, - 'remUserId' => $remUserId - ]; try { - $resultRemove = $this->GrouperGroup->removeGrouperGroupMember($scope, - $this->userId, + $resultRemove = $this->GrouperGroup->removeGrouperGroupMember($this->userId, + $groupNameFormatted, + $remUserId, $this->CoGrouperLiteWidget->getConfig()); CakeLog::write('debug', __METHOD__ . '::response: ' . var_export($resultRemove, true)); @@ -361,12 +356,11 @@ public function removeSubscriber() { CakeLog::write('error', __METHOD__ . ': ' . var_export($e->getMessage(), true)); } - if ($resultRemove != 'SUCCESS') { + if (!$resultRemove) { $this->restResponse(HttpStatusCodesEnum::HTTP_NOT_FOUND, ErrorsEnum::Error); - $resultRemove = ''; } - $this->set(compact('resultRemove')); + $this->set(compact($resultRemove ? GrouperResultCodesEnum::SUCCESS : '')); $this->set('_serialize', 'resultRemove'); } @@ -529,56 +523,51 @@ public function groupCreateTemplate() /** * Process to join a group displayed on the "Optin" page * - * @return CakeResponse Redirect back to "Optin" page */ - public function joinGroup() + public function joinGroup(): void { - $resultAdd = 'Success'; $name = urldecode($this->request->query['GroupName']); - $display = urldecode($this->request->query['GroupDisplayName']); + $resultAdd = false; try { - if (!$this->GrouperGroup->joinGroup($this->userId, - $name, - $this->CoGrouperLiteWidget->getConfig())) { - $this->restResponse(HttpStatusCodesEnum::HTTP_UNAUTHORIZED, ErrorsEnum::NotAdded); - $resultAdd = ''; - } + // Add myself + $resultAdd = $this->GrouperGroup->joinGroup($this->userId, + $name, + $this->CoGrouperLiteWidget->getConfig()); } catch (Exception $e) { CakeLog::write('error', __METHOD__ . ': ' . var_export($e->getMessage(), true)); +// $this->restResponse(HttpStatusCodesEnum::HTTP_UNAUTHORIZED, ErrorsEnum::NotAdded); $this->restResponse(HttpStatusCodesEnum::HTTP_NOT_FOUND, ErrorsEnum::Exception); - $resultAdd = ''; } - $this->set(compact('resultAdd')); + $this->set(compact($resultAdd ? GrouperResultCodesEnum::SUCCESS : '')); $this->set('_serialize', 'resultAdd'); } /** * Process to leave a group displayed on the "Member Of" page * - * @return CakeResponse Redirect back to "Member Of" page */ - public function leaveGroup() + public function leaveGroup(): void { $name = urldecode($this->request->query['GroupName']); - $display = urldecode($this->request->query['GroupDisplayName']); - $resultRemove = 'Success'; + $resultRemove = false; try { - if (!$this->GrouperGroup->leaveGroup($this->userId, - $name, - $this->CoGrouperLiteWidget->getConfig())) { - $this->restResponse(HttpStatusCodesEnum::HTTP_UNAUTHORIZED, ErrorsEnum::NotDeleted); - $resultRemove = ''; - } + $resultRemove = $this->GrouperGroup->leaveGroup($this->userId, + $name, + $this->CoGrouperLiteWidget->getConfig()); } catch (Exception $e) { CakeLog::write('error', __METHOD__ . ': ' . var_export($e->getMessage(), true)); - $this->restResponse(HttpStatusCodesEnum::HTTP_NOT_FOUND, ErrorsEnum::Exception); - $resultRemove = ''; } - $this->set(compact('resultRemove')); +// $this->restResponse(HttpStatusCodesEnum::HTTP_UNAUTHORIZED, ErrorsEnum::NotDeleted); + + if (!$resultRemove) { + $this->restResponse(HttpStatusCodesEnum::HTTP_NOT_FOUND, ErrorsEnum::Error); + } + + $this->set(compact($resultRemove ? GrouperResultCodesEnum::SUCCESS : '')); $this->set('_serialize', 'resultRemove'); } @@ -590,10 +579,10 @@ public function leaveGroup() * - precondition: Session.Auth holds data used for authz decisions * - postcondition: $permissions set with calculated permissions * - * @return Array Permissions + * @return array|bool Permissions * @since COmanage Registry v3.2.0 */ - function isAuthorized() + function isAuthorized(): array|bool { $roles = $this->Role->calculateCMRoles(); $cfg = $this->CoGrouperLiteWidget->getConfig(); @@ -673,7 +662,8 @@ private function breakoutGroups(array $recordSet) * @return Boolean True if sanity check is successful */ - public function verifyRequestedId() { + public function verifyRequestedId(): bool + { return true; } @@ -686,17 +676,17 @@ public function verifyRequestedId() { * @return Integer The CO ID if found, or -1 if not */ - public function parseCOID($data = null) { - if(!empty($this->request->params["named"]["co"])) { - return $this->request->params["named"]["co"]; + public function parseCOID($data = null): int { + if(!empty($this->request->params['named']['co'])) { + return (int)$this->request->params['named']['co']; } - if(!empty($this->request->params["named"]["glid"])) { + if(!empty($this->request->params['named']['glid'])) { $connectionInfo = $this->CoGrouperLiteWidget->findById($this->passedArgs['glid']); - $this->CoGrouperLiteWidget->CoDashboardWidget->CoDashboard->id = $connectionInfo["CoDashboardWidget"]["co_dashboard_id"]; + $this->CoGrouperLiteWidget->CoDashboardWidget->CoDashboard->id = $connectionInfo['CoDashboardWidget']['co_dashboard_id']; $co_id = $this->CoGrouperLiteWidget->CoDashboardWidget->CoDashboard->field('co_id'); if(!empty($co_id)) { - return $co_id; + return (int)$co_id; } } @@ -704,9 +694,6 @@ public function parseCOID($data = null) { } /** - * Prepare a REST result HTTP header. - * - precondition: HTTP headers must not yet have been sent - * - postcondition: CakeResponse configured with header * * @param integer $status HTTP result code * @param array $body HTTP result comment @@ -720,7 +707,8 @@ public function parseCOID($data = null) { public function restResponse(int $status, array $body=[], string $contentType = 'json', - ?string $statusTxt = null) { + ?string $statusTxt = null): void + { if(isset($statusTxt)) { // We need to update the text associated with $status $this->response->httpCodes(array($status => $statusTxt)); diff --git a/GrouperWidget/Config/Schema/empty b/GrouperWidget/Config/Schema/empty deleted file mode 100644 index e69de29..0000000 diff --git a/GrouperWidget/Console/Command/Task/empty b/GrouperWidget/Console/Command/Task/empty deleted file mode 100644 index e69de29..0000000 diff --git a/GrouperWidget/Console/Templates/empty b/GrouperWidget/Console/Templates/empty deleted file mode 100644 index e69de29..0000000 diff --git a/GrouperWidget/Controller/CoGrouperWidgetController.php b/GrouperWidget/Controller/CoGrouperWidgetController.php deleted file mode 100644 index 5759dc2..0000000 --- a/GrouperWidget/Controller/CoGrouperWidgetController.php +++ /dev/null @@ -1,71 +0,0 @@ -CoServicesWidget->getConfig(); - - // For now simply provide the services portal URL for the current CO. All necessary - // logic is already attended to there. See: Views/CoServices/portal.ctp - $services_url = Router::url([ - 'plugin' => null, - 'controller' => 'co_services', - 'action' => 'portal', - 'co' => $this->cur_co['Co']['id'] - ]); - $this->set('vv_services_url', $services_url); - - // Pass the config so we know which div to overwrite - $this->set('vv_config', $cfg); - - } - - /** - * Authorization for this Controller, called by Auth component - * - precondition: Session.Auth holds data used for authz decisions - * - postcondition: $permissions set with calculated permissions - * - * @since COmanage Registry v3.2.0 - * @return Array Permissions - */ - - function isAuthorized() { - //TODO - Need to work on this - - $roles = $this->Role->calculateCMRoles(); - - // Determine what operations this user can perform - - // Construct the permission set for this user, which will also be passed to the view. - // Ask the parent to calculate the display permission, based on the configuration. - // Note that the display permission is set at the Dashboard, not Dashboard Widget level. - $p = $this->calculateParentPermissions($roles); - - // Delete an existing CO Services Widget? - $p['delete'] = ($roles['cmadmin'] || $roles['coadmin']); - - // Edit an existing CO Services Widget? - $p['edit'] = ($roles['cmadmin'] || $roles['coadmin']); - - // View an existing CO Services Widget? - $p['view'] = ($roles['cmadmin'] || $roles['coadmin']); - - $this->set('permissions', $p); - return($p[$this->action]); - } - -} diff --git a/GrouperWidget/Controller/Component/empty b/GrouperWidget/Controller/Component/empty deleted file mode 100644 index e69de29..0000000 diff --git a/GrouperWidget/Controller/GrouperWidgetAppController.php b/GrouperWidget/Controller/GrouperWidgetAppController.php deleted file mode 100644 index 8255498..0000000 --- a/GrouperWidget/Controller/GrouperWidgetAppController.php +++ /dev/null @@ -1,7 +0,0 @@ -urlGrouperEncode($groupName); $actionEndpoint = "/groups/$groupName/members"; //Build request logic $usersToAdd = [ 'WsRestAddMemberRequest' => [ 'subjectLookups' => [ - ['subjectId' => $queryData['addUserId']], + ['subjectId' => $addUserId], ], 'replaceAllExisting' => 'F', 'actAsSubjectLookup' => [ - 'subjectId' => $queryData['userId'] + 'subjectId' => $actAsUserId ] ] ]; @@ -108,7 +121,8 @@ public function addGrouperGroupMember(array $queryData): string throw $e; } - return $results['WsAddMemberResults']['results'][0]['resultMetadata']['resultCode'] ?? ''; + return isset($results['WsAddMemberResults']['wsGroupAssigned']) + && $results['WsAddMemberResults']['wsGroupAssigned']['name'] === urldecode($groupName); } /** @@ -502,92 +516,6 @@ public function getOwnedStems(array $queryData) return $results['WsGetMembershipsResults']['wsStems'] ?? []; } - /** - * For Optin groups, calls Grouper WS to join a group - * - * @param string $userId - * @param string $groupName - * - * @return bool True if join or leave successful, False if not - * @throws GrouperLiteWidgetException - * @throws JsonException - */ - public function joinGrouperGroup(string $userId, string $groupName) - { - if(empty($userId) || empty($groupName)) { - return false; - } - - //Build request logic - $groupCommand = [ - 'WsRestAddMemberRequest' => [ - 'actAsSubjectLookup' => [ - 'subjectId' => $userId - ], - 'replaceAllExisting' => 'F', - 'subjectLookups' => [ - ['subjectId' => $userId] - ] - ] - ]; - - $actionEndpoint = "/groups/{$groupName}/members"; - - try { - $results = $this->http->sendRequest('PUT', - $actionEndpoint, - json_encode($groupCommand, JSON_THROW_ON_ERROR)); - } catch (Exception $e) { - CakeLog::write('error', __METHOD__ . ': An error occurred'); - throw $e; - } - - return isset($results['WsAddMemberResults']['wsGroupAssigned']) - && $results['WsAddMemberResults']['wsGroupAssigned']['name'] == urldecode($groupName); - } - - /** - * For Optin groups, calls Grouper WS to join or leave a group - * - * @param array $queryData Array of conditions for querying - * - * @return bool True if join or leave successful, False if not - * @throws GrouperLiteWidgetException|JsonException - */ - public function leaveGrouperGroup(string $userId, string $groupName) - { - if(empty($userId) || empty($groupName)) { - return false; - } - - //Build request logic - $groupCommand = [ - '$memberRequest' => [ - 'actAsSubjectLookup' => [ - 'subjectId' => $userId - ], - 'replaceAllExisting' => 'F', - 'subjectLookups' => [ - ['subjectId' => $userId] - ] - ] - ]; - - $actionEndpoint = "/groups/{$groupName}/members"; - - try { - $results = $this->http->sendRequest('PUT', - $actionEndpoint, - json_encode($groupCommand, JSON_THROW_ON_ERROR)); - } catch (Exception $e) { - CakeLog::write('error', __METHOD__ . ': An error occurred'); - throw $e; - } - - return isset($results['WsDeleteMemberResults']['wsGroup']) - && $results['WsDeleteMemberResults']['wsGroup']['name'] == urldecode($groupName); - } - /** * Is the user member of the Group * @@ -598,7 +526,7 @@ public function leaveGrouperGroup(string $userId, string $groupName) * * @throws GrouperLiteWidgetException */ - public function isMemberOf(string $groupName, string $userId): bool + public function isMemberOfGrouperGroup(string $groupName, string $userId): bool { if(empty($userId) || empty($groupName)) { return []; @@ -653,26 +581,37 @@ public function removeDuplicates(array $arrOne, array $arrTwo) /** * Remove a member from a specific Grouper Group * - * @param array $queryData Array of conditions for querying + * @param string $actAsUserId The actor of the remove action + * @param string $groupName Group to remove the member from + * @param string $removeUserId User to be removed from the Group * - * @return string Requests success or not + * @return bool True on success, false otherwise * * @throws GrouperLiteWidgetException * @throws JsonException */ - public function removeGrouperGroupMember(array $queryData) + public function removeGrouperGroupMember(string $actAsUserId, + string $groupName, + string $removeUserId): bool { - $groupName = $queryData['groupName']; + if(empty($actAsUserId) + || empty($groupName) + || empty($removeUserId) + ) { + return false; + } + // We have to urlencode the Group Names passed in the url + $groupName = $this->urlGrouperEncode($groupName); $actionEndpoint = "/groups/$groupName/members"; //Build request logic $userToDelete = [ 'WsRestDeleteMemberRequest' => [ 'subjectLookups' => [ - ['subjectId' => $queryData['remUserId']], + ['subjectId' => $removeUserId], ], 'actAsSubjectLookup' => [ - 'subjectId' => $queryData['userId'] + 'subjectId' => $actAsUserId ] ] ]; @@ -688,7 +627,8 @@ public function removeGrouperGroupMember(array $queryData) } // Parse out relevant records to send front end - return $results['WsDeleteMemberResults']['results'][0]['resultMetadata']['resultCode'] ?? ''; + return isset($results['WsDeleteMemberResults']['resultMetadata']['resultCode']) + && $results['WsDeleteMemberResults']['resultMetadata']['resultCode'] === GrouperResultCodesEnum::SUCCESS; } /** @@ -698,7 +638,8 @@ public function removeGrouperGroupMember(array $queryData) * * @return string */ - public function urlGrouperEncode(string $url) { + public function urlGrouperEncode(string $url): string + { $url = urlencode($url); return str_replace(':', '%3A', $url); } @@ -740,7 +681,6 @@ private function useMembershipUrl(array $queryData) $groupsToShow['WsRestGetMembershipsRequest']['wsSubjectLookups'][1]['subjectId'] = $userId; } - $this->http->setHeader(array('Content-Type' => 'application/json', 'Accept' => 'application/json')); $actionEndpoint = "/memberships"; try { diff --git a/Lib/GrouperHTTPWrapper.php b/Lib/GrouperHTTPWrapper.php index 8a7725a..00a29f9 100644 --- a/Lib/GrouperHTTPWrapper.php +++ b/Lib/GrouperHTTPWrapper.php @@ -172,6 +172,8 @@ public function setUser(string $user): void * @param string $body JSON formatted request, if applicable * @return array array of records | array with error message * @throws GrouperLiteWidgetException If issue with Grouper WS connection + * + * TODO: Handle unauthorized request-responses */ public function sendRequest(string $method, string $endPoint, string $body = ''): array { $uri = "{$this->_serviceUrl}{$endPoint}"; diff --git a/Model/GrouperGroup.php b/Model/GrouperGroup.php index 18d776e..58216f0 100644 --- a/Model/GrouperGroup.php +++ b/Model/GrouperGroup.php @@ -106,12 +106,12 @@ public function isUserOwner(string $userId, array $cfg) * * @since COmanage Registry v4.4.0 */ - public function isGrouperVisible(string $userId, array $cfg) + public function isGrouperVisible(string $userId, array $cfg): string { $this->initApi($cfg); try { - $isMember = $this->grouperAPI->isMemberOf(GrouperSpecialGroups::GROUPER_VISIBLE_GROUP, $userId); + $isMember = $this->grouperAPI->isMemberOfGrouperGroup(GrouperSpecialGroups::GROUPER_VISIBLE_GROUP, $userId); } catch (Exception $e) { CakeLog::write('error', __METHOD__ . ': An error occurred'); throw $e; @@ -201,12 +201,15 @@ private function memberOfGroups(array $conditions, array $cfg) * * @since COmanage Registry v4.4.0 */ - public function leaveGroup(string $userId, string $groupName, array $cfg) + public function leaveGroup(string $userId, string $groupName, array $cfg): bool { $this->initApi($cfg); try { - return $this->grouperAPI->leaveGrouperGroup($userId, $groupName); + return $this->grouperAPI->removeGrouperGroupMember($userId, + $groupName, + $userId // Remove myself from the Group + ); } catch (Exception $e) { CakeLog::write('error', __METHOD__ . ': An error occurred'); throw $e; @@ -223,12 +226,12 @@ public function leaveGroup(string $userId, string $groupName, array $cfg) * * @since COmanage Registry v4.4.0 */ - public function joinGroup(string $userId, string $groupName, array $cfg) + public function joinGroup(string $userId, string $groupName, array $cfg): bool { $this->initApi($cfg); try { - return $this->grouperAPI->joinGrouperGroup($userId, $groupName); + return $this->grouperAPI->addGrouperGroupMember($userId, $groupName, $userId); } catch (Exception $e) { CakeLog::write('error', __METHOD__ . ': An error occurred'); throw $e; @@ -298,21 +301,22 @@ public function membersInGroup(array $conditions, string $userId, array $cfg) /** * Add a member to a specific Grouper Group * - * @param array $conditions Listing of conditions for display of records - * @param string $userId Id of User + * @param string $userId Id of User + * @param string $groupName + * @param string $addUserId + * @param array $cfg + * * @return string success of Request * @throws GrouperLiteWidgetException Captured in Controller - * + * @throws JsonException * @since COmanage Registry v4.4.0 */ - public function addGrouperGroupMember(array $conditions, string $userId, array $cfg) + public function addGrouperGroupMember(string $userId, string $groupName, string $addUserId, array $cfg) { $this->initApi($cfg); - $conditions['userId'] = $userId; - try { - return $this->grouperAPI->addGrouperGroupMember($conditions); + return $this->grouperAPI->addGrouperGroupMember($userId, $groupName, $addUserId); } catch (Exception $e) { CakeLog::write('error', __METHOD__ . ': An error occurred'); throw $e; @@ -322,21 +326,24 @@ public function addGrouperGroupMember(array $conditions, string $userId, array $ /** * Remove a member from a specific Grouper Group * - * @param array $conditions Listing of conditions for display of records - * @param string $userId Id of User - * @return string success of Request - * @throws GrouperLiteWidgetException Captured in Controller + * @param string $userId Id of User + * @param string $groupName + * @param string $removeUserId + * @param array $cfg * + * @return bool success of Request + * @throws GrouperLiteWidgetException Captured in Controller + * @throws JsonException Captured in Controller * @since COmanage Registry v4.4.0 */ - public function removeGrouperGroupMember(array $conditions, string $userId, array $cfg) + public function removeGrouperGroupMember(string $userId, string $groupName, string $removeUserId, array $cfg): bool { $this->initApi($cfg); - $conditions['userId'] = $userId; - try { - return $this->grouperAPI->removeGrouperGroupMember($conditions); + return $this->grouperAPI->removeGrouperGroupMember($userId, + $groupName, + $removeUserId); } catch (Exception $e) { CakeLog::write('error', __METHOD__ . ': An error occurred'); throw $e; @@ -389,7 +396,7 @@ public function isTemplateUser(string $userId, array $cfg) $this->initApi($cfg); try { - $isMember = $this->grouperAPI->isMemberOf(GrouperSpecialGroups::TEMPLATE_CREATION_GROUP, $userId); + $isMember = $this->grouperAPI->isMemberOfGrouperGroup(GrouperSpecialGroups::TEMPLATE_CREATION_GROUP, $userId); } catch (Exception $e) { CakeLog::write('error', __METHOD__ . ': An error occurred'); throw $e; diff --git a/View/Elements/Components/navigation-emaillists.ctp b/View/Elements/Components/navigation-emaillists.ctp index 9a1b34a..c4b796c 100644 --- a/View/Elements/Components/navigation-emaillists.ctp +++ b/View/Elements/Components/navigation-emaillists.ctp @@ -6,7 +6,9 @@ _txt('pl.grouperlite.nav.emaillists-member'), array( 'controller' => 'grouper_groups', - 'action' => 'emaillistsmember' + 'action' => 'emaillistsmember', + 'co' => $vv_coid, + 'glid' => $vv_config['CoGrouperLiteWidget']['id'], ), array('class' => array('nav-link', $active == 'emaillistsmember' ? 'active' : '')) ) @@ -18,7 +20,9 @@ _txt('pl.grouperlite.nav.emaillists-join'), array( 'controller' => 'grouper_groups', - 'action' => 'emaillistsoptin' + 'action' => 'emaillistsoptin', + 'co' => $vv_coid, + 'glid' => $vv_config['CoGrouperLiteWidget']['id'], ), array('class' => array('nav-link', $active == 'emaillistsoptin' ? 'active' : '')) ) @@ -30,7 +34,9 @@ _txt('pl.grouperlite.nav.emaillists-manage'), array( 'controller' => 'grouper_groups', - 'action' => 'emaillistsmanage' + 'action' => 'emaillistsmanage', + 'co' => $vv_coid, + 'glid' => $vv_config['CoGrouperLiteWidget']['id'], ), array('class' => array('nav-link', $active == 'emaillistsmanage' ? 'active' : '')) ) @@ -43,7 +49,9 @@ $createTemplateGroupUrl = $this->Html->url( array( 'controller' => 'grouper_groups', - 'action' => 'groupcreatetemplate' + 'action' => 'groupcreatetemplate', + 'co' => $vv_coid, + 'glid' => $vv_config['CoGrouperLiteWidget']['id'], ) ); ?> @@ -57,7 +65,9 @@ $gotoGroupsUrl = $this->Html->url( array( 'controller' => 'grouper_groups', - 'action' => 'groupmember' + 'action' => 'groupmember', + 'co' => $vv_coid, + 'glid' => $vv_config['CoGrouperLiteWidget']['id'], ) ); ?> diff --git a/View/Elements/Components/navigation-groups.ctp b/View/Elements/Components/navigation-groups.ctp index 1163f8a..4b0edd1 100644 --- a/View/Elements/Components/navigation-groups.ctp +++ b/View/Elements/Components/navigation-groups.ctp @@ -6,7 +6,9 @@ _txt('pl.grouperlite.nav.memberships'), array( 'controller' => 'grouper_groups', - 'action' => 'groupmember' + 'action' => 'groupmember', + 'co' => $vv_coid, + 'glid' => $vv_config['CoGrouperLiteWidget']['id'], ), array('class' => array('nav-link', $active == 'groupmember' ? 'active' : '')) ) @@ -18,7 +20,9 @@ _txt('pl.grouperlite.nav.groups-can-join'), array( 'controller' => 'grouper_groups', - 'action' => 'groupoptin' + 'action' => 'groupoptin', + 'co' => $vv_coid, + 'glid' => $vv_config['CoGrouperLiteWidget']['id'], ), array('class' => array('nav-link', $active == 'groupoptin' ? 'active' : '')) ) @@ -30,7 +34,9 @@ _txt('pl.grouperlite.nav.groups-presided'), array( 'controller' => 'grouper_groups', - 'action' => 'groupowner' + 'action' => 'groupowner', + 'co' => $vv_coid, + 'glid' => $vv_config['CoGrouperLiteWidget']['id'], ), array('class' => array('nav-link', $active == 'groupowner' ? 'active' : '')) ) @@ -42,7 +48,9 @@ _txt('pl.grouperlite.nav.users-presided'), array( 'controller' => 'grouper_groups', - 'action' => 'userowner' + 'action' => 'userowner', + 'co' => $vv_coid, + 'glid' => $vv_config['CoGrouperLiteWidget']['id'], ), array('class' => array('nav-link', $active == 'groupowner' ? 'active' : '')) ) @@ -55,7 +63,9 @@ $createGroupUrl = $this->Html->url( array( 'controller' => 'grouper_groups', - 'action' => 'groupcreate' + 'action' => 'groupcreate', + 'co' => $vv_coid, + 'glid' => $vv_config['CoGrouperLiteWidget']['id'], ) ); $createGroupUrl = '#'; @@ -71,7 +81,9 @@ $createTemplateGroupUrl = $this->Html->url( array( 'controller' => 'grouper_groups', - 'action' => 'groupcreatetemplate' + 'action' => 'groupcreatetemplate', + 'co' => $vv_coid, + 'glid' => $vv_config['CoGrouperLiteWidget']['id'], ) ); ?> diff --git a/View/Elements/Components/subscriberList.ctp b/View/Elements/Components/subscriberList.ctp index 100673e..909c0ca 100644 --- a/View/Elements/Components/subscriberList.ctp +++ b/View/Elements/Components/subscriberList.ctp @@ -85,9 +85,11 @@ var load, modal, group; var loadUrl = 'Html->url( array( - 'plugin' => "grouper_lite", + 'plugin' => 'grouper_lite', 'controller' => 'grouper_groups', - 'action' => 'groupSubscribers' + 'action' => 'groupSubscribers', + 'co' => $vv_coid, + 'glid' => $vv_config['CoGrouperLiteWidget']['id'], ) ); ?>'; @@ -95,7 +97,9 @@ array( 'plugin' => "grouper_lite", 'controller' => 'grouper_groups', - 'action' => 'removeSubscriber' + 'action' => 'removeSubscriber', + 'co' => $vv_coid, + 'glid' => $vv_config['CoGrouperLiteWidget']['id'], ) ); ?>'; @@ -103,7 +107,9 @@ array( 'plugin' => "grouper_lite", 'controller' => 'grouper_groups', - 'action' => 'addSubscriber' + 'action' => 'addSubscriber', + 'co' => $vv_coid, + 'glid' => $vv_config['CoGrouperLiteWidget']['id'], ) ); ?>'; $('.members-btn').click(function(ev) { @@ -125,13 +131,6 @@ function attachAutoComplete() { $("#addUser").autocomplete({ - /*source: "< ?php print $this->Html->url( - array( - 'controller' => 'grouper_groups', - 'action' => 'findSubscriber', - '?' => array('co' => $config['co']) - ) - ); ?>&mode=All",*/ source: [].concat(test, test, test, test, test, test, test, test, test, test, test, test, test, test, test, test, test, test, test), minLength: 3, select: function(event, ui) { diff --git a/View/Elements/Components/vue-table.ctp b/View/Elements/Components/vue-table.ctp index f0a0634..21faffa 100644 --- a/View/Elements/Components/vue-table.ctp +++ b/View/Elements/Components/vue-table.ctp @@ -44,7 +44,9 @@ find: "Html->url( array( 'controller' => 'grouper_groups', - 'action' => 'findSubscriber' + 'action' => 'findSubscriber', + 'co' => $vv_coid, + 'glid' => $vv_config['CoGrouperLiteWidget']['id'], ) ) ?>", remove: "webroot ?>grouper_lite_widget/grouper_groups/removeSubscriber/co:/glid:", diff --git a/View/GrouperGroups/groupmember.ctp b/View/GrouperGroups/groupmember.ctp index 034224f..82428f8 100644 --- a/View/GrouperGroups/groupmember.ctp +++ b/View/GrouperGroups/groupmember.ctp @@ -16,7 +16,10 @@ )), 'optAction' => "leavegroup", 'actionUrl' => $this->Html->url([ - 'controller' => 'grouper_groups', 'action' => 'leavegroup' + 'controller' => 'grouper_groups', + 'action' => 'leavegroup', + 'co' => $vv_coid, + 'glid' => $vv_config['CoGrouperLiteWidget']['id'], ]), 'members' => true, 'addSubscribers' => false, diff --git a/View/GrouperGroups/groupoptin.ctp b/View/GrouperGroups/groupoptin.ctp index fcf02f9..e5cfa4d 100644 --- a/View/GrouperGroups/groupoptin.ctp +++ b/View/GrouperGroups/groupoptin.ctp @@ -16,7 +16,10 @@ )), 'optAction' => "joingroup", 'actionUrl' => $this->Html->url([ - 'controller' => 'grouper_groups', 'action' => 'joingroup' + 'controller' => 'grouper_groups', + 'action' => 'joingroup', + 'co' => $vv_coid, + 'glid' => $vv_config['CoGrouperLiteWidget']['id'], ]), )); ?> diff --git a/View/GrouperGroups/index.ctp b/View/GrouperGroups/index.ctp index 7e8d97f..8d076f1 100644 --- a/View/GrouperGroups/index.ctp +++ b/View/GrouperGroups/index.ctp @@ -119,19 +119,25 @@ find: "Html->url( array( 'controller' => 'grouper_groups', - 'action' => 'findSubscriber' + 'action' => 'findSubscriber', + 'co' => $vv_coid, + 'glid' => $vv_config['CoGrouperLiteWidget']['id'], ) ) ?>", join: "Html->url( array( 'controller' => 'grouper_groups', - 'action' => 'joinGroup' + 'action' => 'joinGroup', + 'co' => $vv_coid, + 'glid' => $vv_config['CoGrouperLiteWidget']['id'], ) ) ?>", leave: "Html->url( array( 'controller' => 'grouper_groups', - 'action' => 'leaveGroup' + 'action' => 'leaveGroup', + 'co' => $vv_coid, + 'glid' => $vv_config['CoGrouperLiteWidget']['id'], ) ) ?>", remove: "webroot ?>grouper_lite_widget/grouper_groups/removeSubscriber/co:/glid:",