Skip to content

Commit

Permalink
refactor getGrouperUserMemberships
Browse files Browse the repository at this point in the history
  • Loading branch information
Ioannis committed Feb 28, 2024
1 parent a6e11e6 commit e3b6617
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 17 deletions.
4 changes: 2 additions & 2 deletions Controller/GrouperGroupsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ public function addSubscriber(): void
throw $e;
}

$this->restResponse(HttpStatusCodesEnum::HTTP_OK);
$this->restResponse(HttpStatusCodesEnum::HTTP_CREATED);
}

/**
Expand Down Expand Up @@ -464,7 +464,7 @@ public function joinGroup(): void
throw $e;
}

$this->restResponse(HttpStatusCodesEnum::HTTP_OK);
$this->restResponse(HttpStatusCodesEnum::HTTP_CREATED);
}

/**
Expand Down
28 changes: 13 additions & 15 deletions Lib/GrouperApiAccess.php
Original file line number Diff line number Diff line change
Expand Up @@ -407,29 +407,28 @@ public function getUserGroupMemberships(string $actorUserId, string $userId): ar
*/
public function getGrouperUserMemberships(string $userId, string $groupType): array
{
if (in_array($groupType, [
if(!in_array($groupType, [
GrouperGroupTypeEnum::OPTINS,
GrouperGroupTypeEnum::OPTOUTS], true)
) {
$subjectId = 'GrouperAll';
} elseif (in_array($groupType, [
GrouperGroupTypeEnum::OPTOUTS,
GrouperGroupTypeEnum::ADMIN,
GrouperGroupTypeEnum::UPDATE,
GrouperGroupTypeEnum::STEM_ADMIN], true)
GrouperGroupTypeEnum::STEM_ADMIN
], true)
) {
$subjectId = $userId;
} else {
CakeLog::write('error', __METHOD__ . ": Option of {$groupType} is not supported");
throw new GrouperLiteWidgetException("Option of {$groupType} is not supported");
throw new BadRequestException("Option of {$groupType} is not supported");
}

$isOptinsOrOptouts = in_array($groupType,
[GrouperGroupTypeEnum::OPTINS, GrouperGroupTypeEnum::OPTOUTS],
true);

//Build request logic
$data = [];
$data['WsRestGetMembershipsRequest']['fieldName'] = $groupType;
$data['WsRestGetMembershipsRequest']['wsSubjectLookups'][0]['subjectId'] = $subjectId;
$data['WsRestGetMembershipsRequest']['wsSubjectLookups'][0]['subjectId'] = $isOptinsOrOptouts ? GrouperConfigEnums::ALL : $userId;

if ($groupType == GrouperGroupTypeEnum::OPTINS
|| $groupType == GrouperGroupTypeEnum::OPTOUTS) {
if ($isOptinsOrOptouts) {
// Build request logic, 2 subjectId's, second is for when user in "Secret" Optin/Optout Group
$data['WsRestGetMembershipsRequest']['wsSubjectLookups'][1]['subjectId'] = $userId;
}
Expand All @@ -455,8 +454,7 @@ public function getGrouperUserMemberships(string $userId, string $groupType): ar
* @param string $groupName
*
* @return array Listing of Members belonging to Grouper Group
* @throws GrouperLiteWidgetException
* @throws JsonException
* @throws GrouperLiteWidgetException|JsonException|NotFoundException
*/
public function getGroupMembers(string $actorUserId, string $groupName): array
{
Expand All @@ -473,7 +471,7 @@ public function getGroupMembers(string $actorUserId, string $groupName): array
]
];

$actionEndpoint = "/groups";
$actionEndpoint = '/groups';

try {
$results = $this->http->sendRequest('POST',
Expand Down
10 changes: 10 additions & 0 deletions Lib/enum.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,19 @@ class GrouperSpecialGroups {
}

class GrouperResultCodesEnum {
const SUCCESS_ALREADY_EXISTED = 'SUCCESS_ALREADY_EXISTED';
const EXECUTE_FAILED = 'EXECUTE_FAILED';
const GROUP_NOT_FOUND = 'GROUP_NOT_FOUND';
const IS_MEMBER = 'IS_MEMBER';
const IS_NOT_MEMBER = 'IS_NOT_MEMBER';
const NO_SUCH_OBJECT = 'NO_SUCH_OBJECT';
const PROBLEM_WITH_ASSIGNMENT = 'PROBLEM_WITH_ASSIGNMENT';
const SUBJECT_NOT_FOUND = 'SUBJECT_NOT_FOUND';
const SUCCESS = 'SUCCESS';
const SUCCESS_INSERTED = 'SUCCESS_INSERTED';
const SUCCESS_NO_CHANGES_NEEDED = 'SUCCESS_NO_CHANGES_NEEDED';
const SUCCESS_NO_INFO = 'SUCCESS_NO_INFO';
const SUCCESS_UPDATED = 'SUCCESS_UPDATED';
}

class GrouperCodesToExceptionClassEnum {
Expand All @@ -45,4 +50,9 @@ class GrouperGroupTypeEnum {
const OPTOUTS = 'optouts';
const STEM_ADMIN = 'stemAdmin';
const UPDATE = 'update';
}

class GrouperConfigEnums {
// https://github.com/Internet2/grouper/blob/GROUPER_4_BRANCH/grouper/src/grouper/edu/internet2/middleware/grouper/cfg/GrouperConfig.java
const ALL = 'GrouperAll';
}

0 comments on commit e3b6617

Please sign in to comment.