refactor(系统设置): 用户组查询用户接口支持远程检索
This commit is contained in:
parent
b6567a8318
commit
7e4bbd595d
|
@ -0,0 +1,18 @@
|
|||
package io.metersphere.sdk.dto;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* 加载选项时,标记是否已经关联过,前端需要 exclude 判断禁止重复关联
|
||||
* @author jianxing
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class UserExcludeOptionDTO extends ExcludeOptionDTO {
|
||||
@Schema(description = "邮箱")
|
||||
private String email;
|
||||
}
|
|
@ -1,8 +1,8 @@
|
|||
package io.metersphere.sdk.mapper;
|
||||
|
||||
import io.metersphere.sdk.dto.ExcludeOptionDTO;
|
||||
import io.metersphere.sdk.dto.OptionDTO;
|
||||
import io.metersphere.sdk.dto.UserDTO;
|
||||
import io.metersphere.sdk.dto.UserExcludeOptionDTO;
|
||||
import io.metersphere.system.domain.User;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
|
@ -31,9 +31,7 @@ public interface BaseUserMapper {
|
|||
|
||||
List<OptionDTO> selectUserOptionByIds(List<String> userIds);
|
||||
|
||||
List<ExcludeOptionDTO> getExcludeSelectOption();
|
||||
List<UserExcludeOptionDTO> getExcludeSelectOptionWithLimit(@Param("keyword") String keyword);
|
||||
|
||||
List<OptionDTO> getSelectOptionByIdsWithDeleted(List<String> ids);
|
||||
|
||||
List<OptionDTO> getSelectOptionWithDeleted();
|
||||
}
|
||||
|
|
|
@ -93,10 +93,14 @@
|
|||
#{id}
|
||||
</foreach>
|
||||
</select>
|
||||
<select id="getExcludeSelectOption" resultType="io.metersphere.sdk.dto.ExcludeOptionDTO">
|
||||
select id, name
|
||||
<select id="getExcludeSelectOptionWithLimit" resultType="io.metersphere.sdk.dto.UserExcludeOptionDTO">
|
||||
select id, name, email
|
||||
from user
|
||||
where deleted = 0
|
||||
<if test="keyword != null and keyword != ''">
|
||||
and (name LIKE CONCAT('%', #{keyword}, '%') or email like CONCAT('%', #{keyword}, '%'))
|
||||
</if>
|
||||
limit 100
|
||||
</select>
|
||||
<select id="getSelectOptionByIdsWithDeleted" resultType="io.metersphere.sdk.dto.OptionDTO">
|
||||
SELECT id, name
|
||||
|
@ -107,8 +111,4 @@
|
|||
#{id}
|
||||
</foreach>
|
||||
</select>
|
||||
<select id="getSelectOptionWithDeleted" resultType="io.metersphere.sdk.dto.OptionDTO">
|
||||
select id, name
|
||||
from user
|
||||
</select>
|
||||
</mapper>
|
|
@ -1,6 +1,6 @@
|
|||
package io.metersphere.sdk.service;
|
||||
|
||||
import io.metersphere.sdk.dto.ExcludeOptionDTO;
|
||||
import io.metersphere.sdk.dto.UserExcludeOptionDTO;
|
||||
import io.metersphere.sdk.exception.MSException;
|
||||
import io.metersphere.sdk.mapper.BaseUserRoleRelationMapper;
|
||||
import io.metersphere.system.domain.UserRole;
|
||||
|
@ -122,9 +122,9 @@ public class BaseUserRoleRelationService {
|
|||
* @param roleId
|
||||
* @return
|
||||
*/
|
||||
public List<ExcludeOptionDTO> getExcludeSelectOption(String roleId) {
|
||||
public List<UserExcludeOptionDTO> getExcludeSelectOptionWithLimit(String roleId, String keyword) {
|
||||
// 查询所有用户选项
|
||||
List<ExcludeOptionDTO> selectOptions = baseUserService.getExcludeSelectOption();
|
||||
List<UserExcludeOptionDTO> selectOptions = baseUserService.getExcludeSelectOptionWithLimit(keyword);
|
||||
// 查询已经关联的用户ID
|
||||
Set<String> excludeUserIds = baseUserRoleRelationMapper.getUserIdByRoleId(roleId)
|
||||
.stream()
|
||||
|
|
|
@ -425,12 +425,8 @@ public class BaseUserService {
|
|||
return false;
|
||||
}
|
||||
|
||||
public List<ExcludeOptionDTO> getExcludeSelectOption() {
|
||||
return baseUserMapper.getExcludeSelectOption();
|
||||
}
|
||||
|
||||
public List<OptionDTO> getSelectOptionWithDeleted() {
|
||||
return baseUserMapper.getSelectOptionWithDeleted();
|
||||
public List<UserExcludeOptionDTO> getExcludeSelectOptionWithLimit(String keyword) {
|
||||
return baseUserMapper.getExcludeSelectOptionWithLimit(keyword);
|
||||
}
|
||||
|
||||
public List<OptionDTO> getSelectOptionByIdsWithDeleted(List<String> ids) {
|
||||
|
|
|
@ -3,7 +3,7 @@ package io.metersphere.system.controller;
|
|||
import com.github.pagehelper.Page;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import io.metersphere.sdk.constants.PermissionConstants;
|
||||
import io.metersphere.sdk.dto.ExcludeOptionDTO;
|
||||
import io.metersphere.sdk.dto.UserExcludeOptionDTO;
|
||||
import io.metersphere.sdk.dto.UserRoleRelationUserDTO;
|
||||
import io.metersphere.sdk.dto.request.GlobalUserRoleRelationUpdateRequest;
|
||||
import io.metersphere.sdk.log.annotation.Log;
|
||||
|
@ -16,7 +16,6 @@ import io.metersphere.system.service.GlobalUserRoleRelationLogService;
|
|||
import io.metersphere.system.service.GlobalUserRoleRelationService;
|
||||
import io.metersphere.validation.groups.Created;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.annotation.Resource;
|
||||
|
@ -66,8 +65,10 @@ public class GlobalUserRoleRelationController {
|
|||
@GetMapping("/user/option/{roleId}")
|
||||
@Operation(summary = "系统设置-系统-用户组-用户关联关系-获取需要关联的用户选项")
|
||||
@RequiresPermissions(value = {PermissionConstants.SYSTEM_USER_ROLE_READ})
|
||||
public List<ExcludeOptionDTO> getSelectOption(@Parameter(description = "用户组ID", schema = @Schema(requiredMode = Schema.RequiredMode.REQUIRED))
|
||||
@PathVariable String roleId) {
|
||||
return globalUserRoleRelationService.getExcludeSelectOption(roleId);
|
||||
public List<UserExcludeOptionDTO> getSelectOption(@Schema(description = "用户组ID", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@PathVariable String roleId,
|
||||
@Schema(description = "查询关键字,根据邮箱和用户名查询", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@RequestParam(value = "keyword", required = false) String keyword) {
|
||||
return globalUserRoleRelationService.getExcludeSelectOption(roleId, keyword);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
package io.metersphere.system.service;
|
||||
|
||||
import io.metersphere.sdk.constants.UserRoleScope;
|
||||
import io.metersphere.sdk.dto.ExcludeOptionDTO;
|
||||
import io.metersphere.sdk.dto.TableBatchProcessResponse;
|
||||
import io.metersphere.sdk.dto.UserExcludeOptionDTO;
|
||||
import io.metersphere.sdk.dto.UserRoleRelationUserDTO;
|
||||
import io.metersphere.sdk.dto.request.GlobalUserRoleRelationUpdateRequest;
|
||||
import io.metersphere.sdk.exception.MSException;
|
||||
|
@ -147,8 +147,8 @@ public class GlobalUserRoleRelationService extends BaseUserRoleRelationService {
|
|||
}
|
||||
}
|
||||
|
||||
public List<ExcludeOptionDTO> getExcludeSelectOption(String roleId) {
|
||||
public List<UserExcludeOptionDTO> getExcludeSelectOption(String roleId, String keyword) {
|
||||
baseUserRoleService.getWithCheck(roleId);
|
||||
return super.getExcludeSelectOption(roleId);
|
||||
return super.getExcludeSelectOptionWithLimit(roleId, keyword);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@ package io.metersphere.system.controller;
|
|||
import io.metersphere.sdk.base.BaseTest;
|
||||
import io.metersphere.sdk.constants.PermissionConstants;
|
||||
import io.metersphere.sdk.constants.UserRoleScope;
|
||||
import io.metersphere.sdk.dto.ExcludeOptionDTO;
|
||||
import io.metersphere.sdk.dto.UserExcludeOptionDTO;
|
||||
import io.metersphere.sdk.dto.UserRoleRelationUserDTO;
|
||||
import io.metersphere.sdk.dto.request.GlobalUserRoleRelationUpdateRequest;
|
||||
import io.metersphere.sdk.log.constants.OperationLogType;
|
||||
|
@ -22,6 +22,7 @@ import io.metersphere.system.mapper.UserRoleMapper;
|
|||
import io.metersphere.system.mapper.UserRoleRelationMapper;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.junit.jupiter.api.*;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
@ -155,8 +156,20 @@ class GlobalUserRoleRelationControllerTests extends BaseTest {
|
|||
// @@正常请求
|
||||
MvcResult mvcResult = this.requestGetWithOkAndReturn(USER_OPTION, ADMIN.getValue());
|
||||
// 校验请求数据
|
||||
List<ExcludeOptionDTO> options = getResultDataArray(mvcResult, ExcludeOptionDTO.class);
|
||||
List<ExcludeOptionDTO> excludeSelectOption = baseUserService.getExcludeSelectOption();
|
||||
assertSelectOptionResult(mvcResult, null);
|
||||
|
||||
// 校验检索
|
||||
String keyword = "a";
|
||||
MvcResult searchMvcResult = this.requestGetWithOkAndReturn(USER_OPTION + "?keyword={1}", ADMIN.getValue(), keyword);
|
||||
assertSelectOptionResult(searchMvcResult, keyword);
|
||||
|
||||
// @@校验 NOT_FOUND 异常
|
||||
assertErrorCode(this.requestGet(USER_OPTION, "111"), NOT_FOUND);
|
||||
}
|
||||
|
||||
private void assertSelectOptionResult(MvcResult mvcResult, String keyword) throws Exception {
|
||||
List<UserExcludeOptionDTO> options = getResultDataArray(mvcResult, UserExcludeOptionDTO.class);
|
||||
List<UserExcludeOptionDTO> excludeSelectOption = baseUserService.getExcludeSelectOptionWithLimit(keyword);
|
||||
Set<String> excludeUserIds = baseUserRoleRelationMapper.getUserIdByRoleId(ADMIN.getValue())
|
||||
.stream()
|
||||
.collect(Collectors.toSet());
|
||||
|
@ -174,8 +187,11 @@ class GlobalUserRoleRelationControllerTests extends BaseTest {
|
|||
Assertions.assertTrue(item.getExclude() == excludeUserIds.contains(item.getId()));
|
||||
});
|
||||
|
||||
// @@校验 NOT_FOUND 异常
|
||||
assertErrorCode(this.requestGet(USER_OPTION, "111"), NOT_FOUND);
|
||||
// 校验检索
|
||||
if (StringUtils.isNotBlank(keyword)) {
|
||||
Assertions.assertTrue(options.stream().anyMatch(item -> StringUtils.containsIgnoreCase(item.getName(), keyword)
|
||||
|| StringUtils.containsIgnoreCase(item.getEmail(), keyword)));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
Loading…
Reference in New Issue