Skip to content

Commit e8db4ea

Browse files
Address code-rabbit comments.
1 parent 795deca commit e8db4ea

File tree

5 files changed

+39
-31
lines changed
  • components/org.wso2.carbon.identity.api.server.organization.user.sharing.management

5 files changed

+39
-31
lines changed

components/org.wso2.carbon.identity.api.server.organization.user.sharing.management/org.wso2.carbon.identity.api.server.organization.user.sharing.management.common/src/main/java/org/wso2/carbon/identity/api/server/organization/user/sharing/management/common/constants/UserSharingMgtConstants.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,13 @@ public enum ErrorMessage {
6666
"Invalid user share patch request body.",
6767
"The user share patch request body is either null or empty. " +
6868
"Please provide a valid user share patch request body."),
69+
ERROR_MISSING_USER_CRITERIA("60006",
70+
"Missing user criteria in the request body.",
71+
"The user criteria is missing in the request body. Please provide the user criteria to proceed."),
72+
ERROR_UNSUPPORTED_USER_SHARE_PATCH_PATH("60007",
73+
"Unsupported user share patch path.",
74+
"The provided patch path to update attributes of shared user is not supported. " +
75+
"Please provide a valid patch path."),
6976

7077
// Server errors.
7178
ERROR_INITIATING_USERS_API_SERVICE("65001",

components/org.wso2.carbon.identity.api.server.organization.user.sharing.management/org.wso2.carbon.identity.api.server.organization.user.sharing.management.v2/src/gen/java/org/wso2/carbon/identity/api/server/organization/user/sharing/management/v2/UsersApi.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public UsersApi() {
6161
@ApiResponse(code = 400, message = "Bad Request", response = Error.class),
6262
@ApiResponse(code = 500, message = "Internal Server Error", response = Error.class)
6363
})
64-
public Response getUserSharedOrganizations(@ApiParam(value = "The ID of the user.",required=true) @PathParam("userId") String userId, @Valid@ApiParam(value = "Base64 encoded cursor value for backward pagination.") @QueryParam("before") String before, @Valid@ApiParam(value = "Base64 encoded cursor value for forward pagination.") @QueryParam("after") String after, @Valid@ApiParam(value = "Condition to filter the retrieval of records. Supports `sw`, `co`, `ew`, and `eq` operations.") @QueryParam("filter") String filter, @Valid@ApiParam(value = "Maximum number of records to return. If you do not specify this parameter, this will return all shared organizations.") @QueryParam("limit") Integer limit, @Valid@ApiParam(value = "Determines whether a recursive search should happen. If set to true, includes shared organizations in all levels of the hierarchy; if set to false, includes only shared organizations in the next level of the hierarchy.") @QueryParam("recursive") Boolean recursive, @Valid@ApiParam(value = "Specifies the required parameters in the response. Supported values: `roles`, `sharingMode`.", allowableValues="sharingMode") @QueryParam("attributes") String attributes) {
64+
public Response getUserSharedOrganizations(@ApiParam(value = "The ID of the user.",required=true) @PathParam("userId") String userId, @Valid@ApiParam(value = "Base64 encoded cursor value for backward pagination.") @QueryParam("before") String before, @Valid@ApiParam(value = "Base64 encoded cursor value for forward pagination.") @QueryParam("after") String after, @Valid@ApiParam(value = "Condition to filter the retrieval of records. Supports `sw`, `co`, `ew`, and `eq` operations.") @QueryParam("filter") String filter, @Valid@ApiParam(value = "Maximum number of records to return. If you do not specify this parameter, this will return all shared organizations.") @QueryParam("limit") Integer limit, @Valid@ApiParam(value = "Determines whether a recursive search should happen. If set to true, includes shared organizations in all levels of the hierarchy; if set to false, includes only shared organizations in the next level of the hierarchy.") @QueryParam("recursive") Boolean recursive, @Valid@ApiParam(value = "Specifies the required parameters in the response. Supported values: `roles`, `sharingMode`.") @QueryParam("attributes") String attributes) {
6565

6666
return delegate.getUserSharedOrganizations(userId, before, after, filter, limit, recursive, attributes );
6767
}

components/org.wso2.carbon.identity.api.server.organization.user.sharing.management/org.wso2.carbon.identity.api.server.organization.user.sharing.management.v2/src/main/java/org/wso2/carbon/identity/api/server/organization/user/sharing/management/v2/core/UsersApiServiceCore.java

Lines changed: 30 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@
7474
import javax.ws.rs.core.UriBuilder;
7575
import javax.ws.rs.core.UriInfo;
7676

77+
import static org.wso2.carbon.identity.api.server.organization.user.sharing.management.common.constants.UserSharingMgtConstants.ErrorMessage.ERROR_MISSING_USER_CRITERIA;
78+
import static org.wso2.carbon.identity.api.server.organization.user.sharing.management.common.constants.UserSharingMgtConstants.ErrorMessage.ERROR_UNSUPPORTED_USER_SHARE_PATCH_PATH;
7779
import static org.wso2.carbon.identity.api.server.organization.user.sharing.management.common.constants.UserSharingMgtConstants.ErrorMessage.INVALID_GENERAL_USER_SHARE_REQUEST_BODY;
7880
import static org.wso2.carbon.identity.api.server.organization.user.sharing.management.common.constants.UserSharingMgtConstants.ErrorMessage.INVALID_GENERAL_USER_UNSHARE_REQUEST_BODY;
7981
import static org.wso2.carbon.identity.api.server.organization.user.sharing.management.common.constants.UserSharingMgtConstants.ErrorMessage.INVALID_SELECTIVE_USER_SHARE_REQUEST_BODY;
@@ -121,10 +123,10 @@ public Response shareUsersWithSelectedOrgs(UserShareSelectedRequestBody userShar
121123
.entity(buildErrorResponse(makeRequestError(INVALID_SELECTIVE_USER_SHARE_REQUEST_BODY))).build();
122124
}
123125

124-
// Populate selectiveUserShareV2DO object from the request body.
125-
SelectiveUserShareV2DO selectiveUserShareV2DO = populateSelectiveUserShareV2DO(userShareSelectedRequestBody);
126-
127126
try {
127+
// Populate selectiveUserShareV2DO object from the request body.
128+
SelectiveUserShareV2DO selectiveUserShareV2DO =
129+
populateSelectiveUserShareV2DO(userShareSelectedRequestBody);
128130
userSharingPolicyHandlerServiceV2.populateSelectiveUserShareV2(selectiveUserShareV2DO);
129131
return Response.status(Response.Status.ACCEPTED)
130132
.entity(getProcessSuccessResponse(RESPONSE_DETAIL_USER_SHARE)).build();
@@ -151,10 +153,9 @@ public Response shareUsersWithAllOrgs(UserShareAllRequestBody userShareAllReques
151153
.entity(buildErrorResponse(makeRequestError(INVALID_GENERAL_USER_SHARE_REQUEST_BODY))).build();
152154
}
153155

154-
// Populate GeneralUserShareDO object from the request body.
155-
GeneralUserShareV2DO generalUserShareV2DO = populateGeneralUserShareV2DO(userShareAllRequestBody);
156-
157156
try {
157+
// Populate GeneralUserShareDO object from the request body.
158+
GeneralUserShareV2DO generalUserShareV2DO = populateGeneralUserShareV2DO(userShareAllRequestBody);
158159
userSharingPolicyHandlerServiceV2.populateGeneralUserShareV2(generalUserShareV2DO);
159160
return Response.status(Response.Status.ACCEPTED)
160161
.entity(getProcessSuccessResponse(RESPONSE_DETAIL_USER_SHARE)).build();
@@ -181,10 +182,10 @@ public Response unshareUsersFromSelectedOrgs(UserUnshareSelectedRequestBody user
181182
.entity(buildErrorResponse(makeRequestError(INVALID_SELECTIVE_USER_UNSHARE_REQUEST_BODY))).build();
182183
}
183184

184-
// Populate SelectiveUserUnshareDO object from the request body.
185-
SelectiveUserUnshareDO selectiveUserUnshareDO = populateSelectiveUserUnshareDO(userUnshareSelectedRequestBody);
186-
187185
try {
186+
// Populate SelectiveUserUnshareDO object from the request body.
187+
SelectiveUserUnshareDO selectiveUserUnshareDO =
188+
populateSelectiveUserUnshareDO(userUnshareSelectedRequestBody);
188189
userSharingPolicyHandlerServiceV2.populateSelectiveUserUnshareV2(selectiveUserUnshareDO);
189190
return Response.status(Response.Status.ACCEPTED)
190191
.entity(getProcessSuccessResponse(RESPONSE_DETAIL_USER_UNSHARE))
@@ -211,10 +212,9 @@ public Response unshareUsersFromAllOrgs(UserUnshareAllRequestBody userUnshareAll
211212
.entity(buildErrorResponse(makeRequestError(INVALID_GENERAL_USER_UNSHARE_REQUEST_BODY))).build();
212213
}
213214

214-
// Populate GeneralUserUnshareDO object from the request body.
215-
GeneralUserUnshareDO generalUserUnshareDO = populateGeneralUserUnshareDO(userUnshareAllRequestBody);
216-
217215
try {
216+
// Populate GeneralUserUnshareDO object from the request body.
217+
GeneralUserUnshareDO generalUserUnshareDO = populateGeneralUserUnshareDO(userUnshareAllRequestBody);
218218
userSharingPolicyHandlerServiceV2.populateGeneralUserUnshareV2(generalUserUnshareDO);
219219
return Response.status(Response.Status.ACCEPTED)
220220
.entity(getProcessSuccessResponse(RESPONSE_DETAIL_USER_UNSHARE))
@@ -242,10 +242,9 @@ public Response patchUserSharing(UserSharingPatchRequest userSharingPatchRequest
242242
.entity(buildErrorResponse(makeRequestError(INVALID_USER_SHARE_PATCH_REQUEST_BODY))).build();
243243
}
244244

245-
// Populate PatchUserShareDO object from the request body.
246-
UserSharePatchDO userSharePatchDO = populateUserSharePatch(userSharingPatchRequest);
247-
248245
try {
246+
// Populate PatchUserShareDO object from the request body.
247+
UserSharePatchDO userSharePatchDO = populateUserSharePatch(userSharingPatchRequest);
249248
userSharingPolicyHandlerServiceV2.updateRoleAssignmentV2(userSharePatchDO);
250249
return Response.status(Response.Status.ACCEPTED)
251250
.entity(getProcessSuccessResponse(RESPONSE_DETAIL_USER_SHARE_PATCH))
@@ -309,7 +308,7 @@ public Response getUserSharedOrganizations(String userId, String before, String
309308
* @return A populated SelectiveUserShareDO object.
310309
*/
311310
private SelectiveUserShareV2DO populateSelectiveUserShareV2DO(
312-
UserShareSelectedRequestBody userShareSelectedRequestBody) {
311+
UserShareSelectedRequestBody userShareSelectedRequestBody) throws UserSharingMgtClientException {
313312

314313
SelectiveUserShareV2DO selectiveUserShareV2DO = new SelectiveUserShareV2DO();
315314

@@ -339,7 +338,8 @@ private SelectiveUserShareV2DO populateSelectiveUserShareV2DO(
339338
* @param userShareAllRequestBody Contains details for sharing users with all organizations.
340339
* @return A populated GeneralUserShareDO object.
341340
*/
342-
private GeneralUserShareV2DO populateGeneralUserShareV2DO(UserShareAllRequestBody userShareAllRequestBody) {
341+
private GeneralUserShareV2DO populateGeneralUserShareV2DO(UserShareAllRequestBody userShareAllRequestBody)
342+
throws UserSharingMgtClientException {
343343

344344
GeneralUserShareV2DO generalUserShareV2DO = new GeneralUserShareV2DO();
345345

@@ -363,7 +363,7 @@ private GeneralUserShareV2DO populateGeneralUserShareV2DO(UserShareAllRequestBod
363363
* @return A populated SelectiveUserUnshareDO object.
364364
*/
365365
private SelectiveUserUnshareDO populateSelectiveUserUnshareDO(
366-
UserUnshareSelectedRequestBody userUnshareSelectedRequestBody) {
366+
UserUnshareSelectedRequestBody userUnshareSelectedRequestBody) throws UserSharingMgtClientException {
367367

368368
SelectiveUserUnshareDO selectiveUserUnshareDO = new SelectiveUserUnshareDO();
369369

@@ -384,7 +384,8 @@ private SelectiveUserUnshareDO populateSelectiveUserUnshareDO(
384384
* @param userUnshareAllRequestBody Contains details for removing shared access.
385385
* @return A populated GeneralUserUnshareDO object.
386386
*/
387-
private GeneralUserUnshareDO populateGeneralUserUnshareDO(UserUnshareAllRequestBody userUnshareAllRequestBody) {
387+
private GeneralUserUnshareDO populateGeneralUserUnshareDO(UserUnshareAllRequestBody userUnshareAllRequestBody)
388+
throws UserSharingMgtClientException {
388389

389390
GeneralUserUnshareDO generalUserUnshareDO = new GeneralUserUnshareDO();
390391

@@ -402,7 +403,8 @@ private GeneralUserUnshareDO populateGeneralUserUnshareDO(UserUnshareAllRequestB
402403
* @param userSharingPatchRequest Contains details for patching user sharing.
403404
* @return A populated PatchUserShareDO object.
404405
*/
405-
private UserSharePatchDO populateUserSharePatch(UserSharingPatchRequest userSharingPatchRequest) {
406+
private UserSharePatchDO populateUserSharePatch(UserSharingPatchRequest userSharingPatchRequest)
407+
throws UserSharingMgtClientException {
406408

407409
UserSharePatchDO userSharePatchDO = new UserSharePatchDO();
408410

@@ -481,7 +483,8 @@ private UriInfo getCurrentRequestUriInfo() {
481483
* @return A map of user criteria keyed by criterion type.
482484
* @throws IllegalArgumentException If no supported user criteria are provided.
483485
*/
484-
private Map<String, UserCriteriaType> buildUserCriteriaFromRequest(UserCriteria userCriteria) {
486+
private Map<String, UserCriteriaType> buildUserCriteriaFromRequest(UserCriteria userCriteria)
487+
throws UserSharingMgtClientException {
485488

486489
Map<String, UserCriteriaType> userCriteriaMap = new HashMap<>();
487490

@@ -491,7 +494,7 @@ private Map<String, UserCriteriaType> buildUserCriteriaFromRequest(UserCriteria
491494
}
492495

493496
if (userCriteriaMap.isEmpty()) {
494-
throw new IllegalArgumentException("At least one user criterion must be provided.");
497+
throw makeRequestError(ERROR_MISSING_USER_CRITERIA);
495498
}
496499

497500
return userCriteriaMap;
@@ -544,7 +547,8 @@ private List<RoleWithAudienceDO> buildRoleWithAudienceDO(List<RoleShareConfig> r
544547
* @param operations List of patch operations from the request.
545548
* @return List of internal {@link PatchOperationDO} instances.
546549
*/
547-
private List<PatchOperationDO> buildPatchOperationsFromRequest(List<UserSharingPatchOperation> operations) {
550+
private List<PatchOperationDO> buildPatchOperationsFromRequest(List<UserSharingPatchOperation> operations)
551+
throws UserSharingMgtClientException {
548552

549553
List<PatchOperationDO> patchOperations = new ArrayList<>();
550554

@@ -567,7 +571,8 @@ private List<PatchOperationDO> buildPatchOperationsFromRequest(List<UserSharingP
567571
* @return Internal values object appropriate for the given path.
568572
* @throws IllegalArgumentException If the path is empty or not supported.
569573
*/
570-
private Object buildPatchOperationValuesFromRequest(String path, List<RoleShareConfig> values) {
574+
private Object buildPatchOperationValuesFromRequest(String path, List<RoleShareConfig> values)
575+
throws UserSharingMgtClientException {
571576

572577
if (path == null || path.isEmpty()) {
573578
throw new IllegalArgumentException("Patch operation 'path' cannot be empty.");
@@ -578,7 +583,7 @@ private Object buildPatchOperationValuesFromRequest(String path, List<RoleShareC
578583
return buildRoleWithAudienceDO(values);
579584
}
580585

581-
throw new IllegalArgumentException("Unsupported patch path: " + path);
586+
throw makeRequestError(ERROR_UNSUPPORTED_USER_SHARE_PATCH_PATH);
582587
}
583588

584589
/**

components/org.wso2.carbon.identity.api.server.organization.user.sharing.management/org.wso2.carbon.identity.api.server.organization.user.sharing.management.v2/src/main/java/org/wso2/carbon/identity/api/server/organization/user/sharing/management/v2/impl/UsersApiServiceImpl.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818

1919
package org.wso2.carbon.identity.api.server.organization.user.sharing.management.v2.impl;
2020

21-
22-
2321
import org.apache.commons.logging.Log;
2422
import org.apache.commons.logging.LogFactory;
2523
import org.wso2.carbon.identity.api.server.organization.user.sharing.management.v2.UsersApiService;

components/org.wso2.carbon.identity.api.server.organization.user.sharing.management/org.wso2.carbon.identity.api.server.organization.user.sharing.management.v2/src/main/resources/organization-user-share-v2.yaml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -384,12 +384,10 @@ paths:
384384
required: false
385385
schema:
386386
type: string
387-
enum:
388-
- sharingMode
387+
example: "roles"
389388
description: |-
390389
Specifies the required parameters in the response.
391390
Supported values: `roles`, `sharingMode`.
392-
example: "roles"
393391
responses:
394392
"200":
395393
description: Successful response with the user's shared organizations.

0 commit comments

Comments
 (0)