diff --git a/Controller/GrouperGroupsController.php b/Controller/GrouperGroupsController.php index 7796d6b..3baeed7 100644 --- a/Controller/GrouperGroupsController.php +++ b/Controller/GrouperGroupsController.php @@ -215,7 +215,7 @@ public function addSubscriber(): void throw $e; } - $this->restResponse(HttpStatusCodesEnum::HTTP_OK); + $this->restResponse(HttpStatusCodesEnum::HTTP_CREATED); } /** @@ -464,7 +464,7 @@ public function joinGroup(): void throw $e; } - $this->restResponse(HttpStatusCodesEnum::HTTP_OK); + $this->restResponse(HttpStatusCodesEnum::HTTP_CREATED); } /** diff --git a/Lib/GrouperApiAccess.php b/Lib/GrouperApiAccess.php index 7c3b7b5..bf5c9e8 100644 --- a/Lib/GrouperApiAccess.php +++ b/Lib/GrouperApiAccess.php @@ -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; } @@ -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 { @@ -473,7 +471,7 @@ public function getGroupMembers(string $actorUserId, string $groupName): array ] ]; - $actionEndpoint = "/groups"; + $actionEndpoint = '/groups'; try { $results = $this->http->sendRequest('POST', diff --git a/Lib/enum.php b/Lib/enum.php index c9799a6..815b144 100644 --- a/Lib/enum.php +++ b/Lib/enum.php @@ -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 { @@ -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'; } \ No newline at end of file