Skip to content

Commit

Permalink
Move json content header to constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
Ioannis committed Feb 20, 2024
1 parent 6233090 commit 88ba44e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 17 deletions.
19 changes: 12 additions & 7 deletions Controller/GrouperGroupsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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 = '';
}
Expand Down Expand Up @@ -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'];
Expand Down
12 changes: 2 additions & 10 deletions Lib/GrouperApiAccess.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
}

/**
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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',
Expand Down
3 changes: 3 additions & 0 deletions Lib/enum.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}

0 comments on commit 88ba44e

Please sign in to comment.