feat(系统): 系统-组织与项目-项目成员列表修改成员用户组

This commit is contained in:
WangXu10 2024-09-03 14:35:18 +08:00 committed by Craftsman
parent 68276ef05d
commit 695c26d6d3
5 changed files with 61 additions and 2 deletions

View File

@ -57,7 +57,7 @@ public class ProjectMemberController {
@CheckOwner(resourceId = "#projectId", resourceType = "project") @CheckOwner(resourceId = "#projectId", resourceType = "project")
public List<UserExtendDTO> getMemberOption(@PathVariable String projectId, public List<UserExtendDTO> getMemberOption(@PathVariable String projectId,
@Schema(description = "查询关键字,根据邮箱和用户名查询") @Schema(description = "查询关键字,根据邮箱和用户名查询")
@RequestParam(value = "keyword", required = false) String keyword) { @RequestParam(value = "keyword", required = false) String keyword) {
return projectMemberService.getMemberOption(projectId, keyword); return projectMemberService.getMemberOption(projectId, keyword);
} }
@ -125,4 +125,12 @@ public class ProjectMemberController {
public List<CommentUserInfo> selectCommentUser(@PathVariable String projectId, @RequestParam(value = "keyword", required = false) String keyword) { public List<CommentUserInfo> selectCommentUser(@PathVariable String projectId, @RequestParam(value = "keyword", required = false) String keyword) {
return projectMemberService.selectCommentUser(projectId, keyword); return projectMemberService.selectCommentUser(projectId, keyword);
} }
@PostMapping("/update-member")
@Operation(summary = "系统设置-系统-组织与项-项目-更新成员用户组")
@RequiresPermissions(PermissionConstants.ORGANIZATION_PROJECT_MEMBER_UPDATE)
@CheckOwner(resourceId = "#request.getProjectId()", resourceType = "project")
public void updateProjectMemberRole(@RequestBody ProjectMemberEditRequest request) {
projectMemberService.updateMember(request, SessionUtils.getUserId());
}
} }

View File

@ -43,6 +43,7 @@ public class ProjectMemberControllerTests extends BaseTest {
public static final String ADD_ROLE = "/project/member/add-role"; public static final String ADD_ROLE = "/project/member/add-role";
public static final String BATCH_REMOVE_MEMBER = "/project/member/batch/remove"; public static final String BATCH_REMOVE_MEMBER = "/project/member/batch/remove";
public static final String COMMENT_USER_OPTION = "/project/member/comment/user-option"; public static final String COMMENT_USER_OPTION = "/project/member/comment/user-option";
public static final String UPDATE_MEMBER_ROLE = "/project/member/update-member";
@Test @Test
@Order(1) @Order(1)
@ -301,4 +302,21 @@ public class ProjectMemberControllerTests extends BaseTest {
.andExpect(resultMatcher) .andExpect(resultMatcher)
.andExpect(content().contentType(MediaType.APPLICATION_JSON)); .andExpect(content().contentType(MediaType.APPLICATION_JSON));
} }
@Test
@Order(18)
public void testUpdateMemberRole() throws Exception {
// 不存在的用户组
ProjectMemberEditRequest request = new ProjectMemberEditRequest();
request.setProjectId("default-project-member-test");
request.setUserId("default-project-member-user-1");
request.setRoleIds(List.of("project_admin_x"));
this.requestPost(UPDATE_MEMBER, request, status().isOk());
// 存在的用户组
request.setRoleIds(List.of("project_admin", "project_member"));
this.requestPost(UPDATE_MEMBER, request, status().isOk());
// 权限校验
request.setProjectId(DEFAULT_PROJECT_ID);
requestPostPermissionTest(PermissionConstants.PROJECT_USER_UPDATE, UPDATE_MEMBER, request);
}
} }

View File

@ -18,4 +18,6 @@ public interface ExtUserRoleRelationMapper {
List<UserRoleRelationUserDTO> listGlobal(@Param("request") GlobalUserRoleRelationQueryRequest request); List<UserRoleRelationUserDTO> listGlobal(@Param("request") GlobalUserRoleRelationQueryRequest request);
List<UserRoleOptionDto> selectUserRoleByUserIds(@Param("userIds") List<String> userIds, @Param("orgId") String orgId); List<UserRoleOptionDto> selectUserRoleByUserIds(@Param("userIds") List<String> userIds, @Param("orgId") String orgId);
List<UserRoleOptionDto> selectProjectUserRoleByUserIds(@Param("userIds") List<String> userIds, @Param("projectId") String projectId);
} }

