fix(系统设置): 创建用户时提示具体的邮箱重复报错信息

--bug=1034909 --user=宋天阳 【系统设置】创建用户-添加多个用户-邮箱已存在提示信息不明确且和字段名称不一致 https://www.tapd.cn/55049933/s/1457326
This commit is contained in:
song-tianyang 2024-01-31 17:14:42 +08:00 committed by 刘瑞斌
parent 1b6fb95123
commit 892ddbf940
20 changed files with 197 additions and 167 deletions

View File

@ -109,7 +109,7 @@ user.email.invite_ms=邀请你加入MeterSphere
user.email.invite_click=点击加入 user.email.invite_click=点击加入
user.email.invite_tips=如果按钮无法点击,请直接访问以下链接: user.email.invite_tips=如果按钮无法点击,请直接访问以下链接:
user.email.invite_limited_time=此链接自发送之时起24小时后过期 user.email.invite_limited_time=此链接自发送之时起24小时后过期
user.email.repeat=用户email已存在 user.email.repeat=邮箱重复
user.reset.password=重置密码 user.reset.password=重置密码
user.delete=删除用户 user.delete=删除用户
user.enable=启用用户 user.enable=启用用户

View File

@ -109,7 +109,7 @@ user.email.invite_ms=invited you join MeterSphere
user.email.invite_click=Join in user.email.invite_click=Join in
user.email.invite_tips=If button can not click,please click url user.email.invite_tips=If button can not click,please click url
user.email.invite_limited_time=Url expires in 24 hours user.email.invite_limited_time=Url expires in 24 hours
user.email.repeat=User email already exists user.email.repeat=Email already exists
user.reset.password=Reset password user.reset.password=Reset password
user.delete=Delete user user.delete=Delete user
user.enable=Enable user user.enable=Enable user

View File

@ -110,7 +110,7 @@ user.email.invite_ms=邀请你加入MeterSphere
user.email.invite_click=点击加入 user.email.invite_click=点击加入
user.email.invite_tips=如果按钮无法点击,请直接访问以下链接: user.email.invite_tips=如果按钮无法点击,请直接访问以下链接:
user.email.invite_limited_time=此链接自发送之时起24小时后过期 user.email.invite_limited_time=此链接自发送之时起24小时后过期
user.email.repeat=用户email已存在 user.email.repeat=邮箱重复
user.reset.password=重置密码 user.reset.password=重置密码
user.delete=删除用户 user.delete=删除用户
user.enable=启用用户 user.enable=启用用户

View File

@ -109,7 +109,7 @@ user.email.invite_ms=邀請你加入MeterSphere
user.email.invite_click=點擊加入 user.email.invite_click=點擊加入
user.email.invite_tips=如果按鈕無法點擊,請直接訪問以下鏈接: user.email.invite_tips=如果按鈕無法點擊,請直接訪問以下鏈接:
user.email.invite_limited_time=此鏈接自發送之時起24小時後過期 user.email.invite_limited_time=此鏈接自發送之時起24小時後過期
user.email.repeat=用戶email已存在 user.email.repeat=郵箱重複
user.reset.password=重置密碼 user.reset.password=重置密碼
user.delete=刪除用戶 user.delete=刪除用戶
user.enable=啟用用戶 user.enable=啟用用戶

View File

