mirror of
https://gitee.com/fit2cloud-feizhiyun/MeterSphere.git
synced 2024-11-30 11:08:38 +08:00
feat(系统): 系统-组织-项目-添加成员&修改成员用户组
This commit is contained in:
parent
c843051f65
commit
7d48b46e71
@ -132,10 +132,7 @@ public class OrganizationProjectController {
|
||||
@Operation(summary = "系统设置-组织-项目-添加成员")
|
||||
@CheckOwner(resourceId = "#request.getProjectId()", resourceType = "project")
|
||||
public void addProjectMember(@Validated @RequestBody ProjectAddMemberRequest request) {
|
||||
ProjectAddMemberBatchRequest batchRequest = new ProjectAddMemberBatchRequest();
|
||||
batchRequest.setProjectIds(List.of(request.getProjectId()));
|
||||
batchRequest.setUserIds(request.getUserIds());
|
||||
organizationProjectService.addProjectMember(batchRequest, SessionUtils.getUserId());
|
||||
organizationProjectService.orgAddProjectMember(request, SessionUtils.getUserId());
|
||||
}
|
||||
|
||||
@GetMapping("/remove-member/{projectId}/{userId}")
|
||||
@ -185,4 +182,11 @@ public class OrganizationProjectController {
|
||||
organizationProjectService.rename(request, SessionUtils.getUserId());
|
||||
}
|
||||
|
||||
@PostMapping("/user-list")
|
||||
@Operation(summary = "系统设置-组织-项目-分页获取成员列表")
|
||||
@RequiresPermissions(PermissionConstants.SYSTEM_ORGANIZATION_PROJECT_READ)
|
||||
public Pager<List<UserExtendDTO>> getMemberList(@Validated @RequestBody ProjectUserRequest request) {
|
||||
return organizationProjectService.getMemberList(request);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,23 @@
|
||||
package io.metersphere.system.dto.request;
|
||||
|
||||
import io.metersphere.system.dto.sdk.BasePageRequest;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
/**
|
||||
* @author wx
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
public class ProjectUserRequest extends BasePageRequest {
|
||||
|
||||
@Schema(description = "组织ID", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotBlank(message = "{organization.id.not_blank}")
|
||||
private String organizationId;
|
||||
|
||||
@Schema(description = "项目ID", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotBlank(message = "{project_application.project_id.not_blank}")
|
||||
private String projectId;
|
||||
}
|
@ -41,4 +41,5 @@ public interface ExtSystemProjectMapper {
|
||||
|
||||
List<OptionDTO> getSystemProject(@Param("keyword") String keyword);
|
||||
|
||||
List<UserExtendDTO> getUserList(@Param("userIds") List<String> userIds, @Param("projectId") String projectId, @Param("keyword") String keyword);
|
||||
}
|
||||
|
@ -250,4 +250,26 @@
|
||||
order by update_time desc
|
||||
limit 1000
|
||||
</select>
|
||||
|
||||
|
||||
<select id="getUserList" resultType="io.metersphere.system.dto.user.UserExtendDTO">
|
||||
select distinct u.id,
|
||||
u.NAME,
|
||||
u.email, count(temp.id) > 0 as memberFlag from
|
||||
user u left join (select * from user_role_relation urr where urr.source_id = #{projectId}) temp on temp.user_id = u.id
|
||||
<where>
|
||||
u.deleted = 0
|
||||
<if test="userIds != null and userIds.size > 0 ">
|
||||
and u.id in
|
||||
<foreach collection="userIds" item="userId" open="(" separator="," close=")">
|
||||
#{userId}
|
||||
</foreach>
|
||||
</if>
|
||||
<if test="keyword != null and keyword != ''">
|
||||
and (LOCATE(#{keyword},u.name)>0 or LOCATE(#{keyword},u.email)>0)
|
||||
</if>
|
||||
</where>
|
||||
group by u.id
|
||||
order by u.create_time desc
|
||||
</select>
|
||||
</mapper>
|
@ -17,6 +17,7 @@ import io.metersphere.sdk.util.Translator;
|
||||
import io.metersphere.system.domain.*;
|
||||
import io.metersphere.system.dto.*;
|
||||
import io.metersphere.system.dto.request.ProjectAddMemberBatchRequest;
|
||||
import io.metersphere.system.dto.request.ProjectAddMemberRequest;
|
||||
import io.metersphere.system.dto.request.ProjectPoolRequest;
|
||||
import io.metersphere.system.dto.sdk.OptionDTO;
|
||||
import io.metersphere.system.dto.user.UserExtendDTO;
|
||||
@ -712,4 +713,34 @@ public class CommonProjectService {
|
||||
int remainDayCount = DEFAULT_REMAIN_DAY_COUNT - (int) remainDays;
|
||||
return remainDayCount > 0 ? remainDayCount : 1;
|
||||
}
|
||||
|
||||
public void addProjectUser(ProjectAddMemberRequest request, String createUser, String path, String type, String content, String module) {
|
||||
List<LogDTO> logDTOList = new ArrayList<>();
|
||||
List<UserRoleRelation> userRoleRelations = new ArrayList<>();
|
||||
Project project = projectMapper.selectByPrimaryKey(request.getProjectId());
|
||||
Map<String, String> userMap = addUserPre(request.getUserIds(), createUser, path, module, request.getProjectId(), project);
|
||||
request.getUserIds().forEach(userId -> {
|
||||
request.getUserRoleIds().forEach(userRoleId -> {
|
||||
UserRoleRelation userRoleRelation = new UserRoleRelation();
|
||||
userRoleRelation.setId(IDGenerator.nextStr());
|
||||
userRoleRelation.setUserId(userId);
|
||||
userRoleRelation.setSourceId(request.getProjectId());
|
||||
userRoleRelation.setRoleId(userRoleId);
|
||||
userRoleRelation.setCreateTime(System.currentTimeMillis());
|
||||
userRoleRelation.setCreateUser(createUser);
|
||||
userRoleRelation.setOrganizationId(project.getOrganizationId());
|
||||
userRoleRelations.add(userRoleRelation);
|
||||
String logProjectId = OperationLogConstants.SYSTEM;
|
||||
if (StringUtils.equals(module, OperationLogModule.SETTING_ORGANIZATION_PROJECT)) {
|
||||
logProjectId = OperationLogConstants.ORGANIZATION;
|
||||
}
|
||||
LogDTO logDTO = new LogDTO(logProjectId, OperationLogConstants.SYSTEM, userRoleRelation.getId(), createUser, type, module, content + Translator.get("project_member") + ": " + userMap.get(userId));
|
||||
setLog(logDTO, path, HttpMethodConstants.POST.name(), logDTOList);
|
||||
});
|
||||
});
|
||||
if (CollectionUtils.isNotEmpty(userRoleRelations)) {
|
||||
userRoleRelationMapper.batchInsert(userRoleRelations);
|
||||
}
|
||||
operationLogService.batchAdd(logDTOList);
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
package io.metersphere.system.service;
|
||||
|
||||
import com.github.pagehelper.Page;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import io.metersphere.sdk.exception.MSException;
|
||||
import io.metersphere.sdk.util.BeanUtils;
|
||||
import io.metersphere.sdk.util.Translator;
|
||||
@ -12,11 +14,15 @@ import io.metersphere.system.dto.UpdateProjectRequest;
|
||||
import io.metersphere.system.dto.request.*;
|
||||
import io.metersphere.system.dto.sdk.OptionDTO;
|
||||
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.OperationLogType;
|
||||
import io.metersphere.system.mapper.ExtSystemProjectMapper;
|
||||
import io.metersphere.system.mapper.ExtUserRoleRelationMapper;
|
||||
import io.metersphere.system.mapper.OrganizationMapper;
|
||||
import io.metersphere.system.mapper.UserRoleRelationMapper;
|
||||
import io.metersphere.system.utils.PageUtils;
|
||||
import io.metersphere.system.utils.Pager;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
@ -24,6 +30,7 @@ import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
@ -38,7 +45,8 @@ public class OrganizationProjectService {
|
||||
private UserRoleRelationMapper userRoleRelationMapper;
|
||||
@Resource
|
||||
private OrganizationMapper organizationMapper;
|
||||
|
||||
@Resource
|
||||
private ExtUserRoleRelationMapper extUserRoleRelationMapper;
|
||||
|
||||
private final static String PREFIX = "/organization-project";
|
||||
private final static String ADD_PROJECT = PREFIX + "/add";
|
||||
@ -74,7 +82,19 @@ public class OrganizationProjectService {
|
||||
}
|
||||
|
||||
public List<UserExtendDTO> getProjectMember(ProjectMemberRequest request) {
|
||||
return extSystemProjectMapper.getProjectMemberList(request);
|
||||
List<UserExtendDTO> userExtendDTOS = extSystemProjectMapper.getProjectMemberList(request);
|
||||
if (CollectionUtils.isNotEmpty(userExtendDTOS)) {
|
||||
List<String> userIds = userExtendDTOS.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));
|
||||
userExtendDTOS.forEach(user -> {
|
||||
if (roleMap.containsKey(user.getId())) {
|
||||
user.setUserRoleList(roleMap.get(user.getId()));
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
return userExtendDTOS;
|
||||
}
|
||||
|
||||
/***
|
||||
@ -82,8 +102,8 @@ public class OrganizationProjectService {
|
||||
* @param request
|
||||
* @param createUser
|
||||
*/
|
||||
public void addProjectMember(ProjectAddMemberBatchRequest request, String createUser) {
|
||||
commonProjectService.addProjectMember(request, createUser, ADD_MEMBER,
|
||||
public void orgAddProjectMember(ProjectAddMemberRequest request, String createUser) {
|
||||
commonProjectService.addProjectUser(request, createUser, ADD_MEMBER,
|
||||
OperationLogType.ADD.name(), Translator.get("add"), OperationLogModule.SETTING_ORGANIZATION_PROJECT);
|
||||
}
|
||||
|
||||
@ -135,4 +155,20 @@ public class OrganizationProjectService {
|
||||
public void rename(UpdateProjectNameRequest project, String userId) {
|
||||
commonProjectService.rename(project, userId);
|
||||
}
|
||||
|
||||
public Pager<List<UserExtendDTO>> getMemberList(ProjectUserRequest request) {
|
||||
checkOrgIsExist(request.getOrganizationId());
|
||||
commonProjectService.checkProjectNotExist(request.getProjectId());
|
||||
UserRoleRelationExample example = new UserRoleRelationExample();
|
||||
example.createCriteria().andSourceIdEqualTo(request.getOrganizationId());
|
||||
List<UserRoleRelation> userRoleRelations = userRoleRelationMapper.selectByExample(example);
|
||||
List<String> userIds = userRoleRelations.stream().map(UserRoleRelation::getUserId).distinct().collect(Collectors.toList());
|
||||
if (CollectionUtils.isNotEmpty(userIds)) {
|
||||
Page<Object> page = PageHelper.startPage(request.getCurrent(), request.getPageSize());
|
||||
return PageUtils.setPageInfo(page, extSystemProjectMapper.getUserList(userIds, request.getProjectId(), request.getKeyword()));
|
||||
} else {
|
||||
return new Pager<>();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,11 +1,7 @@
|
||||
package io.metersphere.system.service;
|
||||
|
||||
import io.metersphere.project.domain.Project;
|
||||
import io.metersphere.project.mapper.ProjectMapper;
|
||||
import io.metersphere.sdk.constants.HttpMethodConstants;
|
||||
import io.metersphere.sdk.constants.OperationLogConstants;
|
||||
import io.metersphere.sdk.util.Translator;
|
||||
import io.metersphere.system.domain.UserRoleRelation;
|
||||
import io.metersphere.system.dto.*;
|
||||
import io.metersphere.system.dto.request.*;
|
||||
import io.metersphere.system.dto.sdk.OptionDTO;
|
||||
@ -13,19 +9,14 @@ 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.OperationLogType;
|
||||
import io.metersphere.system.log.dto.LogDTO;
|
||||
import io.metersphere.system.log.service.OperationLogService;
|
||||
import io.metersphere.system.mapper.ExtSystemProjectMapper;
|
||||
import io.metersphere.system.mapper.ExtUserRoleRelationMapper;
|
||||
import io.metersphere.system.mapper.UserRoleRelationMapper;
|
||||
import io.metersphere.system.uid.IDGenerator;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
@ -39,12 +30,6 @@ public class SystemProjectService {
|
||||
@Resource
|
||||
private CommonProjectService commonProjectService;
|
||||
@Resource
|
||||
private ProjectMapper projectMapper;
|
||||
@Resource
|
||||
private UserRoleRelationMapper userRoleRelationMapper;
|
||||
@Resource
|
||||
private OperationLogService operationLogService;
|
||||
@Resource
|
||||
private ExtUserRoleRelationMapper extUserRoleRelationMapper;
|
||||
|
||||
private final static String PREFIX = "/system/project";
|
||||
@ -142,28 +127,7 @@ public class SystemProjectService {
|
||||
}
|
||||
|
||||
public void addMemberByProject(ProjectAddMemberRequest request, String createUser) {
|
||||
List<LogDTO> logDTOList = new ArrayList<>();
|
||||
List<UserRoleRelation> userRoleRelations = new ArrayList<>();
|
||||
Project project = projectMapper.selectByPrimaryKey(request.getProjectId());
|
||||
Map<String, String> userMap = commonProjectService.addUserPre(request.getUserIds(), createUser, ADD_MEMBER, OperationLogModule.SETTING_SYSTEM_ORGANIZATION, request.getProjectId(), project);
|
||||
request.getUserIds().forEach(userId -> {
|
||||
request.getUserRoleIds().forEach(userRoleId -> {
|
||||
UserRoleRelation userRoleRelation = new UserRoleRelation();
|
||||
userRoleRelation.setId(IDGenerator.nextStr());
|
||||
userRoleRelation.setUserId(userId);
|
||||
userRoleRelation.setSourceId(request.getProjectId());
|
||||
userRoleRelation.setRoleId(userRoleId);
|
||||
userRoleRelation.setCreateTime(System.currentTimeMillis());
|
||||
userRoleRelation.setCreateUser(createUser);
|
||||
userRoleRelation.setOrganizationId(project.getOrganizationId());
|
||||
userRoleRelations.add(userRoleRelation);
|
||||
LogDTO logDTO = new LogDTO(OperationLogConstants.SYSTEM, OperationLogConstants.SYSTEM, userRoleRelation.getId(), createUser, OperationLogType.ADD.name(), OperationLogModule.SETTING_SYSTEM_ORGANIZATION, Translator.get("add") + Translator.get("project_member") + ": " + userMap.get(userId));
|
||||
commonProjectService.setLog(logDTO, ADD_MEMBER, HttpMethodConstants.POST.name(), logDTOList);
|
||||
});
|
||||
});
|
||||
if (CollectionUtils.isNotEmpty(userRoleRelations)) {
|
||||
userRoleRelationMapper.batchInsert(userRoleRelations);
|
||||
}
|
||||
operationLogService.batchAdd(logDTOList);
|
||||
commonProjectService.addProjectUser(request, createUser, ADD_MEMBER,
|
||||
OperationLogType.ADD.name(), Translator.get("add"), OperationLogModule.SETTING_SYSTEM_ORGANIZATION);
|
||||
}
|
||||
}
|
||||
|
@ -12,10 +12,7 @@ import io.metersphere.system.base.BaseTest;
|
||||
import io.metersphere.system.controller.handler.ResultHolder;
|
||||
import io.metersphere.system.domain.*;
|
||||
import io.metersphere.system.dto.*;
|
||||
import io.metersphere.system.dto.request.OrganizationProjectRequest;
|
||||
import io.metersphere.system.dto.request.ProjectAddMemberRequest;
|
||||
import io.metersphere.system.dto.request.ProjectMemberRequest;
|
||||
import io.metersphere.system.dto.request.ProjectPoolRequest;
|
||||
import io.metersphere.system.dto.request.*;
|
||||
import io.metersphere.system.dto.sdk.request.TemplateCustomFieldRequest;
|
||||
import io.metersphere.system.dto.sdk.request.TemplateUpdateRequest;
|
||||
import io.metersphere.system.dto.user.UserDTO;
|
||||
@ -76,6 +73,7 @@ public class OrganizationProjectControllerTests extends BaseTest {
|
||||
private final static String getMemberList = prefix + "/user-member-list/";
|
||||
private final static String getPoolOptions = prefix + "/pool-options";
|
||||
private final static String updateName = prefix + "/rename";
|
||||
private final static String userList = prefix + "/user-list";
|
||||
private static final ResultMatcher BAD_REQUEST_MATCHER = status().isBadRequest();
|
||||
private static final ResultMatcher ERROR_REQUEST_MATCHER = status().is5xxServerError();
|
||||
|
||||
@ -742,6 +740,7 @@ public class OrganizationProjectControllerTests extends BaseTest {
|
||||
projectAddMemberRequest.setProjectId(projectId);
|
||||
List<String> userIds = List.of("admin1", "admin2");
|
||||
projectAddMemberRequest.setUserIds(userIds);
|
||||
projectAddMemberRequest.setUserRoleIds(List.of(InternalUserRole.PROJECT_ADMIN.getValue(), InternalUserRole.PROJECT_MEMBER.getValue()));
|
||||
this.requestPost(addProjectMember, projectAddMemberRequest, status().isOk());
|
||||
UserRoleRelationExample userRoleRelationExample = new UserRoleRelationExample();
|
||||
userRoleRelationExample.createCriteria().andSourceIdEqualTo(projectId);
|
||||
@ -765,20 +764,24 @@ public class OrganizationProjectControllerTests extends BaseTest {
|
||||
//项目Id为空
|
||||
ProjectAddMemberRequest projectAddMemberRequest = new ProjectAddMemberRequest();
|
||||
projectAddMemberRequest.setProjectId(null);
|
||||
projectAddMemberRequest.setUserRoleIds(List.of(InternalUserRole.PROJECT_ADMIN.getValue(), InternalUserRole.PROJECT_MEMBER.getValue()));
|
||||
this.requestPost(addProjectMember, projectAddMemberRequest, BAD_REQUEST_MATCHER);
|
||||
//用户Id为空
|
||||
projectAddMemberRequest = new ProjectAddMemberRequest();
|
||||
projectAddMemberRequest.setProjectId("projectId");
|
||||
projectAddMemberRequest.setUserRoleIds(List.of(InternalUserRole.PROJECT_ADMIN.getValue(), InternalUserRole.PROJECT_MEMBER.getValue()));
|
||||
this.requestPost(addProjectMember, projectAddMemberRequest, BAD_REQUEST_MATCHER);
|
||||
//用户Id不存在
|
||||
projectAddMemberRequest = new ProjectAddMemberRequest();
|
||||
projectAddMemberRequest.setProjectId("projectId");
|
||||
projectAddMemberRequest.setUserIds(List.of("admin3"));
|
||||
projectAddMemberRequest.setUserRoleIds(List.of(InternalUserRole.PROJECT_ADMIN.getValue(), InternalUserRole.PROJECT_MEMBER.getValue()));
|
||||
this.requestPost(addProjectMember, projectAddMemberRequest, ERROR_REQUEST_MATCHER);
|
||||
//项目id不存在
|
||||
projectAddMemberRequest = new ProjectAddMemberRequest();
|
||||
projectAddMemberRequest.setProjectId("projectId111");
|
||||
projectAddMemberRequest.setUserIds(List.of("admin1"));
|
||||
projectAddMemberRequest.setUserRoleIds(List.of(InternalUserRole.PROJECT_ADMIN.getValue(), InternalUserRole.PROJECT_MEMBER.getValue()));
|
||||
this.requestPost(addProjectMember, projectAddMemberRequest, ERROR_REQUEST_MATCHER);
|
||||
}
|
||||
|
||||
@ -1033,4 +1036,22 @@ public class OrganizationProjectControllerTests extends BaseTest {
|
||||
this.requestPost(updateName, project, ERROR_REQUEST_MATCHER);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(26)
|
||||
public void testUserList() throws Exception {
|
||||
//组织下面有成员 返回不为空
|
||||
ProjectUserRequest request = new ProjectUserRequest();
|
||||
request.setCurrent(1);
|
||||
request.setPageSize(10);
|
||||
request.setOrganizationId(getDefault().getId());
|
||||
request.setProjectId("projectId4");
|
||||
MvcResult mvcResult = responsePost(userList, request);
|
||||
List<UserDTO> userDTOS = parseObjectFromMvcResult(mvcResult, List.class);
|
||||
assert userDTOS != null;
|
||||
Assertions.assertFalse(userDTOS.isEmpty());
|
||||
|
||||
request.setKeyword("a");
|
||||
responsePost(userList, request);
|
||||
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user