Skip to content

Commit

Permalink
Refactor get groupSubscribers
Browse files Browse the repository at this point in the history
  • Loading branch information
Ioannis committed Feb 28, 2024
1 parent e3b6617 commit 938e45b
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 25 deletions.
13 changes: 3 additions & 10 deletions Controller/GrouperGroupsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,12 @@ public function groupOwner(): void
* Show all members of a group
* Called from all pages via AJAX call
*
* @throws Exception
*/
public function groupSubscribers(): void
{
$groupName = urldecode($this->request->query['groupname']);
$subscribers = 0;
$subscribers = [];

// //Need to see if coming from AdHoc or from a WG (Working Group)
// $groupNameFormatted = strpos($groupName, ':') === false ? 'ref:incommon-collab:' . $groupName . ':users'
Expand All @@ -165,15 +166,7 @@ public function groupSubscribers(): void
$this->CoGrouperLiteWidget->getConfig());
} catch (Exception $e) {
CakeLog::write('error', __METHOD__ . ': ' . var_export($e->getMessage(), true));

$this->Flash->set(_txt('pl.grouperlite.message.flash.group-detail-members-failed'), array('key' => 'error'));
}

if(count($subscribers) < 1){
$this->restResponse(HttpStatusCodesEnum::HTTP_NOT_FOUND, ErrorsEnum::Error);
} elseif (count($subscribers) == 1
&& $subscribers[0]['sourceId'] === 'NoAccess') {
$this->restResponse(HttpStatusCodesEnum::HTTP_FORBIDDEN, ErrorsEnum::NoAccess);
throw $e;
}

$this->set(compact('subscribers'));
Expand Down
20 changes: 6 additions & 14 deletions Lib/GrouperApiAccess.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function __construct(array $cfg)
|| empty($cfg['CoGrouperLiteWidget']['conn_pass'])
|| empty($cfg['CoGrouperLiteWidget']['conn_ver'])
) {
throw new GrouperLiteWidgetException('No GrouperLite instance captured');
throw new \http\Exception\RuntimeException('No GrouperLite instance captured');
}

$this->http->setServiceUrl($cfg['CoGrouperLiteWidget']['conn_url'], $cfg['CoGrouperLiteWidget']['conn_ver']);
Expand All @@ -78,8 +78,7 @@ public function __construct(array $cfg)
* @param string $addUserId
*
* @return bool Requests success or not
* @throws GrouperLiteWidgetException
* @throws JsonException
* @throws GrouperLiteWidgetException|JsonException
*/
public function addGroupMember(string $actAsUserId,
string $groupName,
Expand Down Expand Up @@ -423,7 +422,7 @@ public function getGrouperUserMemberships(string $userId, string $groupType): ar
[GrouperGroupTypeEnum::OPTINS, GrouperGroupTypeEnum::OPTOUTS],
true);

//Build request logic
// Build request logic
$data = [];
$data['WsRestGetMembershipsRequest']['fieldName'] = $groupType;
$data['WsRestGetMembershipsRequest']['wsSubjectLookups'][0]['subjectId'] = $isOptinsOrOptouts ? GrouperConfigEnums::ALL : $userId;
Expand Down Expand Up @@ -482,16 +481,9 @@ public function getGroupMembers(string $actorUserId, string $groupName): array
throw $e;
}

// Parse out relevant records to send front end
if(isset($results['WsGetMembersResults']['results'][0]['resultMetadata']['resultCode'])
&& $results['WsGetMembersResults']['results'][0]['resultMetadata']['resultCode'] === GrouperResultCodesEnum::GROUP_NOT_FOUND) {
return [
[
'sourceId' => 'NoAccess',
'name' => '',
'id' => ''
]
];
if(isset($results['error']) && $results['error']) {
$cakeExceptionClass = $results['cakeException'];
throw new $cakeExceptionClass($results['message']);
}

return $results['WsGetMembersResults']['results'][0]['wsSubjects'] ?? [];
Expand Down
1 change: 1 addition & 0 deletions Lib/enum.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class GrouperResultCodesEnum {
const IS_NOT_MEMBER = 'IS_NOT_MEMBER';
const NO_SUCH_OBJECT = 'NO_SUCH_OBJECT';
const PROBLEM_WITH_ASSIGNMENT = 'PROBLEM_WITH_ASSIGNMENT';
const PROBLEM_GETTING_MEMBERS = 'PROBLEM_GETTING_MEMBERS';
const SUBJECT_NOT_FOUND = 'SUBJECT_NOT_FOUND';
const SUCCESS = 'SUCCESS';
const SUCCESS_INSERTED = 'SUCCESS_INSERTED';
Expand Down
1 change: 1 addition & 0 deletions View/GrouperGroups/index.ctp
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
addSubscriberSuccess: "<?= _txt('pl.grouperlite.message.flash.add-subscriber-success') ?>",
removeSubscriberError: "<?= _txt('pl.grouperlite.message.flash.remove-subscriber-failed') ?>",
removeSubscriberSuccess: "<?= _txt('pl.grouperlite.message.flash.remove-subscriber-success') ?>",
getSubscriberError: "<?= _txt('pl.grouperlite.message.flash.group-detail-members-failed') ?>",
searchTag: "<?= _txt('pl.grouperlite.search.tags.text') ?>",
peoplePickerPlaceHolder: "<?= _txt('op.grm.add.placeholder') ?>",
noaccess: "<?= _txt('pl.grouperlite.members.noaccess') ?>",
Expand Down
6 changes: 5 additions & 1 deletion webroot/js/members.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,17 @@ export default {
const resp = await fetch(`${this.api.group}?groupname=${encodeURIComponent(name)}`, {
headers: {
"Accept": "application/json",
// 'Content-Type': 'application/x-www-form-urlencoded',
},
method: "GET"
});
if (resp.ok) {
this.subscribers = await resp.json();
} else {
generateFlash(
`${this.txt.getSubscriberError.replace('this', `"${name}"`)}`,
'error');
let errorResponse = await resp.json();
generateFlash(`${errorResponse.message}`, 'error');
this.error = resp;
}
this.loading = false;
Expand Down

0 comments on commit 938e45b

Please sign in to comment.