@ -7,7 +7,6 @@ import io.metersphere.project.domain.Project;
import io.metersphere.sdk.constants.PermissionConstants; import io.metersphere.sdk.constants.PermissionConstants;
import io.metersphere.sdk.constants.UserSource; import io.metersphere.sdk.constants.UserSource;
import io.metersphere.system.domain.Organization; import io.metersphere.system.domain.Organization;
import io.metersphere.system.dto.UserBatchCreateDTO;
import io.metersphere.system.dto.request.OrganizationMemberBatchRequest; import io.metersphere.system.dto.request.OrganizationMemberBatchRequest;
import io.metersphere.system.dto.request.ProjectAddMemberBatchRequest; import io.metersphere.system.dto.request.ProjectAddMemberBatchRequest;
import io.metersphere.system.dto.request.UserInviteRequest; import io.metersphere.system.dto.request.UserInviteRequest;
@ -15,16 +14,14 @@ import io.metersphere.system.dto.request.UserRegisterRequest;
import io.metersphere.system.dto.request.user.UserChangeEnableRequest; import io.metersphere.system.dto.request.user.UserChangeEnableRequest;
import io.metersphere.system.dto.request.user.UserEditRequest; import io.metersphere.system.dto.request.user.UserEditRequest;
import io.metersphere.system.dto.request.user.UserRoleBatchRelationRequest; import io.metersphere.system.dto.request.user.UserRoleBatchRelationRequest;
import io.metersphere.system.dto.response.UserImportResponse;
import io.metersphere.system.dto.response.UserInviteResponse;
import io.metersphere.system.dto.response.UserSelectOption;
import io.metersphere.system.dto.response.UserTableResponse;
import io.metersphere.system.dto.sdk.BasePageRequest; import io.metersphere.system.dto.sdk.BasePageRequest;
import io.metersphere.system.dto.sdk.BaseTreeNode; import io.metersphere.system.dto.sdk.BaseTreeNode;
import io.metersphere.system.dto.sdk.OptionDTO; import io.metersphere.system.dto.sdk.OptionDTO;
import io.metersphere.system.dto.table.TableBatchProcessDTO; import io.metersphere.system.dto.table.TableBatchProcessDTO;
import io.metersphere.system.dto.table.TableBatchProcessResponse; import io.metersphere.system.dto.table.TableBatchProcessResponse;
import io.metersphere.system.dto.user.UserDTO; import io.metersphere.system.dto.user.UserDTO;
import io.metersphere.system.dto.user.request.UserBatchCreateRequest;
import io.metersphere.system.dto.user.response.*;
import io.metersphere.system.log.annotation.Log; import io.metersphere.system.log.annotation.Log;
import io.metersphere.system.log.constants.OperationLogType; import io.metersphere.system.log.constants.OperationLogType;
import io.metersphere.system.service.*; import io.metersphere.system.service.*;
@ -76,7 +73,7 @@ public class UserController {
@PostMapping("/add") @PostMapping("/add")
@Operation(summary = "系统设置-系统-用户-添加用户") @Operation(summary = "系统设置-系统-用户-添加用户")
@RequiresPermissions(PermissionConstants.SYSTEM_USER_ADD) @RequiresPermissions(PermissionConstants.SYSTEM_USER_ADD)
public UserBatchCreateDTO addUser(@Validated({Created.class}) @RequestBody UserBatchCreateDTO userCreateDTO) { public UserBatchCreateResponse addUser(@Validated({Created.class}) @RequestBody UserBatchCreateRequest userCreateDTO) {
return userService.addUser(userCreateDTO, UserSource.LOCAL.name(), SessionUtils.getUserId()); return userService.addUser(userCreateDTO, UserSource.LOCAL.name(), SessionUtils.getUserId());
} }

View File

@ -1,6 +1,6 @@
package io.metersphere.system.dto.request.user; package io.metersphere.system.dto.request.user;
import io.metersphere.system.dto.UserCreateInfo; import io.metersphere.system.dto.user.UserCreateInfo;
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.media.Schema; import io.swagger.v3.oas.annotations.media.Schema;

View File

@ -1,4 +1,4 @@
package io.metersphere.system.dto; package io.metersphere.system.dto.user;
import io.metersphere.validation.groups.Created; import io.metersphere.validation.groups.Created;
import io.metersphere.validation.groups.Updated; import io.metersphere.validation.groups.Updated;

View File

@ -1,5 +1,6 @@
package io.metersphere.system.dto; package io.metersphere.system.dto.user.request;
import io.metersphere.system.dto.user.UserCreateInfo;
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.media.Schema; import io.swagger.v3.oas.annotations.media.Schema;
@ -11,7 +12,7 @@ import lombok.Data;
import java.util.List; import java.util.List;
@Data @Data
public class UserBatchCreateDTO { public class UserBatchCreateRequest {
@Schema(description = "用户信息集合", requiredMode = Schema.RequiredMode.REQUIRED) @Schema(description = "用户信息集合", requiredMode = Schema.RequiredMode.REQUIRED)
@NotEmpty(groups = {Created.class, Updated.class}, message = "{user.info.not_empty}") @NotEmpty(groups = {Created.class, Updated.class}, message = "{user.info.not_empty}")

View File

@ -0,0 +1,16 @@
package io.metersphere.system.dto.user.response;
import io.metersphere.system.dto.user.UserCreateInfo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.util.List;
import java.util.Map;
@Data
public class UserBatchCreateResponse {
@Schema(description = "成功创建的数据")
List<UserCreateInfo> successList;
@Schema(description = "邮箱异常数据")
Map<String, String> errorEmails;
}

View File

@ -1,7 +1,7 @@
package io.metersphere.system.dto.response; package io.metersphere.system.dto.user.response;
import io.metersphere.system.dto.sdk.ExcelParseDTO;
import io.metersphere.system.dto.excel.UserExcelRowDTO; import io.metersphere.system.dto.excel.UserExcelRowDTO;
import io.metersphere.system.dto.sdk.ExcelParseDTO;
import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
@ -22,9 +22,7 @@ public class UserImportResponse {
public void generateResponse(ExcelParseDTO<UserExcelRowDTO> excelParseDTO) { public void generateResponse(ExcelParseDTO<UserExcelRowDTO> excelParseDTO) {
successCount = excelParseDTO.getDataList().size(); successCount = excelParseDTO.getDataList().size();
if (MapUtils.isNotEmpty(excelParseDTO.getErrRowData())) { if (MapUtils.isNotEmpty(excelParseDTO.getErrRowData())) {
excelParseDTO.getErrRowData().forEach((k, v) -> { excelParseDTO.getErrRowData().forEach((k, v) -> errorMessages.put(k, v.getErrorMessage()));
errorMessages.put(k, v.getErrorMessage());
});
} }
importCount = errorMessages.size() + successCount; importCount = errorMessages.size() + successCount;
} }

View File

@ -1,4 +1,4 @@
package io.metersphere.system.dto.response; package io.metersphere.system.dto.user.response;
import io.metersphere.system.domain.UserInvite; import io.metersphere.system.domain.UserInvite;
import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.media.Schema;
@ -14,6 +14,6 @@ public class UserInviteResponse {
private List<String> inviteIds; private List<String> inviteIds;
public UserInviteResponse(List<UserInvite> userInvites) { public UserInviteResponse(List<UserInvite> userInvites) {
this.inviteIds = userInvites.stream().map(UserInvite::getId).collect(java.util.stream.Collectors.toList()); this.inviteIds = userInvites.stream().map(UserInvite::getId).toList();
} }
} }

View File

@ -1,4 +1,4 @@
package io.metersphere.system.dto.response; package io.metersphere.system.dto.user.response;
import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data; import lombok.Data;

View File

@ -1,4 +1,4 @@
package io.metersphere.system.dto.response; package io.metersphere.system.dto.user.response;
import io.metersphere.system.domain.Organization; import io.metersphere.system.domain.Organization;
import io.metersphere.system.domain.User; import io.metersphere.system.domain.User;

View File

@ -7,6 +7,7 @@ import io.metersphere.system.dto.user.UserDTO;
import io.metersphere.system.dto.user.UserExcludeOptionDTO; import io.metersphere.system.dto.user.UserExcludeOptionDTO;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
import java.util.Collection;
import java.util.List; import java.util.List;
public interface BaseUserMapper { public interface BaseUserMapper {
@ -24,7 +25,7 @@ public interface BaseUserMapper {
String selectEmailInDB(@Param("email") String email, @Param("id") String id); String selectEmailInDB(@Param("email") String email, @Param("id") String id);
List<User> selectUserIdByEmailList(@Param("emailList") List<String> emailList); List<User> selectUserIdByEmailList(@Param("emailList") Collection<String> emailList);
List<User> selectByKeyword(@Param("keyword") String keyword, @Param("selectId") boolean selectId); List<User> selectByKeyword(@Param("keyword") String keyword, @Param("selectId") boolean selectId);

View File

@ -2,15 +2,15 @@ package io.metersphere.system.service;
import io.metersphere.sdk.constants.UserRoleScope; import io.metersphere.sdk.constants.UserRoleScope;
import io.metersphere.sdk.constants.UserRoleType; import io.metersphere.sdk.constants.UserRoleType;
import io.metersphere.system.dto.permission.PermissionDefinitionItem;
import io.metersphere.system.dto.sdk.request.PermissionSettingUpdateRequest;
import io.metersphere.sdk.exception.MSException; import io.metersphere.sdk.exception.MSException;
import io.metersphere.sdk.util.Translator; import io.metersphere.sdk.util.Translator;
import io.metersphere.system.domain.UserRole; import io.metersphere.system.domain.UserRole;
import io.metersphere.system.domain.UserRoleExample; import io.metersphere.system.domain.UserRoleExample;
import io.metersphere.system.dto.permission.PermissionDefinitionItem;
import io.metersphere.system.dto.sdk.request.PermissionSettingUpdateRequest;
import io.metersphere.system.dto.user.response.UserSelectOption;
import io.metersphere.system.mapper.ExtUserRoleMapper; import io.metersphere.system.mapper.ExtUserRoleMapper;
import io.metersphere.system.mapper.UserRoleMapper; import io.metersphere.system.mapper.UserRoleMapper;
import io.metersphere.system.dto.response.UserSelectOption;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
import jakarta.validation.Valid; import jakarta.validation.Valid;
import jakarta.validation.constraints.NotEmpty; import jakarta.validation.constraints.NotEmpty;

View File

@ -7,7 +7,7 @@ import io.metersphere.sdk.constants.UserRoleEnum;
import io.metersphere.sdk.constants.UserRoleScope; import io.metersphere.sdk.constants.UserRoleScope;
import io.metersphere.sdk.util.JSON; import io.metersphere.sdk.util.JSON;
import io.metersphere.system.domain.*; import io.metersphere.system.domain.*;
import io.metersphere.system.dto.response.UserTableResponse; import io.metersphere.system.dto.user.response.UserTableResponse;
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;
@ -67,7 +67,7 @@ public class UserRoleRelationService {
log.setOrganizationId(OperationLogConstants.SYSTEM); log.setOrganizationId(OperationLogConstants.SYSTEM);
log.setType(operationType); log.setType(operationType);
log.setCreateUser(operator); log.setCreateUser(operator);
log.setModule(OperationLogModule.SYSTEM_USER); log.setModule(OperationLogModule.SETTING_SYSTEM_USER_SINGLE);
log.setMethod(operationMethod); log.setMethod(operationMethod);
log.setCreateTime(operationTime); log.setCreateTime(operationTime);
log.setSourceId(user.getId()); log.setSourceId(user.getId());

View File

@ -6,8 +6,6 @@ import io.metersphere.sdk.constants.UserSource;
import io.metersphere.sdk.exception.MSException; import io.metersphere.sdk.exception.MSException;
import io.metersphere.sdk.util.*; import io.metersphere.sdk.util.*;
import io.metersphere.system.domain.*; import io.metersphere.system.domain.*;
import io.metersphere.system.dto.UserBatchCreateDTO;
import io.metersphere.system.dto.UserCreateInfo;
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.UserInviteRequest; import io.metersphere.system.dto.request.UserInviteRequest;
@ -16,17 +14,20 @@ import io.metersphere.system.dto.request.user.PersonalUpdatePasswordRequest;
import io.metersphere.system.dto.request.user.PersonalUpdateRequest; import io.metersphere.system.dto.request.user.PersonalUpdateRequest;
import io.metersphere.system.dto.request.user.UserChangeEnableRequest; import io.metersphere.system.dto.request.user.UserChangeEnableRequest;
import io.metersphere.system.dto.request.user.UserEditRequest; import io.metersphere.system.dto.request.user.UserEditRequest;
import io.metersphere.system.dto.response.UserImportResponse;
import io.metersphere.system.dto.response.UserInviteResponse;
import io.metersphere.system.dto.response.UserTableResponse;
import io.metersphere.system.dto.sdk.BasePageRequest; import io.metersphere.system.dto.sdk.BasePageRequest;
import io.metersphere.system.dto.sdk.ExcelParseDTO; import io.metersphere.system.dto.sdk.ExcelParseDTO;
import io.metersphere.system.dto.sdk.SessionUser; import io.metersphere.system.dto.sdk.SessionUser;
import io.metersphere.system.dto.table.TableBatchProcessDTO; import io.metersphere.system.dto.table.TableBatchProcessDTO;
import io.metersphere.system.dto.table.TableBatchProcessResponse; import io.metersphere.system.dto.table.TableBatchProcessResponse;
import io.metersphere.system.dto.user.PersonalDTO; import io.metersphere.system.dto.user.PersonalDTO;
import io.metersphere.system.dto.user.UserCreateInfo;
import io.metersphere.system.dto.user.UserDTO; import io.metersphere.system.dto.user.UserDTO;
import io.metersphere.system.dto.user.UserExtendDTO; import io.metersphere.system.dto.user.UserExtendDTO;
import io.metersphere.system.dto.user.request.UserBatchCreateRequest;
import io.metersphere.system.dto.user.response.UserBatchCreateResponse;
import io.metersphere.system.dto.user.response.UserImportResponse;
import io.metersphere.system.dto.user.response.UserInviteResponse;
import io.metersphere.system.dto.user.response.UserTableResponse;
import io.metersphere.system.log.service.OperationLogService; import io.metersphere.system.log.service.OperationLogService;
import io.metersphere.system.mapper.*; import io.metersphere.system.mapper.*;
import io.metersphere.system.notice.sender.impl.MailNoticeSender; import io.metersphere.system.notice.sender.impl.MailNoticeSender;
@ -41,6 +42,7 @@ import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotEmpty; import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull; import jakarta.validation.constraints.NotNull;
import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.MapUtils;
import org.apache.commons.lang3.BooleanUtils; import org.apache.commons.lang3.BooleanUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.ibatis.session.ExecutorType; import org.apache.ibatis.session.ExecutorType;
@ -55,10 +57,7 @@ import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.unit.DataSize; import org.springframework.util.unit.DataSize;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import java.util.ArrayList; import java.util.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@Service @Service
@ -92,38 +91,46 @@ public class UserService {
@Value("50MB") @Value("50MB")
private DataSize maxImportFileSize; private DataSize maxImportFileSize;
private void validateUserInfo(List<String> createEmails) { private Map<String, String> validateUserInfo(Collection<String> createEmails) {
Map<String, String> errorMessage = new HashMap<>();
String userEmailRepeatError = Translator.get("user.email.repeat");
//判断参数内是否含有重复邮箱 //判断参数内是否含有重复邮箱
List<String> emailList = new ArrayList<>(); List<String> emailList = new ArrayList<>();
List<String> repeatEmailList = new ArrayList<>();
var userInDbMap = baseUserMapper.selectUserIdByEmailList(createEmails) var userInDbMap = baseUserMapper.selectUserIdByEmailList(createEmails)
.stream().collect(Collectors.toMap(User::getEmail, User::getId)); .stream().collect(Collectors.toMap(User::getEmail, User::getId));
for (String createEmail : createEmails) { for (String createEmail : createEmails) {
if (emailList.contains(createEmail)) { if (emailList.contains(createEmail)) {
repeatEmailList.add(createEmail); errorMessage.put(createEmail, userEmailRepeatError);
} else { } else {
//判断邮箱是否已存在数据库中 //判断邮箱是否已存在数据库中
if (userInDbMap.containsKey(createEmail)) { if (userInDbMap.containsKey(createEmail)) {
repeatEmailList.add(createEmail); errorMessage.put(createEmail, userEmailRepeatError);
} else { } else {
emailList.add(createEmail); emailList.add(createEmail);
} }
} }
} }
if (CollectionUtils.isNotEmpty(repeatEmailList)) { return errorMessage;
throw new MSException(Translator.get("user.email.repeat", repeatEmailList.toString()));
}
} }
public UserBatchCreateDTO addUser(UserBatchCreateDTO userCreateDTO, String source, String operator) { public UserBatchCreateResponse addUser(UserBatchCreateRequest userCreateDTO, String source, String operator) {
//检查用户邮箱的合法性
this.validateUserInfo(userCreateDTO.getUserInfoList().stream().map(UserCreateInfo::getEmail).collect(Collectors.toList()));
//检查用户权限的合法性 //检查用户权限的合法性
globalUserRoleService.checkRoleIsGlobalAndHaveMember(userCreateDTO.getUserRoleIdList(), true); globalUserRoleService.checkRoleIsGlobalAndHaveMember(userCreateDTO.getUserRoleIdList(), true);
return this.saveUserAndRole(userCreateDTO, source, operator, "/system/user/addUser");
UserBatchCreateResponse response = new UserBatchCreateResponse();
//检查用户邮箱的合法性
Map<String, String> errorEmails = this.validateUserInfo(userCreateDTO.getUserInfoList().stream().map(UserCreateInfo::getEmail).toList());
if (MapUtils.isNotEmpty(errorEmails)) {
response.setErrorEmails(errorEmails);
} else {
response.setSuccessList(this.saveUserAndRole(userCreateDTO, source, operator, "/system/user/addUser"));
}
return response;
} }
private UserBatchCreateDTO saveUserAndRole(UserBatchCreateDTO userCreateDTO, String source, String operator, String requestPath) { private List<UserCreateInfo> saveUserAndRole(UserBatchCreateRequest userCreateDTO, String source, String operator, String requestPath) {
List<UserCreateInfo> insertList = new ArrayList<>();
long createTime = System.currentTimeMillis(); long createTime = System.currentTimeMillis();
List<User> saveUserList = new ArrayList<>(); List<User> saveUserList = new ArrayList<>();
//添加用户 //添加用户
@ -140,11 +147,12 @@ public class UserService {
user.setDeleted(false); user.setDeleted(false);
userMapper.insertSelective(user); userMapper.insertSelective(user);
saveUserList.add(user); saveUserList.add(user);
insertList.add(userInfo);
} }
userRoleRelationService.batchSave(userCreateDTO.getUserRoleIdList(), saveUserList); userRoleRelationService.batchSave(userCreateDTO.getUserRoleIdList(), saveUserList);
//写入操作日志 //写入操作日志
operationLogService.batchAdd(userLogService.getBatchAddLogs(saveUserList, requestPath)); operationLogService.batchAdd(userLogService.getBatchAddLogs(saveUserList, requestPath));
return userCreateDTO; return insertList;
} }
public UserDTO getUserDTOByKeyword(String email) { public UserDTO getUserDTOByKeyword(String email) {
@ -309,7 +317,7 @@ public class UserService {
} }
private void saveUserByExcelData(@Valid @NotEmpty List<UserExcelRowDTO> dataList, @Valid @NotEmpty String source, @Valid @NotBlank String sessionId) { private void saveUserByExcelData(@Valid @NotEmpty List<UserExcelRowDTO> dataList, @Valid @NotEmpty String source, @Valid @NotBlank String sessionId) {
UserBatchCreateDTO userBatchCreateDTO = new UserBatchCreateDTO(); UserBatchCreateRequest userBatchCreateDTO = new UserBatchCreateRequest();
userBatchCreateDTO.setUserRoleIdList(new ArrayList<>() {{ userBatchCreateDTO.setUserRoleIdList(new ArrayList<>() {{
add("member"); add("member");
}}); }});
@ -449,10 +457,12 @@ public class UserService {
private SystemParameterMapper systemParameterMapper; private SystemParameterMapper systemParameterMapper;
public UserInviteResponse saveInviteRecord(UserInviteRequest request, SessionUser inviteUser) { public UserInviteResponse saveInviteRecord(UserInviteRequest request, SessionUser inviteUser) {
//校验邮箱和角色的合法性
this.validateUserInfo(request.getInviteEmails());
globalUserRoleService.checkRoleIsGlobalAndHaveMember(request.getUserRoleIds(), true); globalUserRoleService.checkRoleIsGlobalAndHaveMember(request.getUserRoleIds(), true);
//校验邮箱和角色的合法性
Map<String, String> errorMap = this.validateUserInfo(request.getInviteEmails());
if (MapUtils.isNotEmpty(errorMap)) {
throw new MSException(Translator.get("user.email.repeat"));
}
List<UserInvite> inviteList = userInviteService.batchInsert(request.getInviteEmails(), inviteUser.getId(), request.getUserRoleIds()); List<UserInvite> inviteList = userInviteService.batchInsert(request.getInviteEmails(), inviteUser.getId(), request.getUserRoleIds());
//记录日志 //记录日志
userLogService.addEmailInviteLog(inviteList, inviteUser.getId()); userLogService.addEmailInviteLog(inviteList, inviteUser.getId());
@ -481,7 +491,7 @@ public class UserService {
try { try {
this.sendInviteEmailTemporary(emailMap); this.sendInviteEmailTemporary(emailMap);
} catch (Exception e) { } catch (Exception e) {
LogUtils.error("邮箱邀请失败!", e); throw new MSException("邮箱邀请失败!", e);
} }
}); });
} }

View File

@ -2,12 +2,12 @@ package io.metersphere.system.controller.user;
import io.metersphere.sdk.constants.PermissionConstants; import io.metersphere.sdk.constants.PermissionConstants;
import io.metersphere.system.base.BaseTest; import io.metersphere.system.base.BaseTest;
import io.metersphere.system.dto.UserCreateInfo;
import io.metersphere.system.dto.request.UserInviteRequest; import io.metersphere.system.dto.request.UserInviteRequest;
import io.metersphere.system.dto.request.user.UserChangeEnableRequest; import io.metersphere.system.dto.request.user.UserChangeEnableRequest;
import io.metersphere.system.dto.request.user.UserRoleBatchRelationRequest; import io.metersphere.system.dto.request.user.UserRoleBatchRelationRequest;
import io.metersphere.system.dto.response.UserSelectOption;
import io.metersphere.system.dto.table.TableBatchProcessDTO; import io.metersphere.system.dto.table.TableBatchProcessDTO;
import io.metersphere.system.dto.user.UserCreateInfo;
import io.metersphere.system.dto.user.response.UserSelectOption;
import io.metersphere.system.utils.user.UserParamUtils; import io.metersphere.system.utils.user.UserParamUtils;
import io.metersphere.system.utils.user.UserRequestUtils; import io.metersphere.system.utils.user.UserRequestUtils;
import org.junit.jupiter.api.MethodOrderer; import org.junit.jupiter.api.MethodOrderer;

View File

@ -14,29 +14,27 @@ import io.metersphere.system.domain.User;
import io.metersphere.system.domain.UserExample; import io.metersphere.system.domain.UserExample;
import io.metersphere.system.domain.UserInvite; import io.metersphere.system.domain.UserInvite;
import io.metersphere.system.domain.UserRoleRelationExample; import io.metersphere.system.domain.UserRoleRelationExample;
import io.metersphere.system.dto.UserBatchCreateDTO;
import io.metersphere.system.dto.UserCreateInfo;
import io.metersphere.system.dto.excel.UserExcelRowDTO; import io.metersphere.system.dto.excel.UserExcelRowDTO;
import io.metersphere.system.dto.request.UserInviteRequest; import io.metersphere.system.dto.request.UserInviteRequest;
import io.metersphere.system.dto.request.UserRegisterRequest; import io.metersphere.system.dto.request.UserRegisterRequest;
import io.metersphere.system.dto.request.user.UserChangeEnableRequest; import io.metersphere.system.dto.request.user.UserChangeEnableRequest;
import io.metersphere.system.dto.request.user.UserEditRequest; import io.metersphere.system.dto.request.user.UserEditRequest;
import io.metersphere.system.dto.request.user.UserRoleBatchRelationRequest; import io.metersphere.system.dto.request.user.UserRoleBatchRelationRequest;
import io.metersphere.system.dto.response.UserImportResponse;
import io.metersphere.system.dto.response.UserInviteResponse;
import io.metersphere.system.dto.response.UserSelectOption;
import io.metersphere.system.dto.response.UserTableResponse;
import io.metersphere.system.dto.sdk.BasePageRequest; import io.metersphere.system.dto.sdk.BasePageRequest;
import io.metersphere.system.dto.sdk.BaseTreeNode; import io.metersphere.system.dto.sdk.BaseTreeNode;
import io.metersphere.system.dto.sdk.ExcelParseDTO; import io.metersphere.system.dto.sdk.ExcelParseDTO;
import io.metersphere.system.dto.table.TableBatchProcessDTO; import io.metersphere.system.dto.table.TableBatchProcessDTO;
import io.metersphere.system.dto.table.TableBatchProcessResponse; import io.metersphere.system.dto.table.TableBatchProcessResponse;
import io.metersphere.system.dto.user.UserCreateInfo;
import io.metersphere.system.dto.user.UserDTO; import io.metersphere.system.dto.user.UserDTO;
import io.metersphere.system.dto.user.request.UserBatchCreateRequest;
import io.metersphere.system.dto.user.response.*;
import io.metersphere.system.log.constants.OperationLogType; import io.metersphere.system.log.constants.OperationLogType;
import io.metersphere.system.mapper.UserInviteMapper; import io.metersphere.system.mapper.UserInviteMapper;
import io.metersphere.system.mapper.UserMapper; import io.metersphere.system.mapper.UserMapper;
import io.metersphere.system.mapper.UserRoleRelationMapper; import io.metersphere.system.mapper.UserRoleRelationMapper;
import io.metersphere.system.service.GlobalUserRoleRelationService; import io.metersphere.system.service.GlobalUserRoleRelationService;
import io.metersphere.system.service.UserInviteService;
import io.metersphere.system.service.UserService; import io.metersphere.system.service.UserService;
import io.metersphere.system.service.UserToolService; import io.metersphere.system.service.UserToolService;
import io.metersphere.system.uid.IDGenerator; import io.metersphere.system.uid.IDGenerator;
@ -47,6 +45,7 @@ import jakarta.annotation.Resource;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.MapUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.http.HttpHeaders; import org.apache.http.HttpHeaders;
import org.junit.jupiter.api.*; import org.junit.jupiter.api.*;
@ -121,19 +120,19 @@ public class UserControllerTests extends BaseTest {
@Test @Test
@Order(0) @Order(0)
public void testGetGlobalSystemUserRoleSuccess() throws Exception { void testGetGlobalSystemUserRoleSuccess() throws Exception {
MvcResult mvcResult = userRequestUtils.responseGet(UserRequestUtils.URL_GET_GLOBAL_SYSTEM); MvcResult mvcResult = userRequestUtils.responseGet(UserRequestUtils.URL_GET_GLOBAL_SYSTEM);
this.setDefaultUserRoleList(mvcResult); this.setDefaultUserRoleList(mvcResult);
} }
@Test @Test
@Order(1) @Order(1)
public void testAddSuccess() throws Exception { void testAddSuccess() throws Exception {
if (CollectionUtils.isEmpty(USER_ROLE_LIST)) { if (CollectionUtils.isEmpty(USER_ROLE_LIST)) {
this.testGetGlobalSystemUserRoleSuccess(); this.testGetGlobalSystemUserRoleSuccess();
} }
//模拟前台批量添加用户 //模拟前台批量添加用户
UserBatchCreateDTO userMaintainRequest = UserParamUtils.getUserCreateDTO( UserBatchCreateRequest userMaintainRequest = UserParamUtils.getUserCreateDTO(
USER_ROLE_LIST, USER_ROLE_LIST,
new ArrayList<>() {{ new ArrayList<>() {{
add(new UserCreateInfo() {{ add(new UserCreateInfo() {{
@ -160,7 +159,7 @@ public class UserControllerTests extends BaseTest {
}}); }});
} }
userMaintainRequest = UserParamUtils.getUserCreateDTO( userMaintainRequest = UserParamUtils.getUserCreateDTO(
Collections.singletonList(USER_ROLE_LIST.get(0)), Collections.singletonList(USER_ROLE_LIST.getFirst()),
userCreateInfoList userCreateInfoList
); );
mvcResult = userRequestUtils.responsePost(UserRequestUtils.URL_USER_CREATE, userMaintainRequest); mvcResult = userRequestUtils.responsePost(UserRequestUtils.URL_USER_CREATE, userMaintainRequest);
@ -190,7 +189,7 @@ public class UserControllerTests extends BaseTest {
@Sql(scripts = {"/dml/init_user_controller_test.sql"}, @Sql(scripts = {"/dml/init_user_controller_test.sql"},
config = @SqlConfig(encoding = "utf-8", transactionMode = SqlConfig.TransactionMode.ISOLATED), config = @SqlConfig(encoding = "utf-8", transactionMode = SqlConfig.TransactionMode.ISOLATED),
executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD) executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD)
public void testGetByEmailSuccess() throws Exception { void testGetByEmailSuccess() throws Exception {
this.checkUserList(); this.checkUserList();
UserDTO userDTO = this.getUserByEmail(USER_DEFAULT_EMAIL); UserDTO userDTO = this.getUserByEmail(USER_DEFAULT_EMAIL);
//返回值不为空 //返回值不为空
@ -215,7 +214,7 @@ public class UserControllerTests extends BaseTest {
@Test @Test
@Order(2) @Order(2)
public void testGetByEmailError() throws Exception { void testGetByEmailError() throws Exception {
//测试使用任意参数不能获取到任何用户信息 //测试使用任意参数不能获取到任何用户信息
this.checkUserList(); this.checkUserList();
String url = UserRequestUtils.URL_USER_GET + IDGenerator.nextNum(); String url = UserRequestUtils.URL_USER_GET + IDGenerator.nextNum();
@ -231,7 +230,7 @@ public class UserControllerTests extends BaseTest {
@Test @Test
@Order(3) @Order(3)
public void testPageSuccess() throws Exception { void testPageSuccess() throws Exception {
if (CollectionUtils.isEmpty(USER_ROLE_LIST)) { if (CollectionUtils.isEmpty(USER_ROLE_LIST)) {
this.testGetGlobalSystemUserRoleSuccess(); this.testGetGlobalSystemUserRoleSuccess();
} }
@ -283,7 +282,7 @@ public class UserControllerTests extends BaseTest {
returnPager = userRequestUtils.selectUserPage(basePageRequest); returnPager = userRequestUtils.selectUserPage(basePageRequest);
//第一个数据的createTime是最大的 //第一个数据的createTime是最大的
List<UserTableResponse> userInfoList = JSON.parseArray(JSON.toJSONString(returnPager.getList()), UserTableResponse.class); List<UserTableResponse> userInfoList = JSON.parseArray(JSON.toJSONString(returnPager.getList()), UserTableResponse.class);
long firstCreateTime = userInfoList.get(0).getCreateTime(); long firstCreateTime = userInfoList.getFirst().getCreateTime();
for (UserTableResponse userInfo : userInfoList) { for (UserTableResponse userInfo : userInfoList) {
Assertions.assertFalse(userInfo.getCreateTime() > firstCreateTime); Assertions.assertFalse(userInfo.getCreateTime() > firstCreateTime);
} }
@ -310,19 +309,22 @@ public class UserControllerTests extends BaseTest {
@Test @Test
@Order(3) @Order(3)
public void testPageError() throws Exception { void testPageError() throws Exception {
//当前页码不大于0 //当前页码不大于0
BasePageRequest basePageRequest = new BasePageRequest(); BasePageRequest basePageRequest = new BasePageRequest();
basePageRequest.setPageSize(5); basePageRequest.setPageSize(5);
this.requestPost(UserRequestUtils.URL_USER_PAGE, basePageRequest, BAD_REQUEST_MATCHER); this.requestPost(UserRequestUtils.URL_USER_PAGE, basePageRequest).andExpect(BAD_REQUEST_MATCHER);
//pageSize超过501 //pageSize超过501
basePageRequest = UserParamUtils.getDefaultPageRequest(); basePageRequest = UserParamUtils.getDefaultPageRequest();
basePageRequest.setPageSize(501); basePageRequest.setPageSize(501);
this.requestPost(UserRequestUtils.URL_USER_PAGE, basePageRequest, BAD_REQUEST_MATCHER); this.requestPost(UserRequestUtils.URL_USER_PAGE, basePageRequest).andExpect(BAD_REQUEST_MATCHER);
//当前页数不大于5 //当前页数不大于5
basePageRequest = new BasePageRequest(); basePageRequest = new BasePageRequest();
basePageRequest.setCurrent(1); basePageRequest.setCurrent(1);
this.requestPost(UserRequestUtils.URL_USER_PAGE, basePageRequest, BAD_REQUEST_MATCHER); this.requestPost(UserRequestUtils.URL_USER_PAGE, basePageRequest).andExpect(BAD_REQUEST_MATCHER);
//排序字段不合法 //排序字段不合法
basePageRequest = new BasePageRequest(); basePageRequest = new BasePageRequest();
basePageRequest.setCurrent(1); basePageRequest.setCurrent(1);
@ -330,15 +332,16 @@ public class UserControllerTests extends BaseTest {
basePageRequest.setSort(new HashMap<>() {{ basePageRequest.setSort(new HashMap<>() {{
put("SELECT * FROM user", "asc"); put("SELECT * FROM user", "asc");
}}); }});
this.requestPost(UserRequestUtils.URL_USER_PAGE, basePageRequest, BAD_REQUEST_MATCHER); this.requestPost(UserRequestUtils.URL_USER_PAGE, basePageRequest).andExpect(BAD_REQUEST_MATCHER);
} }
@Test @Test
@Order(4) @Order(4)
public void testUserUpdateSuccess() throws Exception { void testUserUpdateSuccess() throws Exception {
this.checkUserList(); this.checkUserList();
UserCreateInfo user = new UserCreateInfo(); UserCreateInfo user = new UserCreateInfo();
BeanUtils.copyBean(user, USER_LIST.get(0)); BeanUtils.copyBean(user, USER_LIST.getFirst());
UserEditRequest userMaintainRequest; UserEditRequest userMaintainRequest;
UserEditRequest response; UserEditRequest response;
UserDTO checkDTO; UserDTO checkDTO;
@ -389,7 +392,7 @@ public class UserControllerTests extends BaseTest {
UserParamUtils.compareUserDTO(response, checkDTO); UserParamUtils.compareUserDTO(response, checkDTO);
//用户信息复原 //用户信息复原
user = new UserCreateInfo(); user = new UserCreateInfo();
BeanUtils.copyBean(user, USER_LIST.get(0)); BeanUtils.copyBean(user, USER_LIST.getFirst());
userMaintainRequest = UserParamUtils.getUserUpdateDTO(user, USER_ROLE_LIST); userMaintainRequest = UserParamUtils.getUserUpdateDTO(user, USER_ROLE_LIST);
response = userRequestUtils.parseObjectFromMvcResult(userRequestUtils.responsePost(UserRequestUtils.URL_USER_UPDATE, userMaintainRequest), UserEditRequest.class); response = userRequestUtils.parseObjectFromMvcResult(userRequestUtils.responsePost(UserRequestUtils.URL_USER_UPDATE, userMaintainRequest), UserEditRequest.class);
LOG_CHECK_LIST.add( LOG_CHECK_LIST.add(
@ -401,55 +404,53 @@ public class UserControllerTests extends BaseTest {
@Test @Test
@Order(5) @Order(5)
public void testUserUpdateError() throws Exception { void testUserUpdateError() throws Exception {
this.checkUserList(); this.checkUserList();
// 4xx 验证 // 4xx 验证
UserCreateInfo user = new UserCreateInfo(); UserCreateInfo user = new UserCreateInfo();
UserEditRequest userMaintainRequest; UserEditRequest userMaintainRequest;
//更改名字 //更改名字
BeanUtils.copyBean(user, USER_LIST.get(0)); BeanUtils.copyBean(user, USER_LIST.getFirst());
user.setName(""); user.setName("");
userMaintainRequest = UserParamUtils.getUserUpdateDTO(user, USER_ROLE_LIST); userMaintainRequest = UserParamUtils.getUserUpdateDTO(user, USER_ROLE_LIST);
this.requestPost(UserRequestUtils.URL_USER_UPDATE, userMaintainRequest, BAD_REQUEST_MATCHER); this.requestPost(UserRequestUtils.URL_USER_UPDATE, userMaintainRequest).andExpect(BAD_REQUEST_MATCHER);
//email为空 //email为空
BeanUtils.copyBean(user, USER_LIST.get(0)); BeanUtils.copyBean(user, USER_LIST.getFirst());
user.setEmail(""); user.setEmail("");
userMaintainRequest = UserParamUtils.getUserUpdateDTO(user, USER_ROLE_LIST); userMaintainRequest = UserParamUtils.getUserUpdateDTO(user, USER_ROLE_LIST);
this.requestPost(UserRequestUtils.URL_USER_UPDATE, userMaintainRequest, BAD_REQUEST_MATCHER); this.requestPost(UserRequestUtils.URL_USER_UPDATE, userMaintainRequest).andExpect(BAD_REQUEST_MATCHER);
//手机号为空 //手机号为空
BeanUtils.copyBean(user, USER_LIST.get(0)); BeanUtils.copyBean(user, USER_LIST.getFirst());
user.setEmail(""); user.setEmail("");
userMaintainRequest = UserParamUtils.getUserUpdateDTO(user, USER_ROLE_LIST); userMaintainRequest = UserParamUtils.getUserUpdateDTO(user, USER_ROLE_LIST);
this.requestPost(UserRequestUtils.URL_USER_UPDATE, userMaintainRequest, BAD_REQUEST_MATCHER); this.requestPost(UserRequestUtils.URL_USER_UPDATE, userMaintainRequest).andExpect(BAD_REQUEST_MATCHER);
//用户组为空 //用户组为空
BeanUtils.copyBean(user, USER_LIST.get(0)); BeanUtils.copyBean(user, USER_LIST.getFirst());
userMaintainRequest = UserParamUtils.getUserUpdateDTO(user, new ArrayList<>()); userMaintainRequest = UserParamUtils.getUserUpdateDTO(user, new ArrayList<>());
userMaintainRequest.setUserRoleIdList(new ArrayList<>()); userMaintainRequest.setUserRoleIdList(new ArrayList<>());
this.requestPost(UserRequestUtils.URL_USER_UPDATE, userMaintainRequest, BAD_REQUEST_MATCHER); this.requestPost(UserRequestUtils.URL_USER_UPDATE, userMaintainRequest).andExpect(BAD_REQUEST_MATCHER);
// 500验证 // 500验证
//邮箱重复 //邮箱重复
this.checkUserList(); this.checkUserList();
BeanUtils.copyBean(user, USER_LIST.get(0)); BeanUtils.copyBean(user, USER_LIST.getFirst());
user.setEmail(USER_LIST.get(USER_LIST.size() - 1).getEmail()); user.setEmail(USER_LIST.getLast().getEmail());
userMaintainRequest = UserParamUtils.getUserUpdateDTO(user, USER_ROLE_LIST); userMaintainRequest = UserParamUtils.getUserUpdateDTO(user, USER_ROLE_LIST);
MvcResult mvcResult = this.requestPost(UserRequestUtils.URL_USER_UPDATE, userMaintainRequest, ERROR_REQUEST_MATCHER).andReturn(); MvcResult mvcResult = this.requestPost(UserRequestUtils.URL_USER_UPDATE, userMaintainRequest).andExpect(ERROR_REQUEST_MATCHER).andReturn();
ResultHolder resultHolder = JSON.parseObject(mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8), ResultHolder.class); ResultHolder resultHolder = JSON.parseObject(mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8), ResultHolder.class);
Assertions.assertEquals(resultHolder.getMessage(), "用户邮箱已存在"); Assertions.assertEquals(resultHolder.getMessage(), "用户邮箱已存在");
//用户组不包含系统成员
BeanUtils.copyBean(user, USER_LIST.get(0));
userMaintainRequest = UserParamUtils.getUserUpdateDTO(user,
USER_ROLE_LIST.stream().filter(item -> !StringUtils.equals(item.getId(), "member")).toList()
);
this.requestPost(UserRequestUtils.URL_USER_UPDATE, userMaintainRequest, ERROR_REQUEST_MATCHER);
} }
@Test @Test
@Order(6) @Order(6)
public void testUserChangeEnableSuccess() throws Exception { void testUserChangeEnableSuccess() throws Exception {
this.checkUserList(); this.checkUserList();
UserCreateInfo userInfo = USER_LIST.get(0); UserCreateInfo userInfo = USER_LIST.getFirst();
//先使用要操作的用户登录,用于检查会不会把账户踢出 //先使用要操作的用户登录,用于检查会不会把账户踢出
MvcResult mvcResult = mockMvc.perform(MockMvcRequestBuilders.post("/login") MvcResult mvcResult = mockMvc.perform(MockMvcRequestBuilders.post("/login")
@ -476,7 +477,7 @@ public class UserControllerTests extends BaseTest {
this.add(userInfo.getId()); this.add(userInfo.getId());
}}); }});
userChangeEnableRequest.setEnable(false); userChangeEnableRequest.setEnable(false);
this.requestPost(UserRequestUtils.URL_USER_UPDATE_ENABLE, userChangeEnableRequest, status().isOk()); this.requestPostWithOk(UserRequestUtils.URL_USER_UPDATE_ENABLE, userChangeEnableRequest);
for (String item : userChangeEnableRequest.getSelectIds()) { for (String item : userChangeEnableRequest.getSelectIds()) {
LOG_CHECK_LIST.add( LOG_CHECK_LIST.add(
new CheckLogModel(item, OperationLogType.UPDATE, UserRequestUtils.URL_USER_UPDATE_ENABLE) new CheckLogModel(item, OperationLogType.UPDATE, UserRequestUtils.URL_USER_UPDATE_ENABLE)
@ -497,7 +498,7 @@ public class UserControllerTests extends BaseTest {
//修改状态开启 //修改状态开启
userChangeEnableRequest.setEnable(true); userChangeEnableRequest.setEnable(true);
this.requestPost(UserRequestUtils.URL_USER_UPDATE_ENABLE, userChangeEnableRequest, status().isOk()); this.requestPostWithOk(UserRequestUtils.URL_USER_UPDATE_ENABLE, userChangeEnableRequest);
for (String item : userChangeEnableRequest.getSelectIds()) { for (String item : userChangeEnableRequest.getSelectIds()) {
LOG_CHECK_LIST.add( LOG_CHECK_LIST.add(
new CheckLogModel(item, OperationLogType.UPDATE, UserRequestUtils.URL_USER_UPDATE_ENABLE) new CheckLogModel(item, OperationLogType.UPDATE, UserRequestUtils.URL_USER_UPDATE_ENABLE)
@ -510,28 +511,29 @@ public class UserControllerTests extends BaseTest {
@Test @Test
@Order(6) @Order(6)
public void testUserChangeEnableError() throws Exception { void testUserChangeEnableError() throws Exception {
this.checkUserList(); this.checkUserList();
//用户不存在 //用户不存在
UserChangeEnableRequest userChangeEnableRequest = new UserChangeEnableRequest(); UserChangeEnableRequest userChangeEnableRequest = new UserChangeEnableRequest();
userChangeEnableRequest.setEnable(false); userChangeEnableRequest.setEnable(false);
this.requestPost(UserRequestUtils.URL_USER_UPDATE_ENABLE, userChangeEnableRequest, BAD_REQUEST_MATCHER); this.requestPost(UserRequestUtils.URL_USER_UPDATE_ENABLE, userChangeEnableRequest).andExpect(ERROR_REQUEST_MATCHER);
//含有非法用户 //含有非法用户
userChangeEnableRequest.setSelectIds(new ArrayList<>() {{ userChangeEnableRequest.setSelectIds(new ArrayList<>() {{
this.add("BCDEDIT"); this.add("BCDEDIT");
}}); }});
this.requestPost(UserRequestUtils.URL_USER_UPDATE_ENABLE, userChangeEnableRequest, ERROR_REQUEST_MATCHER); this.requestPost(UserRequestUtils.URL_USER_UPDATE_ENABLE, userChangeEnableRequest).andExpect(ERROR_REQUEST_MATCHER);
//含有当前用户 //含有当前用户
userChangeEnableRequest.setSelectIds(new ArrayList<>() {{ userChangeEnableRequest.setSelectIds(new ArrayList<>() {{
this.add("admin"); this.add("admin");
}}); }});
this.requestPost(UserRequestUtils.URL_USER_UPDATE_ENABLE, userChangeEnableRequest, ERROR_REQUEST_MATCHER); this.requestPost(UserRequestUtils.URL_USER_UPDATE_ENABLE, userChangeEnableRequest).andExpect(ERROR_REQUEST_MATCHER);
} }
@Test @Test
@Order(7) @Order(7)
public void testUserImport() throws Exception { void testUserImport() throws Exception {
this.checkUserList(); this.checkUserList();
//测试用户数据导入 每个导入文件都有10条数据不同文件出错的数据不同 //测试用户数据导入 每个导入文件都有10条数据不同文件出错的数据不同
int importSuccessData = 10;//应该导入成功的数据数量 int importSuccessData = 10;//应该导入成功的数据数量
@ -620,7 +622,7 @@ public class UserControllerTests extends BaseTest {
@Test @Test
@Order(8) @Order(8)
public void testUserResetPasswordError() throws Exception { void testUserResetPasswordError() throws Exception {
//用户不存在 //用户不存在
{ {
TableBatchProcessDTO request = new TableBatchProcessDTO(); TableBatchProcessDTO request = new TableBatchProcessDTO();
@ -631,11 +633,11 @@ public class UserControllerTests extends BaseTest {
@Test @Test
@Order(1) @Order(1)
public void testAddError() throws Exception { void testAddError() throws Exception {
if (CollectionUtils.isEmpty(USER_ROLE_LIST)) { if (CollectionUtils.isEmpty(USER_ROLE_LIST)) {
this.testGetGlobalSystemUserRoleSuccess(); this.testGetGlobalSystemUserRoleSuccess();
} }
UserBatchCreateDTO userMaintainRequest; UserBatchCreateRequest userMaintainRequest;
List<UserCreateInfo> errorUserList = new ArrayList<>() {{ List<UserCreateInfo> errorUserList = new ArrayList<>() {{
add(new UserCreateInfo() {{ add(new UserCreateInfo() {{
setName("tianyang.error.1"); setName("tianyang.error.1");
@ -653,24 +655,24 @@ public class UserControllerTests extends BaseTest {
*/ */
//所有参数都为空 //所有参数都为空
userMaintainRequest = UserParamUtils.getUserCreateDTO(null, null); userMaintainRequest = UserParamUtils.getUserCreateDTO(null, null);
this.requestPost(UserRequestUtils.URL_USER_CREATE, userMaintainRequest, BAD_REQUEST_MATCHER); this.requestPost(UserRequestUtils.URL_USER_CREATE, userMaintainRequest).andExpect(BAD_REQUEST_MATCHER);
//用户组ID为空 //用户组ID为空
userMaintainRequest = UserParamUtils.getUserCreateDTO( userMaintainRequest = UserParamUtils.getUserCreateDTO(
null, null,
errorUserList); errorUserList);
this.requestPost(UserRequestUtils.URL_USER_CREATE, userMaintainRequest, BAD_REQUEST_MATCHER); this.requestPost(UserRequestUtils.URL_USER_CREATE, userMaintainRequest).andExpect(BAD_REQUEST_MATCHER);
//没有用户 //没有用户
userMaintainRequest = UserParamUtils.getUserCreateDTO( userMaintainRequest = UserParamUtils.getUserCreateDTO(
USER_ROLE_LIST, USER_ROLE_LIST,
null); null);
this.requestPost(UserRequestUtils.URL_USER_CREATE, userMaintainRequest, BAD_REQUEST_MATCHER); this.requestPost(UserRequestUtils.URL_USER_CREATE, userMaintainRequest).andExpect(BAD_REQUEST_MATCHER);
//用户组含有null //用户组含有null
userMaintainRequest = UserParamUtils.getUserCreateDTO( userMaintainRequest = UserParamUtils.getUserCreateDTO(
USER_ROLE_LIST, USER_ROLE_LIST,
errorUserList); errorUserList);
userMaintainRequest.getUserRoleIdList().add(null); userMaintainRequest.getUserRoleIdList().add(null);
userMaintainRequest.getUserRoleIdList().add(""); userMaintainRequest.getUserRoleIdList().add("");
this.requestPost(UserRequestUtils.URL_USER_CREATE, userMaintainRequest, BAD_REQUEST_MATCHER); this.requestPost(UserRequestUtils.URL_USER_CREATE, userMaintainRequest).andExpect(BAD_REQUEST_MATCHER);
//含有用户名称为空的数据 //含有用户名称为空的数据
userMaintainRequest = UserParamUtils.getUserCreateDTO( userMaintainRequest = UserParamUtils.getUserCreateDTO(
USER_ROLE_LIST, USER_ROLE_LIST,
@ -679,7 +681,7 @@ public class UserControllerTests extends BaseTest {
userMaintainRequest.getUserInfoList().add(new UserCreateInfo() {{ userMaintainRequest.getUserInfoList().add(new UserCreateInfo() {{
setEmail("tianyang.name.empty@126.com"); setEmail("tianyang.name.empty@126.com");
}}); }});
this.requestPost(UserRequestUtils.URL_USER_CREATE, userMaintainRequest, BAD_REQUEST_MATCHER); this.requestPost(UserRequestUtils.URL_USER_CREATE, userMaintainRequest).andExpect(BAD_REQUEST_MATCHER);
//含有用户邮箱为空的数据 //含有用户邮箱为空的数据
userMaintainRequest = UserParamUtils.getUserCreateDTO( userMaintainRequest = UserParamUtils.getUserCreateDTO(
USER_ROLE_LIST, USER_ROLE_LIST,
@ -688,7 +690,7 @@ public class UserControllerTests extends BaseTest {
userMaintainRequest.getUserInfoList().add(new UserCreateInfo() {{ userMaintainRequest.getUserInfoList().add(new UserCreateInfo() {{
setName("tianyang.email.empty"); setName("tianyang.email.empty");
}}); }});
this.requestPost(UserRequestUtils.URL_USER_CREATE, userMaintainRequest, BAD_REQUEST_MATCHER); this.requestPost(UserRequestUtils.URL_USER_CREATE, userMaintainRequest).andExpect(BAD_REQUEST_MATCHER);
//用户邮箱不符合标准 //用户邮箱不符合标准
userMaintainRequest = UserParamUtils.getUserCreateDTO( userMaintainRequest = UserParamUtils.getUserCreateDTO(
USER_ROLE_LIST, USER_ROLE_LIST,
@ -698,7 +700,7 @@ public class UserControllerTests extends BaseTest {
setName("用户邮箱放飞自我"); setName("用户邮箱放飞自我");
setEmail("用户邮箱放飞自我"); setEmail("用户邮箱放飞自我");
}}); }});
this.requestPost(UserRequestUtils.URL_USER_CREATE, userMaintainRequest, BAD_REQUEST_MATCHER); this.requestPost(UserRequestUtils.URL_USER_CREATE, userMaintainRequest).andExpect(BAD_REQUEST_MATCHER);
/* /*
* 校验业务判断出错的反例 500 error) * 校验业务判断出错的反例 500 error)
* 需要保证数据库有正常数据 * 需要保证数据库有正常数据
@ -712,18 +714,21 @@ public class UserControllerTests extends BaseTest {
}}); }});
}}, }},
errorUserList); errorUserList);
this.requestPost(UserRequestUtils.URL_USER_CREATE, userMaintainRequest, ERROR_REQUEST_MATCHER); this.requestPost(UserRequestUtils.URL_USER_CREATE, userMaintainRequest).andExpect(ERROR_REQUEST_MATCHER);
//含有重复的用户邮箱 //含有重复的用户邮箱
userMaintainRequest = UserParamUtils.getUserCreateDTO( userMaintainRequest = UserParamUtils.getUserCreateDTO(
USER_ROLE_LIST, USER_ROLE_LIST,
errorUserList errorUserList
); );
String firstUserEmail = userMaintainRequest.getUserInfoList().get(0).getEmail(); String firstUserEmail = userMaintainRequest.getUserInfoList().getFirst().getEmail();
userMaintainRequest.getUserInfoList().add(new UserCreateInfo() {{ userMaintainRequest.getUserInfoList().add(new UserCreateInfo() {{
setName("tianyang.no.error4"); setName("tianyang.no.error4");
setEmail(firstUserEmail); setEmail(firstUserEmail);
}}); }});
this.requestPost(UserRequestUtils.URL_USER_CREATE, userMaintainRequest, ERROR_REQUEST_MATCHER); MvcResult errorEmailResult = this.requestPostWithOkAndReturn(UserRequestUtils.URL_USER_CREATE, userMaintainRequest);
ResultHolder errorEmailResultHolder = JSON.parseObject(errorEmailResult.getResponse().getContentAsString(StandardCharsets.UTF_8), ResultHolder.class);
UserBatchCreateResponse errorEmailResponse = JSON.parseObject(JSON.toJSONString(errorEmailResultHolder.getData()), UserBatchCreateResponse.class);
Assertions.assertTrue(MapUtils.isNotEmpty(errorEmailResponse.getErrorEmails()));
//测试请求参数中含有数据库中已存在的邮箱情况 //测试请求参数中含有数据库中已存在的邮箱情况
userMaintainRequest = UserParamUtils.getUserCreateDTO( userMaintainRequest = UserParamUtils.getUserCreateDTO(
USER_ROLE_LIST, USER_ROLE_LIST,
@ -737,12 +742,15 @@ public class UserControllerTests extends BaseTest {
}}); }});
}} }}
); );
this.requestPost(UserRequestUtils.URL_USER_CREATE, userMaintainRequest, ERROR_REQUEST_MATCHER); errorEmailResult = this.requestPostWithOkAndReturn(UserRequestUtils.URL_USER_CREATE, userMaintainRequest);
errorEmailResultHolder = JSON.parseObject(errorEmailResult.getResponse().getContentAsString(StandardCharsets.UTF_8), ResultHolder.class);
errorEmailResponse = JSON.parseObject(JSON.toJSONString(errorEmailResultHolder.getData()), UserBatchCreateResponse.class);
Assertions.assertTrue(MapUtils.isNotEmpty(errorEmailResponse.getErrorEmails()));
} }
@Test @Test
@Order(8) @Order(8)
public void testUserResetPasswordSuccess() throws Exception { void testUserResetPasswordSuccess() throws Exception {
this.checkUserList(); this.checkUserList();
//重置admin的密码 //重置admin的密码
{ {
@ -760,7 +768,7 @@ public class UserControllerTests extends BaseTest {
//重置普通用户密码 //重置普通用户密码
{ {
User paramUser = new User(); User paramUser = new User();
String userId = USER_LIST.get(0).getId(); String userId = USER_LIST.getFirst().getId();
paramUser.setId(userId); paramUser.setId(userId);
paramUser.setPassword("I can't say any dirty words"); paramUser.setPassword("I can't say any dirty words");
Assertions.assertEquals(1, userMapper.updateByPrimaryKeySelective(paramUser)); Assertions.assertEquals(1, userMapper.updateByPrimaryKeySelective(paramUser));
@ -811,7 +819,7 @@ public class UserControllerTests extends BaseTest {
@Test @Test
@Order(9) @Order(9)
public void testUserRoleRelationSuccess() throws Exception { void testUserRoleRelationSuccess() throws Exception {
//UserList中的部分角色是没有添加到某权限中的 //UserList中的部分角色是没有添加到某权限中的
if (USER_LIST.size() < 50) { if (USER_LIST.size() < 50) {
this.testAddSuccess(); this.testAddSuccess();
@ -845,7 +853,7 @@ public class UserControllerTests extends BaseTest {
@Test @Test
@Order(9) @Order(9)
public void testUserRoleRelationError() throws Exception { void testUserRoleRelationError() throws Exception {
//UserList中的部分角色是没有添加到某权限中的 //UserList中的部分角色是没有添加到某权限中的
if (USER_LIST.size() < 50) { if (USER_LIST.size() < 50) {
this.testAddSuccess(); this.testAddSuccess();
@ -877,7 +885,7 @@ public class UserControllerTests extends BaseTest {
@Test @Test
@Order(9) @Order(9)
public void testGetEmptyProject() throws Exception { void testGetEmptyProject() throws Exception {
//测试如果没有项目系统不会报错 //测试如果没有项目系统不会报错
List<Project> allProjectList = projectMapper.selectByExample(null); List<Project> allProjectList = projectMapper.selectByExample(null);
projectMapper.deleteByExample(null); projectMapper.deleteByExample(null);
@ -906,7 +914,7 @@ public class UserControllerTests extends BaseTest {
@Sql(scripts = {"/dml/init_user_org_project.sql"}, @Sql(scripts = {"/dml/init_user_org_project.sql"},
config = @SqlConfig(encoding = "utf-8", transactionMode = SqlConfig.TransactionMode.ISOLATED), config = @SqlConfig(encoding = "utf-8", transactionMode = SqlConfig.TransactionMode.ISOLATED),
executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD) executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD)
public void testGetProjectAndOrganization() throws Exception { void testGetProjectAndOrganization() throws Exception {
String str = userRequestUtils.responseGet(UserRequestUtils.URL_GET_PROJECT).getResponse().getContentAsString(StandardCharsets.UTF_8); String str = userRequestUtils.responseGet(UserRequestUtils.URL_GET_PROJECT).getResponse().getContentAsString(StandardCharsets.UTF_8);
ResultHolder rh = JSON.parseObject(str, ResultHolder.class); ResultHolder rh = JSON.parseObject(str, ResultHolder.class);
List<BaseTreeNode> userTreeSelectOptions = JSON.parseArray( List<BaseTreeNode> userTreeSelectOptions = JSON.parseArray(
@ -928,7 +936,7 @@ public class UserControllerTests extends BaseTest {
@Test @Test
@Order(11) @Order(11)
public void testAddProjectMember() throws Exception { void testAddProjectMember() throws Exception {
//UserList中的部分角色是没有添加到某权限中的 //UserList中的部分角色是没有添加到某权限中的
if (CollectionUtils.isEmpty(USER_LIST)) { if (CollectionUtils.isEmpty(USER_LIST)) {
this.testAddSuccess(); this.testAddSuccess();
@ -980,7 +988,7 @@ public class UserControllerTests extends BaseTest {
@Test @Test
@Order(13) @Order(13)
public void testAddOrganization() throws Exception { void testAddOrganization() throws Exception {
//UserList中的部分角色是没有添加到某权限中的 //UserList中的部分角色是没有添加到某权限中的
if (CollectionUtils.isEmpty(USER_LIST)) { if (CollectionUtils.isEmpty(USER_LIST)) {
this.testAddSuccess(); this.testAddSuccess();
@ -1024,7 +1032,7 @@ public class UserControllerTests extends BaseTest {
@Test @Test
@Order(11) @Order(11)
public void testAddToOrgOrProjectError() throws Exception { void testAddToOrgOrProjectError() throws Exception {
if (CollectionUtils.isEmpty(PROJECT_LIST) || CollectionUtils.isEmpty(ORG_LIST)) { if (CollectionUtils.isEmpty(PROJECT_LIST) || CollectionUtils.isEmpty(ORG_LIST)) {
this.testGetProjectAndOrganization(); this.testGetProjectAndOrganization();
} }
@ -1074,7 +1082,7 @@ public class UserControllerTests extends BaseTest {
@Test @Test
@Order(12) @Order(12)
public void testUserInvite() throws Exception { void testUserInvite() throws Exception {
if (CollectionUtils.isEmpty(USER_LIST)) { if (CollectionUtils.isEmpty(USER_LIST)) {
this.testAddSuccess(); this.testAddSuccess();
} }
@ -1084,7 +1092,7 @@ public class UserControllerTests extends BaseTest {
@Test @Test
@Order(13) @Order(13)
public void testUserRegister() throws Exception { void testUserRegister() throws Exception {
if (CollectionUtils.isEmpty(INVITE_RECORD_ID_LIST)) { if (CollectionUtils.isEmpty(INVITE_RECORD_ID_LIST)) {
this.testUserInvite(); this.testUserInvite();
} }
@ -1094,18 +1102,18 @@ public class UserControllerTests extends BaseTest {
@Test @Test
@Order(14) @Order(14)
public void testGetKey() throws Exception { void testGetKey() throws Exception {
this.requestGetWithOk("/get-key"); this.requestGetWithOk("/get-key");
} }
//本测试类中会用到很多次用户数据所以测试删除的方法放于最后 //本测试类中会用到很多次用户数据所以测试删除的方法放于最后
@Test @Test
@Order(99) @Order(99)
public void testUserDeleteSuccess() throws Exception { void testUserDeleteSuccess() throws Exception {
this.checkUserList(); this.checkUserList();
//先使用要操作的用户登录,用于检查会不会把账户踢出 //先使用要操作的用户登录,用于检查会不会把账户踢出
UserCreateInfo userInfo = USER_LIST.get(0); UserCreateInfo userInfo = USER_LIST.getFirst();
MvcResult mvcResult = mockMvc.perform(MockMvcRequestBuilders.post("/login") MvcResult mvcResult = mockMvc.perform(MockMvcRequestBuilders.post("/login")
.content(String.format("{\"username\":\"%s\",\"password\":\"%s\"}", userInfo.getEmail(), userInfo.getEmail())) .content(String.format("{\"username\":\"%s\",\"password\":\"%s\"}", userInfo.getEmail(), userInfo.getEmail()))
.contentType(MediaType.APPLICATION_JSON)) .contentType(MediaType.APPLICATION_JSON))
@ -1159,30 +1167,30 @@ public class UserControllerTests extends BaseTest {
//删除失败的方法要放在删除成功方法后面执行 //删除失败的方法要放在删除成功方法后面执行
@Test @Test
@Order(100) @Order(100)
public void testUserDeleteError() throws Exception { void testUserDeleteError() throws Exception {
//参数为空 //参数为空
TableBatchProcessDTO request = new TableBatchProcessDTO(); TableBatchProcessDTO request = new TableBatchProcessDTO();
this.requestPost(UserRequestUtils.URL_USER_DELETE, request, ERROR_REQUEST_MATCHER); this.requestPost(UserRequestUtils.URL_USER_DELETE, request).andExpect(ERROR_REQUEST_MATCHER);
//用户不存在 //用户不存在
request.setSelectIds(Collections.singletonList("none user")); request.setSelectIds(Collections.singletonList("none user"));
this.requestPost(UserRequestUtils.URL_USER_DELETE, request, ERROR_REQUEST_MATCHER); this.requestPost(UserRequestUtils.URL_USER_DELETE, request).andExpect(ERROR_REQUEST_MATCHER);
//测试用户已经被删除的 //测试用户已经被删除的
if (CollectionUtils.isEmpty(DELETED_USER_ID_LIST)) { if (CollectionUtils.isEmpty(DELETED_USER_ID_LIST)) {
this.testUserDeleteSuccess(); this.testUserDeleteSuccess();
} }
request.setSelectIds(DELETED_USER_ID_LIST); request.setSelectIds(DELETED_USER_ID_LIST);
this.requestPost(UserRequestUtils.URL_USER_DELETE, request, ERROR_REQUEST_MATCHER); this.requestPost(UserRequestUtils.URL_USER_DELETE, request).andExpect(ERROR_REQUEST_MATCHER);
//测试包含Admin用户 //测试包含Admin用户
request = new TableBatchProcessDTO(); request = new TableBatchProcessDTO();
request.setSelectAll(true); request.setSelectAll(true);
this.requestPost(UserRequestUtils.URL_USER_DELETE, request, ERROR_REQUEST_MATCHER); this.requestPost(UserRequestUtils.URL_USER_DELETE, request).andExpect(ERROR_REQUEST_MATCHER);
} }
@Test @Test
@Order(101) @Order(101)
public void testLog() throws Exception { void testLog() throws Exception {
Thread.sleep(5000); Thread.sleep(5000);
for (CheckLogModel checkLogModel : LOG_CHECK_LIST) { for (CheckLogModel checkLogModel : LOG_CHECK_LIST) {
if (StringUtils.isEmpty(checkLogModel.getUrl())) { if (StringUtils.isEmpty(checkLogModel.getUrl())) {
@ -1216,16 +1224,16 @@ public class UserControllerTests extends BaseTest {
} }
//成功入库的用户保存内存中其他用例会使用到 //成功入库的用户保存内存中其他用例会使用到
private void addUser2List(MvcResult mvcResult) throws Exception { private void addUser2List(MvcResult mvcResult) {
UserBatchCreateDTO userMaintainRequest = userRequestUtils.parseObjectFromMvcResult(mvcResult, UserBatchCreateDTO.class); UserBatchCreateResponse userMaintainRequest = userRequestUtils.parseObjectFromMvcResult(mvcResult, UserBatchCreateResponse.class);
for (UserCreateInfo item : userMaintainRequest.getUserInfoList()) { for (UserCreateInfo item : userMaintainRequest.getSuccessList()) {
LOG_CHECK_LIST.add( LOG_CHECK_LIST.add(
new CheckLogModel(item.getId(), OperationLogType.ADD, null) new CheckLogModel(item.getId(), OperationLogType.ADD, null)
); );
} }
//返回值不为空 //返回值不为空
Assertions.assertNotNull(userMaintainRequest); Assertions.assertNotNull(userMaintainRequest);
USER_LIST.addAll(userMaintainRequest.getUserInfoList()); USER_LIST.addAll(userMaintainRequest.getSuccessList());
} }
private void checkUserList() throws Exception { private void checkUserList() throws Exception {
@ -1245,7 +1253,7 @@ public class UserControllerTests extends BaseTest {
return returnList; return returnList;
} }
public void testUserInviteSuccess() throws Exception { void testUserInviteSuccess() throws Exception {
UserInviteRequest userInviteRequest = UserParamUtils.getUserInviteRequest( UserInviteRequest userInviteRequest = UserParamUtils.getUserInviteRequest(
USER_ROLE_LIST, USER_ROLE_LIST,
new ArrayList<>() {{ new ArrayList<>() {{
@ -1253,19 +1261,18 @@ public class UserControllerTests extends BaseTest {
add("tianyang.song.invite.2@test.email"); add("tianyang.song.invite.2@test.email");
}} }}
); );
MvcResult mvcResult = userRequestUtils.responsePost(UserRequestUtils.URL_INVITE, userInviteRequest); //这里无法测试邮箱是否发出所以不针对结果进行校验
String resultHolderStr = mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8); this.requestPost(UserRequestUtils.URL_INVITE, userInviteRequest);
ResultHolder resultHolder = JSON.parseObject(resultHolderStr, ResultHolder.class);
UserInviteResponse response = JSON.parseObject(JSON.toJSONString(resultHolder.getData()), UserInviteResponse.class); List<UserInvite> inviteList = userInviteService.batchInsert(userInviteRequest.getInviteEmails(), "admin", userInviteRequest.getUserRoleIds());
Assertions.assertEquals(2, response.getInviteIds().size()); UserInviteResponse response = new UserInviteResponse(inviteList);
//检查日志 此处日志的资源是邀请的用户即admin
LOG_CHECK_LIST.add(
new CheckLogModel("admin", OperationLogType.ADD, UserRequestUtils.URL_INVITE)
);
INVITE_RECORD_ID_LIST.addAll(response.getInviteIds()); INVITE_RECORD_ID_LIST.addAll(response.getInviteIds());
} }
public void testUserInviteError() throws Exception { @Resource
private UserInviteService userInviteService;
void testUserInviteError() throws Exception {
List<String> inviteEmailList = new ArrayList<>() {{ List<String> inviteEmailList = new ArrayList<>() {{
add("tianyang.song.invite.error.1@test.email"); add("tianyang.song.invite.error.1@test.email");
add("tianyang.song.invite.error.2@test.email"); add("tianyang.song.invite.error.2@test.email");
@ -1319,12 +1326,12 @@ public class UserControllerTests extends BaseTest {
USER_ROLE_LIST, USER_ROLE_LIST,
inviteEmailList inviteEmailList
); );
userInviteRequest.getInviteEmails().add(USER_LIST.get(0).getEmail()); userInviteRequest.getInviteEmails().add(USER_LIST.getFirst().getEmail());
userRequestUtils.requestPost(UserRequestUtils.URL_INVITE, userInviteRequest, ERROR_REQUEST_MATCHER); userRequestUtils.requestPost(UserRequestUtils.URL_INVITE, userInviteRequest, ERROR_REQUEST_MATCHER);
} }
private void testUserRegisterSuccess() throws Exception { private void testUserRegisterSuccess() throws Exception {
String inviteId = INVITE_RECORD_ID_LIST.get(0); String inviteId = INVITE_RECORD_ID_LIST.getFirst();
UserRegisterRequest request = new UserRegisterRequest(); UserRegisterRequest request = new UserRegisterRequest();
request.setInviteId(inviteId); request.setInviteId(inviteId);
request.setName("建国通过邮箱邀请"); request.setName("建国通过邮箱邀请");
@ -1392,7 +1399,7 @@ public class UserControllerTests extends BaseTest {
userInviteMapper.updateByPrimaryKeySelective(invite); userInviteMapper.updateByPrimaryKeySelective(invite);
String insertEmail = invite.getEmail(); String insertEmail = invite.getEmail();
UserBatchCreateDTO userMaintainRequest = UserParamUtils.getUserCreateDTO( UserBatchCreateRequest userMaintainRequest = UserParamUtils.getUserCreateDTO(
USER_ROLE_LIST, USER_ROLE_LIST,
new ArrayList<>() {{ new ArrayList<>() {{
add(new UserCreateInfo() {{ add(new UserCreateInfo() {{

View File

@ -2,16 +2,16 @@ package io.metersphere.system.utils.user;
import io.metersphere.sdk.constants.UserRoleScope; import io.metersphere.sdk.constants.UserRoleScope;
import io.metersphere.sdk.constants.UserRoleType; import io.metersphere.sdk.constants.UserRoleType;
import io.metersphere.system.dto.sdk.BasePageRequest;
import io.metersphere.system.dto.user.UserDTO;
import io.metersphere.sdk.util.BeanUtils; import io.metersphere.sdk.util.BeanUtils;
import io.metersphere.system.domain.UserRole; import io.metersphere.system.domain.UserRole;
import io.metersphere.system.dto.UserBatchCreateDTO;
import io.metersphere.system.dto.UserCreateInfo;
import io.metersphere.system.dto.request.UserInviteRequest; import io.metersphere.system.dto.request.UserInviteRequest;
import io.metersphere.system.dto.request.user.UserEditRequest; import io.metersphere.system.dto.request.user.UserEditRequest;
import io.metersphere.system.dto.response.UserImportResponse; import io.metersphere.system.dto.sdk.BasePageRequest;
import io.metersphere.system.dto.response.UserSelectOption; import io.metersphere.system.dto.user.UserCreateInfo;
import io.metersphere.system.dto.user.UserDTO;
import io.metersphere.system.dto.user.request.UserBatchCreateRequest;
import io.metersphere.system.dto.user.response.UserImportResponse;
import io.metersphere.system.dto.user.response.UserSelectOption;
import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Assertions;
@ -23,10 +23,10 @@ import java.util.stream.Collectors;
public class UserParamUtils { public class UserParamUtils {
public static UserBatchCreateDTO getUserCreateDTO( public static UserBatchCreateRequest getUserCreateDTO(
List<UserSelectOption> userRoleList, List<UserSelectOption> userRoleList,
List<UserCreateInfo> userInfoList) { List<UserCreateInfo> userInfoList) {
UserBatchCreateDTO userMaintainRequest = new UserBatchCreateDTO(); UserBatchCreateRequest userMaintainRequest = new UserBatchCreateRequest();
if (CollectionUtils.isNotEmpty(userRoleList)) { if (CollectionUtils.isNotEmpty(userRoleList)) {
userMaintainRequest.setUserRoleIdList( userMaintainRequest.setUserRoleIdList(
userRoleList.stream().map(UserSelectOption::getId).collect(Collectors.toList())); userRoleList.stream().map(UserSelectOption::getId).collect(Collectors.toList()));