From 06ba806ba7d56e95eb11cc1425c38b14fd00964c Mon Sep 17 00:00:00 2001 From: song-tianyang Date: Tue, 5 Dec 2023 16:31:34 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E4=B8=AA=E4=BA=BA=E4=B8=AD=E5=BF=83):=20?= =?UTF-8?q?=E4=B8=AA=E4=BA=BA=E4=BF=A1=E6=81=AF=E4=BB=A5=E5=8F=8A=E5=AF=86?= =?UTF-8?q?=E7=A0=81=E7=9A=84=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../metersphere/system/domain/UserExtend.java | 14 +- .../system/domain/UserExtendExample.java | 140 +++++++++++++ .../system/mapper/UserExtendMapper.xml | 60 +++++- .../3.0.0/ddl/V3.0.0_11__system_setting.sql | 6 +- .../migration/3.0.0/dml/V3.0.0_11_1__data.sql | 5 + .../sdk/constants/PermissionConstants.java | 2 + .../src/main/resources/i18n/system.properties | 9 + .../resources/i18n/system_en_US.properties | 9 + .../resources/i18n/system_zh_CN.properties | 9 + .../resources/i18n/system_zh_TW.properties | 9 + .../service/FileRepositoryService.java | 7 - .../FileRepositoryControllerTest.java | 3 + .../controller/PersonalCenterController.java | 60 ++++++ .../system/controller/UserController.java | 24 +-- .../user/PersonalUpdatePasswordRequest.java | 22 ++ .../request/user/PersonalUpdateRequest.java | 30 +++ .../metersphere/system/dto/user/UserDTO.java | 8 +- .../system/service/UserLogService.java | 61 +++++- .../system/service/UserService.java | 39 ++++ .../src/main/resources/permission.json | 6 + .../user/PersonalControllerTests.java | 197 ++++++++++++++++++ .../controller/user/UserControllerTests.java | 17 +- .../utils/user/PersonalRequestUtils.java | 9 + 23 files changed, 699 insertions(+), 47 deletions(-) create mode 100644 backend/services/system-setting/src/main/java/io/metersphere/system/controller/PersonalCenterController.java create mode 100644 backend/services/system-setting/src/main/java/io/metersphere/system/dto/request/user/PersonalUpdatePasswordRequest.java create mode 100644 backend/services/system-setting/src/main/java/io/metersphere/system/dto/request/user/PersonalUpdateRequest.java create mode 100644 backend/services/system-setting/src/test/java/io/metersphere/system/controller/user/PersonalControllerTests.java create mode 100644 backend/services/system-setting/src/test/java/io/metersphere/system/utils/user/PersonalRequestUtils.java diff --git a/backend/framework/domain/src/main/java/io/metersphere/system/domain/UserExtend.java b/backend/framework/domain/src/main/java/io/metersphere/system/domain/UserExtend.java index 8a5528ab30..d0135984f2 100644 --- a/backend/framework/domain/src/main/java/io/metersphere/system/domain/UserExtend.java +++ b/backend/framework/domain/src/main/java/io/metersphere/system/domain/UserExtend.java @@ -10,15 +10,21 @@ import lombok.Data; @Data public class UserExtend implements Serializable { - @Schema(description = "用户ID", requiredMode = Schema.RequiredMode.REQUIRED) + @Schema(description = "用户ID", requiredMode = Schema.RequiredMode.REQUIRED) @NotBlank(message = "{user_extend.id.not_blank}", groups = {Updated.class}) @Size(min = 1, max = 50, message = "{user_extend.id.length_range}", groups = {Created.class, Updated.class}) private String id; - @Schema(description = "UI本地调试地址") + @Schema(description = "UI本地调试地址") private String seleniumServer; - @Schema(description = "其他平台对接信息") + @Schema(description = "api本地调试地址") + private String apiServer; + + @Schema(description = "头像") + private String avatar; + + @Schema(description = "其他平台对接信息") private byte[] platformInfo; private static final long serialVersionUID = 1L; @@ -26,6 +32,8 @@ public class UserExtend implements Serializable { public enum Column { id("id", "id", "VARCHAR", false), seleniumServer("selenium_server", "seleniumServer", "VARCHAR", false), + apiServer("api_server", "apiServer", "VARCHAR", false), + avatar("avatar", "avatar", "VARCHAR", false), platformInfo("platform_info", "platformInfo", "LONGVARBINARY", false); private static final String BEGINNING_DELIMITER = "`"; diff --git a/backend/framework/domain/src/main/java/io/metersphere/system/domain/UserExtendExample.java b/backend/framework/domain/src/main/java/io/metersphere/system/domain/UserExtendExample.java index c2163a8730..6a140d8389 100644 --- a/backend/framework/domain/src/main/java/io/metersphere/system/domain/UserExtendExample.java +++ b/backend/framework/domain/src/main/java/io/metersphere/system/domain/UserExtendExample.java @@ -243,6 +243,146 @@ public class UserExtendExample { addCriterion("selenium_server not between", value1, value2, "seleniumServer"); return (Criteria) this; } + + public Criteria andApiServerIsNull() { + addCriterion("api_server is null"); + return (Criteria) this; + } + + public Criteria andApiServerIsNotNull() { + addCriterion("api_server is not null"); + return (Criteria) this; + } + + public Criteria andApiServerEqualTo(String value) { + addCriterion("api_server =", value, "apiServer"); + return (Criteria) this; + } + + public Criteria andApiServerNotEqualTo(String value) { + addCriterion("api_server <>", value, "apiServer"); + return (Criteria) this; + } + + public Criteria andApiServerGreaterThan(String value) { + addCriterion("api_server >", value, "apiServer"); + return (Criteria) this; + } + + public Criteria andApiServerGreaterThanOrEqualTo(String value) { + addCriterion("api_server >=", value, "apiServer"); + return (Criteria) this; + } + + public Criteria andApiServerLessThan(String value) { + addCriterion("api_server <", value, "apiServer"); + return (Criteria) this; + } + + public Criteria andApiServerLessThanOrEqualTo(String value) { + addCriterion("api_server <=", value, "apiServer"); + return (Criteria) this; + } + + public Criteria andApiServerLike(String value) { + addCriterion("api_server like", value, "apiServer"); + return (Criteria) this; + } + + public Criteria andApiServerNotLike(String value) { + addCriterion("api_server not like", value, "apiServer"); + return (Criteria) this; + } + + public Criteria andApiServerIn(List values) { + addCriterion("api_server in", values, "apiServer"); + return (Criteria) this; + } + + public Criteria andApiServerNotIn(List values) { + addCriterion("api_server not in", values, "apiServer"); + return (Criteria) this; + } + + public Criteria andApiServerBetween(String value1, String value2) { + addCriterion("api_server between", value1, value2, "apiServer"); + return (Criteria) this; + } + + public Criteria andApiServerNotBetween(String value1, String value2) { + addCriterion("api_server not between", value1, value2, "apiServer"); + return (Criteria) this; + } + + public Criteria andAvatarIsNull() { + addCriterion("avatar is null"); + return (Criteria) this; + } + + public Criteria andAvatarIsNotNull() { + addCriterion("avatar is not null"); + return (Criteria) this; + } + + public Criteria andAvatarEqualTo(String value) { + addCriterion("avatar =", value, "avatar"); + return (Criteria) this; + } + + public Criteria andAvatarNotEqualTo(String value) { + addCriterion("avatar <>", value, "avatar"); + return (Criteria) this; + } + + public Criteria andAvatarGreaterThan(String value) { + addCriterion("avatar >", value, "avatar"); + return (Criteria) this; + } + + public Criteria andAvatarGreaterThanOrEqualTo(String value) { + addCriterion("avatar >=", value, "avatar"); + return (Criteria) this; + } + + public Criteria andAvatarLessThan(String value) { + addCriterion("avatar <", value, "avatar"); + return (Criteria) this; + } + + public Criteria andAvatarLessThanOrEqualTo(String value) { + addCriterion("avatar <=", value, "avatar"); + return (Criteria) this; + } + + public Criteria andAvatarLike(String value) { + addCriterion("avatar like", value, "avatar"); + return (Criteria) this; + } + + public Criteria andAvatarNotLike(String value) { + addCriterion("avatar not like", value, "avatar"); + return (Criteria) this; + } + + public Criteria andAvatarIn(List values) { + addCriterion("avatar in", values, "avatar"); + return (Criteria) this; + } + + public Criteria andAvatarNotIn(List values) { + addCriterion("avatar not in", values, "avatar"); + return (Criteria) this; + } + + public Criteria andAvatarBetween(String value1, String value2) { + addCriterion("avatar between", value1, value2, "avatar"); + return (Criteria) this; + } + + public Criteria andAvatarNotBetween(String value1, String value2) { + addCriterion("avatar not between", value1, value2, "avatar"); + return (Criteria) this; + } } public static class Criteria extends GeneratedCriteria { diff --git a/backend/framework/domain/src/main/java/io/metersphere/system/mapper/UserExtendMapper.xml b/backend/framework/domain/src/main/java/io/metersphere/system/mapper/UserExtendMapper.xml index b46349743b..979c191a0b 100644 --- a/backend/framework/domain/src/main/java/io/metersphere/system/mapper/UserExtendMapper.xml +++ b/backend/framework/domain/src/main/java/io/metersphere/system/mapper/UserExtendMapper.xml @@ -4,6 +4,8 @@ + + @@ -67,7 +69,7 @@ - id, selenium_server + id, selenium_server, api_server, avatar platform_info @@ -121,10 +123,10 @@ - insert into user_extend (id, selenium_server, platform_info - ) - values (#{id,jdbcType=VARCHAR}, #{seleniumServer,jdbcType=VARCHAR}, #{platformInfo,jdbcType=LONGVARBINARY} - ) + insert into user_extend (id, selenium_server, api_server, + avatar, platform_info) + values (#{id,jdbcType=VARCHAR}, #{seleniumServer,jdbcType=VARCHAR}, #{apiServer,jdbcType=VARCHAR}, + #{avatar,jdbcType=VARCHAR}, #{platformInfo,jdbcType=LONGVARBINARY}) insert into user_extend @@ -135,6 +137,12 @@ selenium_server, + + api_server, + + + avatar, + platform_info, @@ -146,6 +154,12 @@ #{seleniumServer,jdbcType=VARCHAR}, + + #{apiServer,jdbcType=VARCHAR}, + + + #{avatar,jdbcType=VARCHAR}, + #{platformInfo,jdbcType=LONGVARBINARY}, @@ -166,6 +180,12 @@ selenium_server = #{record.seleniumServer,jdbcType=VARCHAR}, + + api_server = #{record.apiServer,jdbcType=VARCHAR}, + + + avatar = #{record.avatar,jdbcType=VARCHAR}, + platform_info = #{record.platformInfo,jdbcType=LONGVARBINARY}, @@ -178,6 +198,8 @@ update user_extend set id = #{record.id,jdbcType=VARCHAR}, selenium_server = #{record.seleniumServer,jdbcType=VARCHAR}, + api_server = #{record.apiServer,jdbcType=VARCHAR}, + avatar = #{record.avatar,jdbcType=VARCHAR}, platform_info = #{record.platformInfo,jdbcType=LONGVARBINARY} @@ -186,7 +208,9 @@ update user_extend set id = #{record.id,jdbcType=VARCHAR}, - selenium_server = #{record.seleniumServer,jdbcType=VARCHAR} + selenium_server = #{record.seleniumServer,jdbcType=VARCHAR}, + api_server = #{record.apiServer,jdbcType=VARCHAR}, + avatar = #{record.avatar,jdbcType=VARCHAR} @@ -197,6 +221,12 @@ selenium_server = #{seleniumServer,jdbcType=VARCHAR}, + + api_server = #{apiServer,jdbcType=VARCHAR}, + + + avatar = #{avatar,jdbcType=VARCHAR}, + platform_info = #{platformInfo,jdbcType=LONGVARBINARY}, @@ -206,21 +236,25 @@ update user_extend set selenium_server = #{seleniumServer,jdbcType=VARCHAR}, + api_server = #{apiServer,jdbcType=VARCHAR}, + avatar = #{avatar,jdbcType=VARCHAR}, platform_info = #{platformInfo,jdbcType=LONGVARBINARY} where id = #{id,jdbcType=VARCHAR} update user_extend - set selenium_server = #{seleniumServer,jdbcType=VARCHAR} + set selenium_server = #{seleniumServer,jdbcType=VARCHAR}, + api_server = #{apiServer,jdbcType=VARCHAR}, + avatar = #{avatar,jdbcType=VARCHAR} where id = #{id,jdbcType=VARCHAR} insert into user_extend - (id, selenium_server, platform_info) + (id, selenium_server, api_server, avatar, platform_info) values - (#{item.id,jdbcType=VARCHAR}, #{item.seleniumServer,jdbcType=VARCHAR}, #{item.platformInfo,jdbcType=LONGVARBINARY} - ) + (#{item.id,jdbcType=VARCHAR}, #{item.seleniumServer,jdbcType=VARCHAR}, #{item.apiServer,jdbcType=VARCHAR}, + #{item.avatar,jdbcType=VARCHAR}, #{item.platformInfo,jdbcType=LONGVARBINARY}) @@ -239,6 +273,12 @@ #{item.seleniumServer,jdbcType=VARCHAR} + + #{item.apiServer,jdbcType=VARCHAR} + + + #{item.avatar,jdbcType=VARCHAR} + #{item.platformInfo,jdbcType=LONGVARBINARY} diff --git a/backend/framework/domain/src/main/resources/migration/3.0.0/ddl/V3.0.0_11__system_setting.sql b/backend/framework/domain/src/main/resources/migration/3.0.0/ddl/V3.0.0_11__system_setting.sql index 1ba063839b..e542f7208a 100644 --- a/backend/framework/domain/src/main/resources/migration/3.0.0/ddl/V3.0.0_11__system_setting.sql +++ b/backend/framework/domain/src/main/resources/migration/3.0.0/ddl/V3.0.0_11__system_setting.sql @@ -318,17 +318,21 @@ CREATE INDEX idx_update_time ON organization (`update_time` desc); CREATE INDEX idx_deleted ON organization (`deleted`); CREATE INDEX idx_update_user ON organization(`update_user`); -CREATE TABLE IF NOT EXISTS user_extend +DROP TABLE IF EXISTS user_extend; +CREATE TABLE user_extend ( `id` VARCHAR(50) NOT NULL COMMENT '用户ID', `platform_info` BLOB COMMENT '其他平台对接信息', `selenium_server` VARCHAR(255) COMMENT 'UI本地调试地址', + `api_server` VARCHAR(255) COMMENT 'api本地调试地址', + `avatar` VARCHAR(255) COMMENT '头像', PRIMARY KEY (id) ) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '用户扩展'; + CREATE TABLE IF NOT EXISTS test_resource_pool_organization ( `id` VARCHAR(50) NOT NULL COMMENT '测试资源池项目关系ID', diff --git a/backend/framework/domain/src/main/resources/migration/3.0.0/dml/V3.0.0_11_1__data.sql b/backend/framework/domain/src/main/resources/migration/3.0.0/dml/V3.0.0_11_1__data.sql index 15a23f3d62..bd1d531a95 100644 --- a/backend/framework/domain/src/main/resources/migration/3.0.0/dml/V3.0.0_11_1__data.sql +++ b/backend/framework/domain/src/main/resources/migration/3.0.0/dml/V3.0.0_11_1__data.sql @@ -39,6 +39,11 @@ INSERT INTO user_role_permission (id, role_id, permission_id) VALUES (UUID_SHORT INSERT INTO user_role_permission (id, role_id, permission_id) VALUES (UUID_SHORT(), 'member', 'SYSTEM_PERSONAL_API_KEY_ADD:READ+UPDATE'); INSERT INTO user_role_permission (id, role_id, permission_id) VALUES (UUID_SHORT(), 'member', 'SYSTEM_PERSONAL_API_KEY_ADD:READ+DELETE'); INSERT INTO user_role_permission (id, role_id, permission_id) VALUES (UUID_SHORT(), 'member', 'SYSTEM_PERSONAL_API_KEY_ADD:READ'); +INSERT INTO user_role_permission (id, role_id, permission_id) +VALUES (UUID_SHORT(), 'member', 'SYSTEM_PERSONAL:READ'); +INSERT INTO user_role_permission (id, role_id, permission_id) +VALUES (UUID_SHORT(), 'member', 'SYSTEM_PERSONAL:READ+UPDATE'); + -- 组织管理员权限 INSERT INTO user_role_permission (id, role_id, permission_id) VALUES (UUID_SHORT(), 'org_admin', 'ORGANIZATION_USER_ROLE:READ'); INSERT INTO user_role_permission (id, role_id, permission_id) VALUES (UUID_SHORT(), 'org_admin', 'ORGANIZATION_USER_ROLE:READ+ADD'); diff --git a/backend/framework/sdk/src/main/java/io/metersphere/sdk/constants/PermissionConstants.java b/backend/framework/sdk/src/main/java/io/metersphere/sdk/constants/PermissionConstants.java index e3e5e29ebe..feec4c0068 100644 --- a/backend/framework/sdk/src/main/java/io/metersphere/sdk/constants/PermissionConstants.java +++ b/backend/framework/sdk/src/main/java/io/metersphere/sdk/constants/PermissionConstants.java @@ -267,4 +267,6 @@ public class PermissionConstants { public static final String SYSTEM_PERSONAL_API_KEY_DELETE = "SYSTEM_PERSONAL_API_KEY_DELETE:READ+DELETE"; public static final String SYSTEM_PERSONAL_API_KEY_READ = "SYSTEM_PERSONAL_API_KEY_READ:READ"; public static final String SYSTEM_PERSONAL_API_KEY_UPDATE = "SYSTEM_PERSONAL_API_KEY_UPDATE:READ+UPDATE"; + public static final String SYSTEM_PERSONAL_READ = "SYSTEM_PERSONAL:READ"; + public static final String SYSTEM_PERSONAL_READ_UPDATE = "SYSTEM_PERSONAL:READ+UPDATE"; } diff --git a/backend/framework/sdk/src/main/resources/i18n/system.properties b/backend/framework/sdk/src/main/resources/i18n/system.properties index 0d56c0a7f3..a4e9688107 100644 --- a/backend/framework/sdk/src/main/resources/i18n/system.properties +++ b/backend/framework/sdk/src/main/resources/i18n/system.properties @@ -5,6 +5,12 @@ role.not.contains.member=角色不包含系统成员角色 user.not.login=未获取到登录用户 user.not.empty=用户不呢为空 user.not.exist=用户不存在 +personal.no.permission=无权操作非本人账户 +personal.change.password=修改了密码 +personal.change.info=修改了信息 +personal.user.name=用户名称 +personal.user.phone=手机号 +personal.user.email=用户邮箱 auth_source.id.not_blank=认证源ID不能为空 auth_source.status.length_range=认证源状态长度必须在{min}和{max}之间 auth_source.status.not_blank=认证源状态不能为空 @@ -91,6 +97,9 @@ user.not.disable=用户不能禁用 user.id.not_blank=用户ID不能为空 user.name.not_blank=用户名称不能为空 user.name.length_range=用户名称长度必须在{min}和{max}之间 +user.phone.not_blank=用户手机号不能为空 +user.password.error=验证用户密码失败 +user.password.not.blank=用户密码不能为空 user.email.not_blank=用户email不能为空 user.email.length_range=用户email长度必须在{min}和{max}之间 user.email.hi=你好 diff --git a/backend/framework/sdk/src/main/resources/i18n/system_en_US.properties b/backend/framework/sdk/src/main/resources/i18n/system_en_US.properties index 9492544a24..204daa759e 100644 --- a/backend/framework/sdk/src/main/resources/i18n/system_en_US.properties +++ b/backend/framework/sdk/src/main/resources/i18n/system_en_US.properties @@ -4,6 +4,12 @@ role.not.global.system=Role is not global system role role.not.contains.member=Role not contains member user.not.login=User not login user.not.exist=User not exist +personal.no.permission=No permission +personal.change.password=Changed password +personal.change.info=Changed information +personal.user.name=Name +personal.user.phone=Phone +personal.user.email=Email default.module=Default module user.not.empty=User can not empty auth_source.id.not_blank=Auth source id must not be blank @@ -91,6 +97,9 @@ user.not.disable=User can't disable user.id.not_blank=User id must not be blank user.name.not_blank=Username must not be blank user.name.length_range=Username must be between {min} and {max} characters long +user.phone.not_blank=User phone must not be blank +user.password.error=Validate password error +user.password.not.blank=User password must not be blank user.email.not_blank=User email must not be blank user.email.length_range=User email must be between {min} and {max} characters long user.email.hi=Hi diff --git a/backend/framework/sdk/src/main/resources/i18n/system_zh_CN.properties b/backend/framework/sdk/src/main/resources/i18n/system_zh_CN.properties index fc1176a902..7a856c1ac8 100644 --- a/backend/framework/sdk/src/main/resources/i18n/system_zh_CN.properties +++ b/backend/framework/sdk/src/main/resources/i18n/system_zh_CN.properties @@ -5,6 +5,12 @@ role.not.contains.member=角色不包含系统成员角色 user.not.login=未获取到登录用户 user.not.empty=用户不呢为空 user.not.exist=用户不存在 +personal.no.permission=无权操作非本人账户 +personal.change.password=修改了密码 +personal.change.info=修改了信息 +personal.user.name=用户名称 +personal.user.phone=手机号 +personal.user.email=用户邮箱 default.module=默认模块 auth_source.id.not_blank=认证源ID不能为空 auth_source.status.length_range=认证源状态长度必须在{min}和{max}之间 @@ -92,6 +98,9 @@ user.not.disable=用户不能禁用 user.id.not_blank=用户ID不能为空 user.name.not_blank=用户名称不能为空 user.name.length_range=用户名称长度必须在{min}和{max}之间 +user.phone.not_blank=用户手机号不能为空 +user.password.error=验证用户密码失败 +user.password.not.blank=用户密码不能为空 user.email.not_blank=用户email不能为空 user.email.length_range=用户email长度必须在{min}和{max}之间 user.email.hi=你好 diff --git a/backend/framework/sdk/src/main/resources/i18n/system_zh_TW.properties b/backend/framework/sdk/src/main/resources/i18n/system_zh_TW.properties index d12b749696..0aca9a614f 100644 --- a/backend/framework/sdk/src/main/resources/i18n/system_zh_TW.properties +++ b/backend/framework/sdk/src/main/resources/i18n/system_zh_TW.properties @@ -5,6 +5,12 @@ role.not.contains.member=角色不包含系統成員角色 user.not.login=未獲取到登錄用戶 user.not.empty=用戶不呢為空 user.not.exist=用戶不存在 +personal.no.permission=無權操作非本人賬戶 +personal.change.password=修改了密碼 +personal.change.info=修改了信息 +personal.user.name=用戶名稱 +personal.user.phone=手機號 +personal.user.email=用戶郵箱 default.module=默認模塊 auth_source.id.not_blank=認證源ID不能為空 auth_source.status.length_range=認證源狀態長度必須在{min}和{max}之間 @@ -91,6 +97,9 @@ user.not.disable=用戶不能禁用 user.id.not_blank=用戶ID不能為空 user.name.not_blank=用戶名稱不能為空 user.name.length_range=用戶名稱長度必須在{min}和{max}之間 +user.phone.not_blank=用戶手機號不能為空 +user.password.error=驗證用戶密碼失敗 +user.password.not.blank=用戶密碼不能為空 user.email.not_blank=用戶email不能為空 user.email.length_range=用戶email長度必須在{min}和{max}之間 user.email.hi=你好 diff --git a/backend/services/project-management/src/main/java/io/metersphere/project/service/FileRepositoryService.java b/backend/services/project-management/src/main/java/io/metersphere/project/service/FileRepositoryService.java index 207954699c..8c5f07b403 100644 --- a/backend/services/project-management/src/main/java/io/metersphere/project/service/FileRepositoryService.java +++ b/backend/services/project-management/src/main/java/io/metersphere/project/service/FileRepositoryService.java @@ -51,7 +51,6 @@ public class FileRepositoryService extends FileModuleService { public String addRepository(FileRepositoryCreateRequest request, String operator) { this.connect(request.getUrl(), request.getToken(), request.getUserName()); - this.checkPlatForm(request.getPlatform()); //记录模块节点数据 FileModule fileModule = new FileModule(); fileModule.setId(IDGenerator.nextStr()); @@ -126,12 +125,6 @@ public class FileRepositoryService extends FileModuleService { fileModuleLogService.saveUpdateRepositoryLog(oldLog, new FileRepositoryLog(fileModule, repository), operator); } - private void checkPlatForm(String platform) { - if (!StringUtils.equalsAny(platform, ModuleConstants.NODE_TYPE_GITHUB, ModuleConstants.NODE_TYPE_GITEE, ModuleConstants.NODE_TYPE_GITLAB)) { - throw new MSException(Translator.get("file_repository.platform.error")); - } - } - public String addFile(RepositoryFileAddRequest request, String operator) { FileModule fileModule = fileModuleMapper.selectByPrimaryKey(request.getModuleId()); FileModuleRepository repository = fileModuleRepositoryMapper.selectByPrimaryKey(request.getModuleId()); diff --git a/backend/services/project-management/src/test/java/io/metersphere/project/controller/filemanagement/FileRepositoryControllerTest.java b/backend/services/project-management/src/test/java/io/metersphere/project/controller/filemanagement/FileRepositoryControllerTest.java index cde0b576ae..1730eb45e1 100644 --- a/backend/services/project-management/src/test/java/io/metersphere/project/controller/filemanagement/FileRepositoryControllerTest.java +++ b/backend/services/project-management/src/test/java/io/metersphere/project/controller/filemanagement/FileRepositoryControllerTest.java @@ -51,6 +51,9 @@ public class FileRepositoryControllerTest extends BaseTest { private static final String GITEE_USERNAME = "testformetersphere"; private static final String GITEE_TOKEN = "4548d369bb595738d726512742e4478f"; + private static final String GITEA_USERNAME = "meterspherecodetest"; + private static final String GITEA_TOKEN = "f5e34c45e998291909e0897a76a1f1ae42095e3f"; + private static final List fileList = new ArrayList<>(); private static String repositoryId; diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/controller/PersonalCenterController.java b/backend/services/system-setting/src/main/java/io/metersphere/system/controller/PersonalCenterController.java new file mode 100644 index 0000000000..89eecde11b --- /dev/null +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/controller/PersonalCenterController.java @@ -0,0 +1,60 @@ +package io.metersphere.system.controller; + +import io.metersphere.sdk.constants.PermissionConstants; +import io.metersphere.sdk.exception.MSException; +import io.metersphere.system.dto.request.user.PersonalUpdatePasswordRequest; +import io.metersphere.system.dto.request.user.PersonalUpdateRequest; +import io.metersphere.system.dto.user.UserDTO; +import io.metersphere.system.log.annotation.Log; +import io.metersphere.system.log.constants.OperationLogType; +import io.metersphere.system.service.UserLogService; +import io.metersphere.system.service.UserService; +import io.metersphere.system.utils.SessionUtils; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.tags.Tag; +import jakarta.annotation.Resource; +import org.apache.commons.lang3.StringUtils; +import org.apache.shiro.authz.annotation.RequiresPermissions; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; + +@RestController +@Tag(name = "个人中心") +@RequestMapping("/personal") +public class PersonalCenterController { + + @Resource + private UserService userService; + + @GetMapping("/get/{id}") + @Operation(summary = "个人中心-获取信息") + @RequiresPermissions(PermissionConstants.SYSTEM_PERSONAL_READ) + public UserDTO getInformation(@PathVariable String id) { + this.checkPermission(id); + return userService.getUserDTOByKeyword(id); + } + + @PostMapping("/update-info") + @Operation(summary = "个人中心-修改信息") + @RequiresPermissions(PermissionConstants.SYSTEM_PERSONAL_READ_UPDATE) + @Log(type = OperationLogType.UPDATE, expression = "#msClass.updateAccountLog(#request)", msClass = UserLogService.class) + public boolean updateUser(@Validated @RequestBody PersonalUpdateRequest request) { + this.checkPermission(request.getId()); + return userService.updateAccount(request, SessionUtils.getUserId()); + } + + @PostMapping("/update-password") + @Operation(summary = "个人中心-修改密码") + @RequiresPermissions(PermissionConstants.SYSTEM_PERSONAL_READ_UPDATE) + @Log(type = OperationLogType.UPDATE, expression = "#msClass.updatePasswordLog(#request)", msClass = UserLogService.class) + public boolean updateUser(@Validated @RequestBody PersonalUpdatePasswordRequest request) { + this.checkPermission(request.getId()); + return userService.updatePassword(request); + } + + private void checkPermission(String id) { + if (!StringUtils.equals(id, SessionUtils.getUserId())) { + throw new MSException("personal.no.permission"); + } + } +} diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/controller/UserController.java b/backend/services/system-setting/src/main/java/io/metersphere/system/controller/UserController.java index 01ca146a17..47b12f4086 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/controller/UserController.java +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/controller/UserController.java @@ -6,13 +6,19 @@ import com.github.pagehelper.PageHelper; import io.metersphere.project.domain.Project; import io.metersphere.sdk.constants.PermissionConstants; import io.metersphere.sdk.constants.UserSource; -import io.metersphere.system.utils.PageUtils; -import io.metersphere.system.utils.Pager; 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.ProjectAddMemberBatchRequest; import io.metersphere.system.dto.request.UserInviteRequest; import io.metersphere.system.dto.request.UserRegisterRequest; +import io.metersphere.system.dto.request.user.UserChangeEnableRequest; +import io.metersphere.system.dto.request.user.UserEditRequest; +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.BaseTreeNode; import io.metersphere.system.dto.sdk.OptionDTO; @@ -21,15 +27,9 @@ import io.metersphere.system.dto.table.TableBatchProcessResponse; import io.metersphere.system.dto.user.UserDTO; import io.metersphere.system.log.annotation.Log; import io.metersphere.system.log.constants.OperationLogType; -import io.metersphere.system.dto.request.OrganizationMemberBatchRequest; -import io.metersphere.system.dto.request.ProjectAddMemberBatchRequest; -import io.metersphere.system.dto.request.user.UserChangeEnableRequest; -import io.metersphere.system.dto.request.user.UserEditRequest; -import io.metersphere.system.dto.request.user.UserRoleBatchRelationRequest; -import io.metersphere.system.dto.response.UserImportResponse; -import io.metersphere.system.dto.response.UserSelectOption; -import io.metersphere.system.dto.response.UserTableResponse; import io.metersphere.system.service.*; +import io.metersphere.system.utils.PageUtils; +import io.metersphere.system.utils.Pager; import io.metersphere.system.utils.SessionUtils; import io.metersphere.system.utils.TreeNodeParseUtils; import io.metersphere.validation.groups.Created; @@ -186,14 +186,14 @@ public class UserController { } @PostMapping("/invite") - @Operation(summary = "系统设置-系统-用户-用户邀请") + @Operation(summary = "系统设置-系统-用户-邀请用户注册") @RequiresPermissions(PermissionConstants.SYSTEM_USER_ADD) public UserInviteResponse invite(@Validated @RequestBody UserInviteRequest request) { return userService.saveInviteRecord(request, SessionUtils.getUser()); } @PostMapping("/register-by-invite") - @Operation(summary = "系统设置-系统-用户-用户邀请") + @Operation(summary = "系统设置-系统-用户-用户接受注册邀请并创建账户") public String registerByInvite(@Validated @RequestBody UserRegisterRequest request) throws Exception { return userService.registerByInvite(request); } diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/dto/request/user/PersonalUpdatePasswordRequest.java b/backend/services/system-setting/src/main/java/io/metersphere/system/dto/request/user/PersonalUpdatePasswordRequest.java new file mode 100644 index 0000000000..dddf59bddd --- /dev/null +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/dto/request/user/PersonalUpdatePasswordRequest.java @@ -0,0 +1,22 @@ +package io.metersphere.system.dto.request.user; + +import io.swagger.v3.oas.annotations.media.Schema; +import jakarta.validation.constraints.NotBlank; +import lombok.Data; + +@Data +public class PersonalUpdatePasswordRequest { + + @Schema(description = "用户ID", requiredMode = Schema.RequiredMode.REQUIRED) + @NotBlank(message = "{user.id.not_blank}") + private String id; + + @Schema(description = "旧密码", requiredMode = Schema.RequiredMode.REQUIRED) + @NotBlank(message = "{user.password.not.blank}") + private String oldPassword; + + @Schema(description = "新密码", requiredMode = Schema.RequiredMode.REQUIRED) + @NotBlank(message = "{user.password.not.blank}") + private String newPassword; + +} diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/dto/request/user/PersonalUpdateRequest.java b/backend/services/system-setting/src/main/java/io/metersphere/system/dto/request/user/PersonalUpdateRequest.java new file mode 100644 index 0000000000..04c6a18293 --- /dev/null +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/dto/request/user/PersonalUpdateRequest.java @@ -0,0 +1,30 @@ +package io.metersphere.system.dto.request.user; + +import io.swagger.v3.oas.annotations.media.Schema; +import jakarta.validation.constraints.Email; +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.Size; +import lombok.Data; + +@Data +public class PersonalUpdateRequest { + + @Schema(description = "用户ID", requiredMode = Schema.RequiredMode.REQUIRED) + @NotBlank(message = "{user.id.not_blank}") + private String id; + + @Schema(description = "用户名", requiredMode = Schema.RequiredMode.REQUIRED) + @NotBlank(message = "{user.id.not_blank}") + private String username; + + @Schema(description = "手机号", requiredMode = Schema.RequiredMode.REQUIRED) + @NotBlank(message = "{user.email.not_blank}") + private String phone; + + @Schema(description = "邮箱", requiredMode = Schema.RequiredMode.REQUIRED) + @NotBlank(message = "{user.phone.not_blank}") + @Size(min = 1, max = 64, message = "{user.email.length_range}") + @Email(message = "{user.email.invalid}") + private String email; + +} diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/dto/user/UserDTO.java b/backend/services/system-setting/src/main/java/io/metersphere/system/dto/user/UserDTO.java index f0982d86c9..cc1f84613f 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/dto/user/UserDTO.java +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/dto/user/UserDTO.java @@ -21,6 +21,12 @@ public class UserDTO extends User { @Schema(description = "其他平台对接信息", requiredMode = Schema.RequiredMode.NOT_REQUIRED) private byte[] platformInfo; - @Schema(description = "UI本地调试地址", requiredMode = Schema.RequiredMode.NOT_REQUIRED) + @Schema(description = "UI本地调试地址") private String seleniumServer; + + @Schema(description = "API本地调试地址") + private String apiServer; + + @Schema(description = "头像") + private String avatar; } diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/service/UserLogService.java b/backend/services/system-setting/src/main/java/io/metersphere/system/service/UserLogService.java index 3a2fa11b2b..4dfa3e20c2 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/service/UserLogService.java +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/service/UserLogService.java @@ -5,21 +5,19 @@ import io.metersphere.project.domain.ProjectExample; import io.metersphere.project.mapper.ProjectMapper; import io.metersphere.sdk.constants.HttpMethodConstants; import io.metersphere.sdk.constants.OperationLogConstants; -import io.metersphere.system.log.dto.LogDTO; -import io.metersphere.system.dto.table.TableBatchProcessDTO; -import io.metersphere.system.dto.builder.LogDTOBuilder; import io.metersphere.sdk.util.JSON; import io.metersphere.sdk.util.Translator; import io.metersphere.system.domain.*; +import io.metersphere.system.dto.builder.LogDTOBuilder; +import io.metersphere.system.dto.request.user.*; +import io.metersphere.system.dto.table.TableBatchProcessDTO; import io.metersphere.system.log.constants.OperationLogModule; import io.metersphere.system.log.constants.OperationLogType; +import io.metersphere.system.log.dto.LogDTO; import io.metersphere.system.log.service.OperationLogService; import io.metersphere.system.mapper.OrganizationMapper; import io.metersphere.system.mapper.UserMapper; import io.metersphere.system.mapper.UserRoleMapper; -import io.metersphere.system.dto.request.user.UserChangeEnableRequest; -import io.metersphere.system.dto.request.user.UserEditRequest; -import io.metersphere.system.dto.request.user.UserRoleBatchRelationRequest; import jakarta.annotation.Resource; import jakarta.validation.Valid; import org.apache.commons.lang3.StringUtils; @@ -86,6 +84,57 @@ public class UserLogService { return null; } + public LogDTO updatePasswordLog(PersonalUpdatePasswordRequest request) { + User user = userMapper.selectByPrimaryKey(request.getId()); + if (user != null) { + LogDTO dto = LogDTOBuilder.builder() + .projectId(OperationLogConstants.SYSTEM) + .organizationId(OperationLogConstants.SYSTEM) + .type(OperationLogType.UPDATE.name()) + .module(OperationLogModule.PERSONAL_INFORMATION_PERSONAL_SETTINGS) + .method(HttpMethodConstants.POST.name()) + .path("/personal/update-password") + .sourceId(request.getId()) + .content(user.getName() + StringUtils.SPACE + Translator.get("personal.change.password")) + .originalValue(JSON.toJSONBytes(user)) + .build().getLogDTO(); + return dto; + } + return null; + } + + public LogDTO updateAccountLog(PersonalUpdateRequest request) { + User user = userMapper.selectByPrimaryKey(request.getId()); + StringBuilder content = new StringBuilder(); + if (user != null) { + if (!StringUtils.equals(user.getName(), request.getUsername())) { + content.append(Translator.get("personal.user.name")).append(":").append(user.getName()).append("->").append(request.getUsername()).append(";"); + } + if (!StringUtils.equals(user.getEmail(), request.getEmail())) { + content.append(Translator.get("personal.user.email")).append(":").append(user.getEmail()).append("->").append(request.getEmail()).append(";"); + } + if (!StringUtils.equals(user.getPhone(), request.getPhone())) { + content.append(Translator.get("personal.user.phone")).append(":").append(user.getPhone()).append("->").append(request.getPhone()).append(";"); + } + + + LogDTO dto = LogDTOBuilder.builder() + .projectId(OperationLogConstants.SYSTEM) + .organizationId(OperationLogConstants.SYSTEM) + .type(OperationLogType.UPDATE.name()) + .module(OperationLogModule.PERSONAL_INFORMATION_PERSONAL_SETTINGS) + .method(HttpMethodConstants.POST.name()) + .path("/personal/update-info") + .sourceId(request.getId()) + .content(user.getName() + StringUtils.SPACE + Translator.get("personal.change.info") + ". " + content) + .originalValue(JSON.toJSONBytes(user)) + .build().getLogDTO(); + return dto; + } + return null; + } + + //批量开启和关闭 public List batchUpdateEnableLog(UserChangeEnableRequest request) { List logDTOList = new ArrayList<>(); 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 20f1b0f7ce..61551c7e86 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 @@ -12,6 +12,8 @@ import io.metersphere.system.dto.excel.UserExcel; import io.metersphere.system.dto.excel.UserExcelRowDTO; import io.metersphere.system.dto.request.UserInviteRequest; import io.metersphere.system.dto.request.UserRegisterRequest; +import io.metersphere.system.dto.request.user.PersonalUpdatePasswordRequest; +import io.metersphere.system.dto.request.user.PersonalUpdateRequest; import io.metersphere.system.dto.request.user.UserChangeEnableRequest; import io.metersphere.system.dto.request.user.UserEditRequest; import io.metersphere.system.dto.response.UserImportResponse; @@ -172,6 +174,23 @@ public class UserService { return returnList; } + private void checkUserEmail(String id, String email) { + UserExample userExample = new UserExample(); + userExample.createCriteria().andEmailEqualTo(email).andIdNotEqualTo(id); + if (userMapper.countByExample(userExample) > 0) { + throw new MSException(Translator.get("user_email_already_exists")); + } + } + + private void checkOldPassword(String id, String password) { + UserExample userExample = new UserExample(); + userExample.createCriteria().andPasswordEqualTo(password).andIdEqualTo(id); + if (userMapper.countByExample(userExample) != 1) { + throw new MSException(Translator.get("password_modification_failed")); + } + } + + public UserEditRequest updateUser(UserEditRequest userEditRequest, String operator) { //检查用户组合法性 globalUserRoleService.checkRoleIsGlobalAndHaveMember(userEditRequest.getUserRoleIdList(), true); @@ -495,4 +514,24 @@ public class UserService { userLogService.addRegisterLog(user, userInvite); return user.getId(); } + + public boolean updateAccount(PersonalUpdateRequest request, String operator) { + this.checkUserEmail(request.getId(), request.getEmail()); + User editUser = new User(); + editUser.setId(request.getId()); + editUser.setName(request.getUsername()); + editUser.setPhone(request.getPhone()); + editUser.setEmail(request.getEmail()); + editUser.setUpdateUser(operator); + editUser.setUpdateTime(System.currentTimeMillis()); + return userMapper.updateByPrimaryKeySelective(editUser) > 0; + } + + public boolean updatePassword(PersonalUpdatePasswordRequest request) { + this.checkOldPassword(request.getId(), request.getOldPassword()); + User editUser = new User(); + editUser.setId(request.getId()); + editUser.setPassword(request.getNewPassword()); + return userMapper.updateByPrimaryKeySelective(editUser) > 0; + } } diff --git a/backend/services/system-setting/src/main/resources/permission.json b/backend/services/system-setting/src/main/resources/permission.json index 222b80708f..8cbd72e74a 100644 --- a/backend/services/system-setting/src/main/resources/permission.json +++ b/backend/services/system-setting/src/main/resources/permission.json @@ -300,6 +300,12 @@ "id": "API_KEYS", "name": "permission.api_keys", "permissions": [ + { + "id": "SYSTEM_PERSONAL:READ" + }, + { + "id": "SYSTEM_PERSONAL:READ+UPDATE" + }, { "id": "SYSTEM_PERSONAL_API_KEY_ADD:READ+ADD" }, diff --git a/backend/services/system-setting/src/test/java/io/metersphere/system/controller/user/PersonalControllerTests.java b/backend/services/system-setting/src/test/java/io/metersphere/system/controller/user/PersonalControllerTests.java new file mode 100644 index 0000000000..62fc007857 --- /dev/null +++ b/backend/services/system-setting/src/test/java/io/metersphere/system/controller/user/PersonalControllerTests.java @@ -0,0 +1,197 @@ +package io.metersphere.system.controller.user; + +import io.metersphere.sdk.constants.PermissionConstants; +import io.metersphere.sdk.util.CodingUtils; +import io.metersphere.sdk.util.JSON; +import io.metersphere.system.base.BaseTest; +import io.metersphere.system.controller.handler.ResultHolder; +import io.metersphere.system.domain.UserExample; +import io.metersphere.system.dto.request.user.PersonalUpdatePasswordRequest; +import io.metersphere.system.dto.request.user.PersonalUpdateRequest; +import io.metersphere.system.dto.user.UserDTO; +import io.metersphere.system.mapper.UserMapper; +import io.metersphere.system.uid.IDGenerator; +import io.metersphere.system.utils.user.PersonalRequestUtils; +import jakarta.annotation.Resource; +import org.junit.jupiter.api.*; +import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.web.servlet.MvcResult; + +import java.nio.charset.StandardCharsets; + +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) +@AutoConfigureMockMvc +@TestMethodOrder(MethodOrderer.OrderAnnotation.class) +public class PersonalControllerTests extends BaseTest { + private static String loginUser = "admin"; + + @Resource + private UserMapper userMapper; + + @Test + @Order(0) + void testPersonalGetId() throws Exception { + //查询自己的 + this.requestGetWithOk(String.format(PersonalRequestUtils.URL_PERSONAL_GET, loginUser)); + //查询非登录人 + this.requestGet(String.format(PersonalRequestUtils.URL_PERSONAL_GET, IDGenerator.nextStr())).andExpect(status().is5xxServerError()); + + //权限校验 + this.requestGetPermissionTest(PermissionConstants.SYSTEM_PERSONAL_READ, String.format(PersonalRequestUtils.URL_PERSONAL_GET, loginUser)); + } + + private UserDTO selectUserDTO(String id) throws Exception { + MvcResult result = this.requestGetAndReturn(String.format(PersonalRequestUtils.URL_PERSONAL_GET, loginUser)); + ResultHolder resultHolder = JSON.parseObject(result.getResponse().getContentAsString(StandardCharsets.UTF_8), ResultHolder.class); + return JSON.parseObject(JSON.toJSONString(resultHolder.getData()), UserDTO.class); + } + + @Test + @Order(1) + void testPersonalUpdateInfo() throws Exception { + PersonalUpdateRequest request = new PersonalUpdateRequest(); + request.setId(loginUser); + request.setEmail("admin_update@metersphere.io"); + request.setUsername("admin_update"); + request.setPhone("1111111111"); + this.requestPostWithOk(PersonalRequestUtils.URL_PERSONAL_UPDATE_INFO, request); + UserDTO userDTO = this.selectUserDTO(loginUser); + this.checkUserInformation(userDTO, request); + + //修改回去 + request = new PersonalUpdateRequest(); + request.setId(loginUser); + request.setEmail("admin@metersphere.io"); + request.setUsername("'Administrator'"); + request.setPhone("12345678901"); + this.requestPostWithOk(PersonalRequestUtils.URL_PERSONAL_UPDATE_INFO, request); + userDTO = this.selectUserDTO(loginUser); + this.checkUserInformation(userDTO, request); + + //修改非登录人 + request = new PersonalUpdateRequest(); + request.setId(IDGenerator.nextStr()); + request.setEmail("admin@metersphere.io"); + request.setUsername("'Administrator'"); + request.setPhone("12345678901"); + this.requestPost(PersonalRequestUtils.URL_PERSONAL_UPDATE_INFO, request).andExpect(status().is5xxServerError()); + + //参数校验 + request = new PersonalUpdateRequest(); + request.setId(loginUser); + request.setEmail("admin@metersphere.io"); + request.setUsername("'Administrator'"); + this.requestPost(PersonalRequestUtils.URL_PERSONAL_UPDATE_INFO, request).andExpect(status().isBadRequest()); + + request = new PersonalUpdateRequest(); + request.setId(loginUser); + request.setEmail("admin@metersphere.io"); + request.setPhone("12345678901"); + this.requestPost(PersonalRequestUtils.URL_PERSONAL_UPDATE_INFO, request).andExpect(status().isBadRequest()); + + request = new PersonalUpdateRequest(); + request.setId(loginUser); + request.setUsername("'Administrator'"); + request.setPhone("12345678901"); + this.requestPost(PersonalRequestUtils.URL_PERSONAL_UPDATE_INFO, request).andExpect(status().isBadRequest()); + + request = new PersonalUpdateRequest(); + request.setEmail("admin@metersphere.io"); + request.setUsername("'Administrator'"); + request.setPhone("12345678901"); + this.requestPost(PersonalRequestUtils.URL_PERSONAL_UPDATE_INFO, request).andExpect(status().isBadRequest()); + + //权限校验 + request = new PersonalUpdateRequest(); + request.setId(loginUser); + request.setEmail("admin@metersphere.io"); + request.setUsername("'Administrator'"); + request.setPhone("12345678901"); + this.requestPostPermissionTest(PermissionConstants.SYSTEM_PERSONAL_READ_UPDATE, PersonalRequestUtils.URL_PERSONAL_UPDATE_INFO, request); + } + + private void checkUserInformation(UserDTO userDTO, PersonalUpdateRequest request) { + if (request.getId() != null) { + Assertions.assertEquals(request.getId(), userDTO.getId()); + } + if (request.getEmail() != null) { + Assertions.assertEquals(request.getEmail(), userDTO.getEmail()); + } + if (request.getUsername() != null) { + Assertions.assertEquals(request.getUsername(), userDTO.getName()); + } + if (request.getPhone() != null) { + Assertions.assertEquals(request.getPhone(), userDTO.getPhone()); + } + } + + @Test + @Order(2) + void testPersonalUpdatePassword() throws Exception { + PersonalUpdatePasswordRequest request = new PersonalUpdatePasswordRequest(); + request.setId(loginUser); + request.setOldPassword(CodingUtils.md5("metersphere")); + request.setNewPassword(CodingUtils.md5("metersphere222")); + this.requestPostWithOk(PersonalRequestUtils.URL_PERSONAL_UPDATE_PASSWORD, request); + + UserExample example = new UserExample(); + example.createCriteria().andIdEqualTo(loginUser).andPasswordEqualTo(CodingUtils.md5("metersphere222")); + Assertions.assertEquals(userMapper.countByExample(example), 1); + + //修改回去 + request = new PersonalUpdatePasswordRequest(); + request.setId(loginUser); + request.setOldPassword(CodingUtils.md5("metersphere222")); + request.setNewPassword(CodingUtils.md5("metersphere")); + this.requestPostWithOk(PersonalRequestUtils.URL_PERSONAL_UPDATE_PASSWORD, request); + example.clear(); + example.createCriteria().andIdEqualTo(loginUser).andPasswordEqualTo(CodingUtils.md5("metersphere")); + Assertions.assertEquals(userMapper.countByExample(example), 1L); + + //密码错误 + request = new PersonalUpdatePasswordRequest(); + request.setId(loginUser); + request.setOldPassword(CodingUtils.md5("metersphere222")); + request.setNewPassword(CodingUtils.md5("metersphere")); + this.requestPost(PersonalRequestUtils.URL_PERSONAL_UPDATE_PASSWORD, request).andExpect(status().is5xxServerError()); + + //参数校验 + request = new PersonalUpdatePasswordRequest(); + request.setOldPassword(CodingUtils.md5("metersphere222")); + request.setNewPassword(CodingUtils.md5("metersphere")); + this.requestPost(PersonalRequestUtils.URL_PERSONAL_UPDATE_PASSWORD, request).andExpect(status().isBadRequest()); + + request = new PersonalUpdatePasswordRequest(); + request.setId(loginUser); + request.setNewPassword(CodingUtils.md5("metersphere")); + this.requestPost(PersonalRequestUtils.URL_PERSONAL_UPDATE_PASSWORD, request).andExpect(status().isBadRequest()); + + request = new PersonalUpdatePasswordRequest(); + request.setId(loginUser); + request.setOldPassword(CodingUtils.md5("metersphere222")); + this.requestPost(PersonalRequestUtils.URL_PERSONAL_UPDATE_PASSWORD, request).andExpect(status().isBadRequest()); + + //修改非当前人 + request = new PersonalUpdatePasswordRequest(); + request.setId(IDGenerator.nextStr()); + request.setOldPassword(CodingUtils.md5("metersphere")); + request.setNewPassword(CodingUtils.md5("metersphere333")); + this.requestPost(PersonalRequestUtils.URL_PERSONAL_UPDATE_PASSWORD, request).andExpect(status().is5xxServerError()); + + //权限校验 + request = new PersonalUpdatePasswordRequest(); + request.setId(loginUser); + request.setOldPassword(CodingUtils.md5("metersphere222")); + request.setNewPassword(CodingUtils.md5("metersphere")); + this.requestPostPermissionTest(PermissionConstants.SYSTEM_PERSONAL_READ_UPDATE, PersonalRequestUtils.URL_PERSONAL_UPDATE_PASSWORD, request); + + //最后检查密码是否回归原密码 + example.clear(); + example.createCriteria().andIdEqualTo(loginUser).andPasswordEqualTo(CodingUtils.md5("metersphere")); + Assertions.assertEquals(userMapper.countByExample(example), 1); + } + +} 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 0f8c8703df..56512ef674 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 @@ -2,7 +2,10 @@ package io.metersphere.system.controller.user; import io.metersphere.project.domain.Project; import io.metersphere.project.mapper.ProjectMapper; -import io.metersphere.sdk.util.*; +import io.metersphere.sdk.util.BeanUtils; +import io.metersphere.sdk.util.CodingUtils; +import io.metersphere.sdk.util.JSON; +import io.metersphere.sdk.util.RsaUtils; import io.metersphere.system.base.BaseTest; import io.metersphere.system.controller.handler.ResultHolder; import io.metersphere.system.domain.User; @@ -14,7 +17,13 @@ import io.metersphere.system.dto.UserCreateInfo; import io.metersphere.system.dto.excel.UserExcelRowDTO; import io.metersphere.system.dto.request.UserInviteRequest; import io.metersphere.system.dto.request.UserRegisterRequest; +import io.metersphere.system.dto.request.user.UserChangeEnableRequest; +import io.metersphere.system.dto.request.user.UserEditRequest; +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.BaseTreeNode; import io.metersphere.system.dto.sdk.ExcelParseDTO; @@ -25,12 +34,6 @@ import io.metersphere.system.log.constants.OperationLogType; import io.metersphere.system.mapper.UserInviteMapper; import io.metersphere.system.mapper.UserMapper; import io.metersphere.system.mapper.UserRoleRelationMapper; -import io.metersphere.system.dto.request.user.UserChangeEnableRequest; -import io.metersphere.system.dto.request.user.UserEditRequest; -import io.metersphere.system.dto.request.user.UserRoleBatchRelationRequest; -import io.metersphere.system.dto.response.UserImportResponse; -import io.metersphere.system.dto.response.UserSelectOption; -import io.metersphere.system.dto.response.UserTableResponse; import io.metersphere.system.service.GlobalUserRoleRelationService; import io.metersphere.system.service.UserService; import io.metersphere.system.service.UserToolService; diff --git a/backend/services/system-setting/src/test/java/io/metersphere/system/utils/user/PersonalRequestUtils.java b/backend/services/system-setting/src/test/java/io/metersphere/system/utils/user/PersonalRequestUtils.java new file mode 100644 index 0000000000..1cf0770125 --- /dev/null +++ b/backend/services/system-setting/src/test/java/io/metersphere/system/utils/user/PersonalRequestUtils.java @@ -0,0 +1,9 @@ +package io.metersphere.system.utils.user; + +public class PersonalRequestUtils { + + //用户管理URL + public static final String URL_PERSONAL_GET = "/personal/get/%s"; + public static final String URL_PERSONAL_UPDATE_INFO = "/personal/update-info"; + public static final String URL_PERSONAL_UPDATE_PASSWORD = "/personal/update-password"; +}