View File

@ -62,4 +62,19 @@
and organization_id = #{orgId} and organization_id = #{orgId}
and source_id = #{orgId} and source_id = #{orgId}
</select> </select>
<select id="selectProjectUserRoleByUserIds" resultType="io.metersphere.system.dto.user.UserRoleOptionDto">
SELECT DISTINCT
user_role_relation.role_id as id,
user_role.`name` as name,
user_role_relation.user_id as userId
FROM
user_role_relation
LEFT JOIN user_role ON user_role_relation.role_id = user_role.id
where user_role_relation.user_id in
<foreach collection="userIds" item="item" open="(" separator="," close=")">
#{item}
</foreach>
and source_id = #{projectId}
</select>
</mapper> </mapper>

View File

@ -10,11 +10,13 @@ import io.metersphere.system.dto.*;
import io.metersphere.system.dto.request.*; import io.metersphere.system.dto.request.*;
import io.metersphere.system.dto.sdk.OptionDTO; import io.metersphere.system.dto.sdk.OptionDTO;
import io.metersphere.system.dto.user.UserExtendDTO; import io.metersphere.system.dto.user.UserExtendDTO;
import io.metersphere.system.dto.user.UserRoleOptionDto;
import io.metersphere.system.log.constants.OperationLogModule; import io.metersphere.system.log.constants.OperationLogModule;
import io.metersphere.system.log.constants.OperationLogType; import io.metersphere.system.log.constants.OperationLogType;
import io.metersphere.system.log.dto.LogDTO; import io.metersphere.system.log.dto.LogDTO;
import io.metersphere.system.log.service.OperationLogService; import io.metersphere.system.log.service.OperationLogService;
import io.metersphere.system.mapper.ExtSystemProjectMapper; import io.metersphere.system.mapper.ExtSystemProjectMapper;
import io.metersphere.system.mapper.ExtUserRoleRelationMapper;
import io.metersphere.system.mapper.UserRoleRelationMapper; import io.metersphere.system.mapper.UserRoleRelationMapper;
import io.metersphere.system.uid.IDGenerator; import io.metersphere.system.uid.IDGenerator;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
@ -26,6 +28,7 @@ import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.stream.Collectors;
@Service @Service
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
@ -41,6 +44,8 @@ public class SystemProjectService {
private UserRoleRelationMapper userRoleRelationMapper; private UserRoleRelationMapper userRoleRelationMapper;
@Resource @Resource
private OperationLogService operationLogService; private OperationLogService operationLogService;
@Resource
private ExtUserRoleRelationMapper extUserRoleRelationMapper;
private final static String PREFIX = "/system/project"; private final static String PREFIX = "/system/project";
private final static String ADD_PROJECT = PREFIX + "/add"; private final static String ADD_PROJECT = PREFIX + "/add";
@ -74,7 +79,18 @@ public class SystemProjectService {
} }
public List<UserExtendDTO> getProjectMember(ProjectMemberRequest request) { public List<UserExtendDTO> getProjectMember(ProjectMemberRequest request) {
return extSystemProjectMapper.getProjectMemberList(request); List<UserExtendDTO> memberList = extSystemProjectMapper.getProjectMemberList(request);
if (CollectionUtils.isNotEmpty(memberList)) {
List<String> userIds = memberList.stream().map(UserExtendDTO::getId).toList();
List<UserRoleOptionDto> userRole = extUserRoleRelationMapper.selectProjectUserRoleByUserIds(userIds, request.getProjectId());
Map<String, List<UserRoleOptionDto>> roleMap = userRole.stream().collect(Collectors.groupingBy(UserRoleOptionDto::getUserId));
memberList.forEach(user -> {
if (roleMap.containsKey(user.getId())) {
user.setUserRoleList(roleMap.get(user.getId()));
}
});
}
return memberList;
} }
/*** /***