From 5a47fc4185c5741b98b83cd0c2f786a2a8dcf7a1 Mon Sep 17 00:00:00 2001 From: Ioannis Igoumenos Date: Mon, 19 Feb 2024 17:27:09 +0000 Subject: [PATCH] Move json content header to constructor --- Controller/GrouperGroupsController.php | 19 ++++++++++++------- Lib/GrouperApiAccess.php | 12 ++---------- Lib/enum.php | 3 +++ 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/Controller/GrouperGroupsController.php b/Controller/GrouperGroupsController.php index 7d7cff8..1967991 100644 --- a/Controller/GrouperGroupsController.php +++ b/Controller/GrouperGroupsController.php @@ -163,7 +163,9 @@ public function groupSubscribers() ]; try { - $subscribers = $this->GrouperGroup->membersInGroup($scope, $this->userId, $this->CoGrouperLiteWidget->getConfig()); + $subscribers = $this->GrouperGroup->membersInGroup($scope, + $this->userId, + $this->CoGrouperLiteWidget->getConfig()); CakeLog::write('debug', __METHOD__ . '::response: ' . var_export($subscribers, true)); } catch (Exception $e) { @@ -204,7 +206,8 @@ public function addSubscriber() { try { $resultAdd = $this->GrouperGroup->addGrouperGroupMember($scope, - $this->userId, $this->CoGrouperLiteWidget->getConfig()); + $this->userId, + $this->CoGrouperLiteWidget->getConfig()); CakeLog::write('debug', __METHOD__ . '::response: ' . var_export($resultAdd, true)); } catch (Exception $e) { CakeLog::write('error', __METHOD__ . ': ' . var_export($e->getMessage(), true)); @@ -350,8 +353,8 @@ public function removeSubscriber() { try { $resultRemove = $this->GrouperGroup->removeGrouperGroupMember($scope, - $this->userId, - $this->CoGrouperLiteWidget->getConfig()); + $this->userId, + $this->CoGrouperLiteWidget->getConfig()); CakeLog::write('debug', __METHOD__ . '::response: ' . var_export($resultRemove, true)); } catch (Exception $e) { @@ -390,7 +393,8 @@ public function groupOwnerApi() { } try { $func = $scope['method']; - $groupowners = $this->GrouperGroup->$func($scope, $this->CoGrouperLiteWidget->getConfig()); + $groupowners = $this->GrouperGroup->$func($scope, + $this->CoGrouperLiteWidget->getConfig()); CakeLog::write('debug', __METHOD__ . "::response: " . var_export($groupowners, true)); } catch (Exception $e) { CakeLog::write('error', __METHOD__ . "::{$errorHint}: " . var_export($e->getMessage(), true)); @@ -534,7 +538,9 @@ public function joinGroup() $display = urldecode($this->request->query['GroupDisplayName']); try { - if (!$this->GrouperGroup->joinGroup($this->userId, $name)) { + if (!$this->GrouperGroup->joinGroup($this->userId, + $name, + $this->CoGrouperLiteWidget->getConfig())) { $this->restResponse(HttpStatusCodesEnum::HTTP_UNAUTHORIZED, ErrorsEnum::NotAdded); $resultAdd = ''; } @@ -593,7 +599,6 @@ function isAuthorized() $cfg = $this->CoGrouperLiteWidget->getConfig(); // Find the identifier $args = array(); - // XXX This should become configuration $args['conditions']['Identifier.type'] = $cfg['CoGrouperLiteWidget']['identifier_type']; $args['conditions']['Identifier.status'] = SuspendableStatusEnum::Active; $args['conditions']['Identifier.co_person_id'] = $roles['copersonid']; diff --git a/Lib/GrouperApiAccess.php b/Lib/GrouperApiAccess.php index e7ad416..2379625 100644 --- a/Lib/GrouperApiAccess.php +++ b/Lib/GrouperApiAccess.php @@ -68,6 +68,8 @@ public function __construct(array $cfg) $this->http->setUser($cfg['CoGrouperLiteWidget']['conn_user']); $this->http->setPassword($cfg['CoGrouperLiteWidget']['conn_pass']); + // Assume json content responses + $this->http->setHeader(['Content-Type' => 'application/json', 'Accept' => 'application/json']); } /** @@ -96,8 +98,6 @@ public function addGrouperGroupMember(array $queryData) ] ]; - $this->http->setHeader(['Content-Type' => 'application/json', 'Accept' => 'application/json']); - try { $results = $this->http->sendRequest('PUT', $connectionUrl, @@ -151,7 +151,6 @@ public function createGroupWithTemplate(array $queryData) ] ]; - $this->http->setHeader(['Content-Type' => 'application/json', 'Accept' => 'application/json']); $connectionUrl = "{$this->config['fullUrl']}/gshTemplateExec"; $status = true; @@ -231,7 +230,6 @@ public function createUpdateGroup(array $queryData) ] ] ]; - $this->http->setHeader(['Content-Type' => 'application/json', 'Accept' => 'application/json']); $connectionUrl = "{$this->config['fullUrl']}/groups"; try { @@ -282,7 +280,6 @@ public function deleteGroupWithTemplate(array $queryData) ] ]; - $this->http->setHeader(['Content-Type' => 'application/json', 'Accept' => 'application/json']); $connectionUrl = "{$this->config['fullUrl']}/gshTemplateExec"; try { @@ -332,7 +329,6 @@ public function getGrouperGroupInfo(array $queryData) ] ] ]; - $this->http->setHeader(['Content-Type' => 'application/json', 'Accept' => 'application/json']); $connectionUrl = "{$this->config['fullUrl']}/attributeAssignments"; try { @@ -409,7 +405,6 @@ public function getMembersInGroup(array $queryData) { ]; $connectionUrl = "{$this->config['fullUrl']}/groups"; - $this->http->setHeader(['Content-Type' => 'application/json', 'Accept' => 'application/json']); try { $results = $this->http->sendRequest('POST', @@ -535,7 +530,6 @@ public function joinGrouperGroup(string $userId, string $groupName) ] ]; - $this->http->setHeader(['Content-Type' => 'application/json', 'Accept' => 'application/json']); $connectionUrl = "{$this->config['fullUrl']}/groups/{$groupName}/members"; try { @@ -578,7 +572,6 @@ public function leaveGrouperGroup(string $userId, string $groupName) ] ]; - $this->http->setHeader(['Content-Type' => 'application/json', 'Accept' => 'application/json']); $connectionUrl = "{$this->config['fullUrl']}/groups/{$groupName}/members"; try { @@ -683,7 +676,6 @@ public function removeGrouperGroupMember(array $queryData) ] ]; - $this->http->setHeader(['Content-Type' => 'application/json', 'Accept' => 'application/json']); try { $results = $this->http->sendRequest('POST', diff --git a/Lib/enum.php b/Lib/enum.php index 5fb9689..f9a2cf7 100644 --- a/Lib/enum.php +++ b/Lib/enum.php @@ -20,4 +20,7 @@ class GrouperResultCodesEnum { const IS_MEMBER = 'IS_MEMBER'; const SUCCESS = 'SUCCESS'; const GROUP_NOT_FOUND = 'GROUP_NOT_FOUND'; + const NO_SUCH_OBJECT = 'NO_SUCH_OBJECT'; + const SUCCESS_NO_INFO = 'SUCCESS_NO_INFO'; + const EXECUTE_FAILED = 'EXECUTE_FAILED'; } \ No newline at end of file