fix(系统设置): 用户组获取待关联用户时没有过滤已经删除的用户

This commit is contained in:
jianxing 2023-08-25 18:02:58 +08:00 committed by 刘瑞斌
parent 8261617a8d
commit 07fe3541de
4 changed files with 29 additions and 6 deletions

View File

@ -33,5 +33,7 @@ public interface BaseUserMapper {
List<ExcludeOptionDTO> getExcludeSelectOption();
List<OptionDTO> getSelectOptionByIds(List<String> ids);
List<OptionDTO> getSelectOptionByIdsWithDeleted(List<String> ids);
List<OptionDTO> getSelectOptionWithDeleted();
}

View File

@ -27,6 +27,7 @@
<select id="findAll" resultType="io.metersphere.system.domain.User">
SELECT *
FROM user
where deleted IS FALSE
</select>
<insert id="batchSave">
@ -95,8 +96,9 @@
<select id="getExcludeSelectOption" resultType="io.metersphere.sdk.dto.ExcludeOptionDTO">
select id, name
from user
where deleted is false
</select>
<select id="getSelectOptionByIds" resultType="io.metersphere.sdk.dto.OptionDTO">
<select id="getSelectOptionByIdsWithDeleted" resultType="io.metersphere.sdk.dto.OptionDTO">
SELECT id, name
FROM user
WHERE id IN
@ -105,4 +107,8 @@
#{id}
</foreach>
</select>
<select id="getSelectOptionWithDeleted" resultType="io.metersphere.sdk.dto.OptionDTO">
select id, name
from user
</select>
</mapper>

View File

@ -429,12 +429,16 @@ public class BaseUserService {
return baseUserMapper.getExcludeSelectOption();
}
public List<OptionDTO> getSelectOptionByIds(List<String> ids) {
return baseUserMapper.getSelectOptionByIds(ids);
public List<OptionDTO> getSelectOptionWithDeleted() {
return baseUserMapper.getSelectOptionWithDeleted();
}
public List<OptionDTO> getSelectOptionByIdsWithDeleted(List<String> ids) {
return baseUserMapper.getSelectOptionByIdsWithDeleted(ids);
}
public Map<String, String> getUserNameMap() {
List<ExcludeOptionDTO> excludeSelectOption = getExcludeSelectOption();
List<OptionDTO> excludeSelectOption = getSelectOptionWithDeleted();
Map<String, String> nameMap = new HashMap<>();
excludeSelectOption.forEach(option -> nameMap.put(option.getId(), option.getName()));
return nameMap;
@ -450,7 +454,7 @@ public class BaseUserService {
if (CollectionUtils.isEmpty(userIds)) {
return Collections.emptyMap();
}
return getSelectOptionByIds(userIds)
return getSelectOptionByIdsWithDeleted(userIds)
.stream()
.collect(Collectors.toMap(OptionDTO::getId, OptionDTO::getName));
}

View File

@ -12,10 +12,12 @@ import io.metersphere.sdk.service.BaseUserService;
import io.metersphere.sdk.util.Pager;
import io.metersphere.system.controller.param.GlobalUserRoleRelationQueryRequestDefinition;
import io.metersphere.system.controller.param.GlobalUserRoleRelationUpdateRequestDefinition;
import io.metersphere.system.domain.UserExample;
import io.metersphere.system.domain.UserRole;
import io.metersphere.system.domain.UserRoleRelation;
import io.metersphere.system.domain.UserRoleRelationExample;
import io.metersphere.system.dto.request.GlobalUserRoleRelationQueryRequest;
import io.metersphere.system.mapper.UserMapper;
import io.metersphere.system.mapper.UserRoleMapper;
import io.metersphere.system.mapper.UserRoleRelationMapper;
import jakarta.annotation.Resource;
@ -51,6 +53,8 @@ class GlobalUserRoleRelationControllerTests extends BaseTest {
@Resource
private UserRoleMapper userRoleMapper;
@Resource
private UserMapper userMapper;
@Resource
private BaseUserService baseUserService;
@Resource
private BaseUserRoleRelationMapper baseUserRoleRelationMapper;
@ -156,6 +160,13 @@ class GlobalUserRoleRelationControllerTests extends BaseTest {
.collect(Collectors.toSet());
// 校验数量
Assertions.assertTrue(options.size() == excludeSelectOption.size());
UserExample example = new UserExample();
example.createCriteria().andIdIn(excludeUserIds.stream().toList())
.andDeletedEqualTo(true);
// 校验获取的用户是不是都是未删除的用户
Assertions.assertTrue(CollectionUtils.isEmpty(userMapper.selectByExample(example)));
options.forEach(item -> {
// 校验 exclude 字段
Assertions.assertTrue(item.getExclude() == excludeUserIds.contains(item.getId()));