Merge pull request #751 from sinthuja/master

adding the if condition for only newRoles list iteration.
4.x.x
Megala Uthayakumar 8 years ago committed by GitHub
commit 47bdbc7c14

@ -367,7 +367,6 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
@Override @Override
public void manageGroupSharing(int groupId, List<String> newRoles) public void manageGroupSharing(int groupId, List<String> newRoles)
throws GroupManagementException, RoleDoesNotExistException { throws GroupManagementException, RoleDoesNotExistException {
if (newRoles != null) {
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId(); int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
UserStoreManager userStoreManager; UserStoreManager userStoreManager;
try { try {
@ -376,15 +375,17 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
tenantId).getUserStoreManager(); tenantId).getUserStoreManager();
List<String> currentUserRoles = getRoles(groupId); List<String> currentUserRoles = getRoles(groupId);
GroupManagementDAOFactory.beginTransaction(); GroupManagementDAOFactory.beginTransaction();
for (String role : newRoles) { if (newRoles != null) {
if (!userStoreManager.isExistingRole(role)) { for (String role : newRoles) {
throw new RoleDoesNotExistException("Role '" + role + "' does not exists in the user store."); if (!userStoreManager.isExistingRole(role)) {
} throw new RoleDoesNotExistException("Role '" + role + "' does not exists in the user store.");
// Removing role from current user roles of the group will return true if role exist. }
// So we don't need to add it to the db again. // Removing role from current user roles of the group will return true if role exist.
if (!currentUserRoles.remove(role)) { // So we don't need to add it to the db again.
// If group doesn't have the role, it is adding to the db. if (!currentUserRoles.remove(role)) {
groupDAO.addRole(groupId, role, tenantId); // If group doesn't have the role, it is adding to the db.
groupDAO.addRole(groupId, role, tenantId);
}
} }
} }
for (String role : currentUserRoles) { for (String role : currentUserRoles) {
@ -401,9 +402,6 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
throw new GroupManagementException(e); throw new GroupManagementException(e);
} finally { } finally {
GroupManagementDAOFactory.closeConnection(); GroupManagementDAOFactory.closeConnection();
}
} else {
throw new GroupManagementException("No roles provided to complete the operation.");
} }
} }

Loading…
Cancel
Save