diff --git a/backend/src/main/java/io/metersphere/service/OrganizationService.java b/backend/src/main/java/io/metersphere/service/OrganizationService.java index c82c51fdbb..1a6465e303 100644 --- a/backend/src/main/java/io/metersphere/service/OrganizationService.java +++ b/backend/src/main/java/io/metersphere/service/OrganizationService.java @@ -84,21 +84,20 @@ public class OrganizationService { List roles = memberDTO.getRoleIds(); List allRoleIds = memberRoles.stream().map(Role::getId).collect(Collectors.toList()); // 更新用户时添加了角色 - if (roles.size() > allRoleIds.size()) { - for (int i = 0; i < roles.size(); i++) { - if (checkSourceRole(orgId, userId, roles.get(i)) == 0) { - UserRole userRole = new UserRole(); - userRole.setId(UUID.randomUUID().toString()); - userRole.setUserId(userId); - userRole.setRoleId(roles.get(i)); - userRole.setSourceId(orgId); - userRole.setCreateTime(System.currentTimeMillis()); - userRole.setUpdateTime(System.currentTimeMillis()); - userRoleMapper.insertSelective(userRole); - } + for (int i = 0; i < roles.size(); i++) { + if (checkSourceRole(orgId, userId, roles.get(i)) == 0) { + UserRole userRole = new UserRole(); + userRole.setId(UUID.randomUUID().toString()); + userRole.setUserId(userId); + userRole.setRoleId(roles.get(i)); + userRole.setSourceId(orgId); + userRole.setCreateTime(System.currentTimeMillis()); + userRole.setUpdateTime(System.currentTimeMillis()); + userRoleMapper.insertSelective(userRole); } - } else if (roles.size() < allRoleIds.size()){ - allRoleIds.removeAll(roles); + } + allRoleIds.removeAll(roles); + if (allRoleIds.size() > 0) { UserRoleExample userRoleExample = new UserRoleExample(); userRoleExample.createCriteria().andUserIdEqualTo(userId) .andSourceIdEqualTo(orgId) diff --git a/backend/src/main/java/io/metersphere/service/WorkspaceService.java b/backend/src/main/java/io/metersphere/service/WorkspaceService.java index 5e473018ef..6ea453e7f3 100644 --- a/backend/src/main/java/io/metersphere/service/WorkspaceService.java +++ b/backend/src/main/java/io/metersphere/service/WorkspaceService.java @@ -151,21 +151,20 @@ public class WorkspaceService { List roles = memberDTO.getRoleIds(); List allRoleIds = memberRoles.stream().map(Role::getId).collect(Collectors.toList()); // 更新用户时添加了角色 - if (roles.size() > allRoleIds.size()) { - for (int i = 0; i < roles.size(); i++) { - if (checkSourceRole(workspaceId, userId, roles.get(i)) == 0) { - UserRole userRole = new UserRole(); - userRole.setId(UUID.randomUUID().toString()); - userRole.setUserId(userId); - userRole.setRoleId(roles.get(i)); - userRole.setSourceId(workspaceId); - userRole.setCreateTime(System.currentTimeMillis()); - userRole.setUpdateTime(System.currentTimeMillis()); - userRoleMapper.insertSelective(userRole); - } + for (int i = 0; i < roles.size(); i++) { + if (checkSourceRole(workspaceId, userId, roles.get(i)) == 0) { + UserRole userRole = new UserRole(); + userRole.setId(UUID.randomUUID().toString()); + userRole.setUserId(userId); + userRole.setRoleId(roles.get(i)); + userRole.setSourceId(workspaceId); + userRole.setCreateTime(System.currentTimeMillis()); + userRole.setUpdateTime(System.currentTimeMillis()); + userRoleMapper.insertSelective(userRole); } - } else if (roles.size() < allRoleIds.size()){ - allRoleIds.removeAll(roles); + } + allRoleIds.removeAll(roles); + if (allRoleIds.size() > 0) { UserRoleExample userRoleExample = new UserRoleExample(); userRoleExample.createCriteria().andUserIdEqualTo(userId) .andSourceIdEqualTo(workspaceId)