Skip to content

Commit

Permalink
Extract the for loop out of the removeSharedUser and handle it outsid…
Browse files Browse the repository at this point in the history
…e the method
  • Loading branch information
BimsaraBodaragama committed Jan 17, 2025
1 parent b2c2573 commit ff7bb1b
Showing 1 changed file with 20 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,9 @@ public boolean unshareOrganizationUsers(String associatedUserId, String associat
List<UserAssociation> userAssociationList =
organizationUserSharingDAO.getUserAssociationsOfAssociatedUser(associatedUserId, associatedOrgId);
// Removing the shared users from the shared organizations.
removeSharedUsers(userAssociationList);
for (UserAssociation userAssociation : userAssociationList) {
removeSharedUser(userAssociation);
}
return true;
}

Expand All @@ -124,8 +126,8 @@ public boolean unshareOrganizationUserInSharedOrganization(String associatedUser
UserAssociation userAssociation =
organizationUserSharingDAO.getUserAssociationOfAssociatedUserByOrgId(associatedUserId, sharedOrgId);

// Removing the shared users from the shared organization.
removeSharedUsers(Collections.singletonList(userAssociation));
// Removing the shared user from the shared organization.
removeSharedUser(userAssociation);
return true;
}

Expand Down Expand Up @@ -174,23 +176,22 @@ private String generatePassword() {
return uuid.toString().substring(0, 12);
}

private void removeSharedUsers(List<UserAssociation> userAssociationList) throws OrganizationManagementException {
private void removeSharedUser(UserAssociation userAssociation) throws OrganizationManagementException {

for (UserAssociation userAssociation : userAssociationList) {
if (USER_UNSHARING_RESTRICTION.equals(userAssociation.getEditRestriction()) &&
!userAssociation.getUserResidentOrganizationId().equals(getOrganizationId())) {
continue;
}
String organizationId = userAssociation.getOrganizationId();
String tenantDomain = getOrganizationManager().resolveTenantDomain(organizationId);
int tenantId = IdentityTenantUtil.getTenantId(tenantDomain);
try {
AbstractUserStoreManager sharedOrgUserStoreManager = getAbstractUserStoreManager(tenantId);
sharedOrgUserStoreManager.deleteUserWithID(userAssociation.getUserId());
} catch (UserStoreException e) {
throw handleServerException(ERROR_CODE_ERROR_DELETE_SHARED_USER, e,
userAssociation.getUserId(), organizationId);
}
if (USER_UNSHARING_RESTRICTION.equals(userAssociation.getEditRestriction()) &&
!userAssociation.getUserResidentOrganizationId().equals(getOrganizationId())) {
return;
}

String organizationId = userAssociation.getOrganizationId();
String tenantDomain = getOrganizationManager().resolveTenantDomain(organizationId);
int tenantId = IdentityTenantUtil.getTenantId(tenantDomain);
try {
AbstractUserStoreManager sharedOrgUserStoreManager = getAbstractUserStoreManager(tenantId);
sharedOrgUserStoreManager.deleteUserWithID(userAssociation.getUserId());
} catch (UserStoreException e) {
throw handleServerException(ERROR_CODE_ERROR_DELETE_SHARED_USER, e,
userAssociation.getUserId(), organizationId);
}
}
}

0 comments on commit ff7bb1b

Please sign in to comment.