diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/service/OrganizationService.java b/backend/services/system-setting/src/main/java/io/metersphere/system/service/OrganizationService.java index 9117e36272..7f0f3ebfde 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/service/OrganizationService.java +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/service/OrganizationService.java @@ -300,35 +300,19 @@ public class OrganizationService { } public void addMemberToProject(OrgMemberExtendProjectRequest orgMemberExtendProjectRequest, String userId) { + String requestOrganizationId = orgMemberExtendProjectRequest.getOrganizationId(); + checkOrgExist(requestOrganizationId); SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH); UserRoleRelationMapper userRoleRelationMapper = sqlSession.getMapper(UserRoleRelationMapper.class); List logDTOList = new ArrayList<>(); - //检查项目ID是否都是当前组织的项目,不是过滤 List projectIds = orgMemberExtendProjectRequest.getProjectIds(); - ProjectExample projectExample = new ProjectExample(); - projectExample.createCriteria().andIdIn(projectIds); - List projects = projectMapper.selectByExample(projectExample); - Map projectIdOrgIdMap = projects.stream().collect(Collectors.toMap(Project::getId, Project::getOrganizationId)); //用户不在当前组织内过掉 Map userMap = checkUserExist(orgMemberExtendProjectRequest.getMemberIds()); - String requestOrganizationId = orgMemberExtendProjectRequest.getOrganizationId(); orgMemberExtendProjectRequest.getMemberIds().forEach(memberId -> { if (userMap.get(memberId) == null) { return; } - UserRoleRelationExample orgExample = new UserRoleRelationExample(); - orgExample.createCriteria().andSourceIdEqualTo(requestOrganizationId).andUserIdEqualTo(memberId); - List userOrgRoleRelations = userRoleRelationMapper.selectByExample(orgExample); - if (CollectionUtils.isEmpty(userOrgRoleRelations)) { - return; - } projectIds.forEach(projectId -> { - String organizationId = projectIdOrgIdMap.get(projectId); - if (StringUtils.isBlank(organizationId)) { - return; - } else if (!StringUtils.equals(organizationId, requestOrganizationId)) { - return; - } //过滤已存在的关系 UserRoleRelationExample example = new UserRoleRelationExample(); example.createCriteria().andSourceIdEqualTo(projectId).andUserIdEqualTo(memberId).andRoleIdEqualTo(InternalUserRole.PROJECT_MEMBER.getValue()); @@ -438,9 +422,6 @@ public class OrganizationService { UserRoleRelationMapper userRoleRelationMapper = sqlSession.getMapper(UserRoleRelationMapper.class); List logDTOList = new ArrayList<>(); userIds.forEach(userId -> { - if (userMap.get(userId) == null) { - throw new MSException("id:" + userId + Translator.get("user.not.exist")); - } organizationMemberExtendRequest.getUserRoleIds().forEach(userRoleId -> { if (userRoleMap.get(userRoleId) == null) { return; diff --git a/backend/services/system-setting/src/test/java/io/metersphere/system/controller/OrganizationControllerTests.java b/backend/services/system-setting/src/test/java/io/metersphere/system/controller/OrganizationControllerTests.java index 1fcab74f75..feaccf8791 100644 --- a/backend/services/system-setting/src/test/java/io/metersphere/system/controller/OrganizationControllerTests.java +++ b/backend/services/system-setting/src/test/java/io/metersphere/system/controller/OrganizationControllerTests.java @@ -276,6 +276,8 @@ public class OrganizationControllerTests extends BaseTest { addOrUpdateOrganizationProjectMemberError(ORGANIZATION_PROJECT_ADD_MEMBER, "sys_default_organization_3", Arrays.asList("sys_default_user", "sys_default_user2"), Collections.emptyList(), status().isBadRequest()); //成员和项目集合都为空 addOrUpdateOrganizationProjectMemberError(ORGANIZATION_PROJECT_ADD_MEMBER, "sys_default_organization_3", Collections.emptyList(), Collections.emptyList(), status().isBadRequest()); + // 成员选择为空 + addOrUpdateOrganizationProjectMemberError(ORGANIZATION_PROJECT_ADD_MEMBER, "sys_default_organization_X", Collections.emptyList(), Arrays.asList("projectId1", "projectId2"), status().isBadRequest()); } @Test