From 55a6ecae3b60f504ef0eeb78f8d4a539c2505e93 Mon Sep 17 00:00:00 2001 From: song-tianyang Date: Tue, 30 Jan 2024 19:10:45 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E7=B3=BB=E7=BB=9F=E8=AE=BE=E7=BD=AE):=20?= =?UTF-8?q?=E4=BC=98=E5=8C=96=E7=94=A8=E6=88=B7=E7=BC=96=E8=BE=91=E6=97=B6?= =?UTF-8?q?=E5=A1=AB=E5=86=99=E5=B7=B2=E5=AD=98=E5=9C=A8=E9=82=AE=E7=AE=B1?= =?UTF-8?q?=E7=9A=84=E6=8A=A5=E9=94=99=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/io/metersphere/system/service/UserService.java | 4 +++- .../system/controller/user/UserControllerTests.java | 5 ++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/service/UserService.java b/backend/services/system-setting/src/main/java/io/metersphere/system/service/UserService.java index bb54dd1c4b..a10a9ade65 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/service/UserService.java +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/service/UserService.java @@ -204,10 +204,12 @@ public class UserService { } } - public UserEditRequest updateUser(UserEditRequest userEditRequest, String operator) { //检查用户组合法性 globalUserRoleService.checkRoleIsGlobalAndHaveMember(userEditRequest.getUserRoleIdList(), true); + //检查用户邮箱的合法性 + this.checkUserEmail(userEditRequest.getId(), userEditRequest.getEmail()); + User user = new User(); BeanUtils.copyBean(user, userEditRequest); user.setUpdateUser(operator); diff --git a/backend/services/system-setting/src/test/java/io/metersphere/system/controller/user/UserControllerTests.java b/backend/services/system-setting/src/test/java/io/metersphere/system/controller/user/UserControllerTests.java index 1ab140e647..8b63b36559 100644 --- a/backend/services/system-setting/src/test/java/io/metersphere/system/controller/user/UserControllerTests.java +++ b/backend/services/system-setting/src/test/java/io/metersphere/system/controller/user/UserControllerTests.java @@ -402,6 +402,7 @@ public class UserControllerTests extends BaseTest { @Test @Order(5) public void testUserUpdateError() throws Exception { + this.checkUserList(); // 4xx 验证 UserCreateInfo user = new UserCreateInfo(); UserEditRequest userMaintainRequest; @@ -432,7 +433,9 @@ public class UserControllerTests extends BaseTest { BeanUtils.copyBean(user, USER_LIST.get(0)); user.setEmail(USER_LIST.get(USER_LIST.size() - 1).getEmail()); userMaintainRequest = UserParamUtils.getUserUpdateDTO(user, USER_ROLE_LIST); - this.requestPost(UserRequestUtils.URL_USER_UPDATE, userMaintainRequest, ERROR_REQUEST_MATCHER); + MvcResult mvcResult = this.requestPost(UserRequestUtils.URL_USER_UPDATE, userMaintainRequest, ERROR_REQUEST_MATCHER).andReturn(); + ResultHolder resultHolder = JSON.parseObject(mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8), ResultHolder.class); + Assertions.assertEquals(resultHolder.getMessage(), "用户邮箱已存在"); //用户组不包含系统成员 BeanUtils.copyBean(user, USER_LIST.get(0)); userMaintainRequest = UserParamUtils.getUserUpdateDTO(user,