feat(系统设置): 添加组织项目成员下拉接口

This commit is contained in:
song-cc-rock 2023-08-07 18:38:56 +08:00 committed by fit2-zhao
parent d41eef401f
commit c620387da1
7 changed files with 58 additions and 2 deletions

View File

@ -14,6 +14,7 @@ import io.metersphere.sdk.util.Pager;
import io.metersphere.sdk.util.SessionUtils; import io.metersphere.sdk.util.SessionUtils;
import io.metersphere.system.domain.User; import io.metersphere.system.domain.User;
import io.metersphere.system.dto.UserBatchCreateDTO; import io.metersphere.system.dto.UserBatchCreateDTO;
import io.metersphere.system.dto.UserExtend;
import io.metersphere.system.dto.UserRoleOption; import io.metersphere.system.dto.UserRoleOption;
import io.metersphere.system.dto.request.UserChangeEnableRequest; import io.metersphere.system.dto.request.UserChangeEnableRequest;
import io.metersphere.system.dto.request.UserEditRequest; import io.metersphere.system.dto.request.UserEditRequest;
@ -25,6 +26,8 @@ import io.metersphere.system.service.UserService;
import io.metersphere.validation.groups.Created; import io.metersphere.validation.groups.Created;
import io.metersphere.validation.groups.Updated; import io.metersphere.validation.groups.Updated;
import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.authz.annotation.Logical; import org.apache.shiro.authz.annotation.Logical;
@ -118,4 +121,12 @@ public class UserController {
userService.resetPassword(userId, SessionUtils.getUserId()); userService.resetPassword(userId, SessionUtils.getUserId());
return true; return true;
} }
@GetMapping("/get-option/{sourceId}")
@Operation(summary = "系统-组织及项目, 获取用户下拉选项")
@RequiresPermissions(value = {PermissionConstants.SYSTEM_USER_READ})
@Parameter(name = "sourceId", description = "组织ID或项目ID", schema = @Schema(requiredMode = Schema.RequiredMode.REQUIRED))
public List<UserExtend> getMemberOption(@PathVariable String sourceId) {
return userService.getMemberOption(sourceId);
}
} }

View File

@ -15,4 +15,9 @@ public class UserExtend extends User {
* 是否管理员(组织, 项目) * 是否管理员(组织, 项目)
*/ */
private boolean adminFlag; private boolean adminFlag;
/**
* 是否成员(组织, 项目)
*/
private boolean memberFlag;
} }

View File

@ -0,0 +1,10 @@
package io.metersphere.system.mapper;
import io.metersphere.system.dto.UserExtend;
import java.util.List;
public interface ExtUserMapper {
List<UserExtend> getMemberOption(String sourceId);
}

View File

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="io.metersphere.system.mapper.ExtUserMapper">
<select id="getMemberOption" resultType="io.metersphere.system.dto.UserExtend">
select distinct u.*, count(urr.id) > 0 as memberFlag
from `user` u left join user_role_relation urr on urr.user_id = u.id and urr.source_id = #{sourceId}
group by u.id
</select>
</mapper>

View File

@ -166,9 +166,9 @@ public class OrganizationService {
if (userMap.get(userId) == null) { if (userMap.get(userId) == null) {
throw new MSException(Translator.get("user.not.exist") + ", id: " + userId); throw new MSException(Translator.get("user.not.exist") + ", id: " + userId);
} }
//组织用户成员关系已存在, 不再重复添加 //组织用户关系已存在, 不再重复添加
UserRoleRelationExample example = new UserRoleRelationExample(); UserRoleRelationExample example = new UserRoleRelationExample();
example.createCriteria().andSourceIdEqualTo(organizationId).andUserIdEqualTo(userId).andRoleIdEqualTo(InternalUserRole.ORG_MEMBER.getValue()); example.createCriteria().andSourceIdEqualTo(organizationId).andUserIdEqualTo(userId);
if (userRoleRelationMapper.countByExample(example) > 0) { if (userRoleRelationMapper.countByExample(example) > 0) {
continue; continue;
} }

View File

@ -17,6 +17,7 @@ import io.metersphere.system.domain.User;
import io.metersphere.system.domain.UserExample; import io.metersphere.system.domain.UserExample;
import io.metersphere.system.dto.UserBatchCreateDTO; import io.metersphere.system.dto.UserBatchCreateDTO;
import io.metersphere.system.dto.UserCreateInfo; import io.metersphere.system.dto.UserCreateInfo;
import io.metersphere.system.dto.UserExtend;
import io.metersphere.system.dto.excel.UserExcel; import io.metersphere.system.dto.excel.UserExcel;
import io.metersphere.system.dto.excel.UserExcelRowDTO; import io.metersphere.system.dto.excel.UserExcelRowDTO;
import io.metersphere.system.dto.request.UserChangeEnableRequest; import io.metersphere.system.dto.request.UserChangeEnableRequest;
@ -24,6 +25,7 @@ import io.metersphere.system.dto.request.UserEditRequest;
import io.metersphere.system.dto.response.UserBatchProcessResponse; import io.metersphere.system.dto.response.UserBatchProcessResponse;
import io.metersphere.system.dto.response.UserImportResponse; import io.metersphere.system.dto.response.UserImportResponse;
import io.metersphere.system.dto.response.UserTableResponse; import io.metersphere.system.dto.response.UserTableResponse;
import io.metersphere.system.mapper.ExtUserMapper;
import io.metersphere.system.mapper.UserMapper; import io.metersphere.system.mapper.UserMapper;
import io.metersphere.system.utils.UserImportEventListener; import io.metersphere.system.utils.UserImportEventListener;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
@ -55,6 +57,8 @@ public class UserService {
@Resource @Resource
private UserMapper userMapper; private UserMapper userMapper;
@Resource @Resource
private ExtUserMapper extUserMapper;
@Resource
private UserRoleRelationService userRoleRelationService; private UserRoleRelationService userRoleRelationService;
@Resource @Resource
private OperationLogService operationLogService; private OperationLogService operationLogService;
@ -378,6 +382,10 @@ public class UserService {
return userMapper.selectByExample(example); return userMapper.selectByExample(example);
} }
public List<UserExtend> getMemberOption(String sourceId) {
return extUserMapper.getMemberOption(sourceId);
}
public void resetPassword(String userId, String operator) { public void resetPassword(String userId, String operator) {
User user = userMapper.selectByPrimaryKey(userId); User user = userMapper.selectByPrimaryKey(userId);
if (user == null) { if (user == null) {

View File

@ -48,6 +48,7 @@ public class SystemOrganizationControllerTests extends BaseTest{
public static final String ORGANIZATION_ADD_MEMBER = "/system/organization/add-member"; public static final String ORGANIZATION_ADD_MEMBER = "/system/organization/add-member";
public static final String ORGANIZATION_REMOVE_MEMBER = "/system/organization/remove-member"; public static final String ORGANIZATION_REMOVE_MEMBER = "/system/organization/remove-member";
public static final String ORGANIZATION_LIST_PROJECT = "/system/organization/list-project"; public static final String ORGANIZATION_LIST_PROJECT = "/system/organization/list-project";
public static final String ORGANIZATION_MEMBER_OPTION = "/system/user/get-option";
@Test @Test
@Order(0) @Order(0)
@ -400,7 +401,19 @@ public class SystemOrganizationControllerTests extends BaseTest{
this.requestPost(ORGANIZATION_DEFAULT, null, status().isMethodNotAllowed()); this.requestPost(ORGANIZATION_DEFAULT, null, status().isMethodNotAllowed());
} }
@Test
@Order(16)
public void testGetOrganizationMemberOption() throws Exception {
MvcResult mvcResult = this.responseGet(SystemOrganizationControllerTests.ORGANIZATION_MEMBER_OPTION + "/default-organization-2");
// 获取返回值
String returnData = mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8);
ResultHolder resultHolder = JSON.parseObject(returnData, ResultHolder.class);
// 返回请求正常
Assertions.assertNotNull(resultHolder);
// 权限校验
requestGetPermissionTest(PermissionConstants.SYSTEM_USER_READ, SystemOrganizationControllerTests.ORGANIZATION_MEMBER_OPTION + "/default-organization-2");
}
private void requestPost(String url, Object param, ResultMatcher resultMatcher) throws Exception { private void requestPost(String url, Object param, ResultMatcher resultMatcher) throws Exception {
mockMvc.perform(MockMvcRequestBuilders.post(url) mockMvc.perform(MockMvcRequestBuilders.post(url)