From 7df2b2d9d08f788635b3ff1ab37ad4d92f5474f7 Mon Sep 17 00:00:00 2001 From: WangXu10 Date: Tue, 1 Aug 2023 14:04:18 +0800 Subject: [PATCH] =?UTF-8?q?refactor(=E7=B3=BB=E7=BB=9F=E8=AE=BE=E7=BD=AE):?= =?UTF-8?q?=20=E7=B3=BB=E7=BB=9F=E6=97=A5=E5=BF=97=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sdk/constants/OperationLogConstants.java | 1 + .../sdk/log/vo/OperationLogRequest.java | 6 ++++++ .../sdk/mapper/BaseOperationLogMapper.xml | 4 ++-- .../sdk/service/SystemParameterService.java | 9 +++++---- .../sdk/service/TestResourcePoolService.java | 13 +++++++------ .../system/service/OrganizationService.java | 17 +++++++---------- .../service/OrganizationUserRoleLogService.java | 9 +++++---- .../system/service/SystemProjectService.java | 7 ++++--- .../system/service/UserRoleRelationService.java | 5 +++-- .../metersphere/system/service/UserService.java | 17 +++++++++-------- .../controller/OperationLogControllerTests.java | 2 +- .../resources/dml/init_operation_log_test.sql | 8 ++++---- 12 files changed, 54 insertions(+), 44 deletions(-) diff --git a/backend/framework/sdk/src/main/java/io/metersphere/sdk/constants/OperationLogConstants.java b/backend/framework/sdk/src/main/java/io/metersphere/sdk/constants/OperationLogConstants.java index dc93e042aa..f6cf8d979f 100644 --- a/backend/framework/sdk/src/main/java/io/metersphere/sdk/constants/OperationLogConstants.java +++ b/backend/framework/sdk/src/main/java/io/metersphere/sdk/constants/OperationLogConstants.java @@ -2,4 +2,5 @@ package io.metersphere.sdk.constants; public class OperationLogConstants { public static final String SYSTEM = "SYSTEM"; + public static final String ORGANIZATION = "ORGANIZATION"; } diff --git a/backend/framework/sdk/src/main/java/io/metersphere/sdk/log/vo/OperationLogRequest.java b/backend/framework/sdk/src/main/java/io/metersphere/sdk/log/vo/OperationLogRequest.java index ec07728e0f..da3bc6f9f8 100644 --- a/backend/framework/sdk/src/main/java/io/metersphere/sdk/log/vo/OperationLogRequest.java +++ b/backend/framework/sdk/src/main/java/io/metersphere/sdk/log/vo/OperationLogRequest.java @@ -1,6 +1,10 @@ package io.metersphere.sdk.log.vo; +import io.metersphere.sdk.constants.UserRoleType; import io.metersphere.sdk.dto.BasePageRequest; +import io.metersphere.sdk.valid.EnumValue; +import io.metersphere.validation.groups.Created; +import io.metersphere.validation.groups.Updated; import io.swagger.v3.oas.annotations.media.Schema; import jakarta.validation.constraints.NotNull; import lombok.Data; @@ -39,6 +43,8 @@ public class OperationLogRequest extends BasePageRequest { @Schema(title = "名称") private String content; + @Schema(title = "级别 系统|组织|项目") + @EnumValue(enumClass = UserRoleType.class, groups = {Created.class, Updated.class}) private String level; } diff --git a/backend/framework/sdk/src/main/java/io/metersphere/sdk/mapper/BaseOperationLogMapper.xml b/backend/framework/sdk/src/main/java/io/metersphere/sdk/mapper/BaseOperationLogMapper.xml index 95d3084299..c25b1378ec 100644 --- a/backend/framework/sdk/src/main/java/io/metersphere/sdk/mapper/BaseOperationLogMapper.xml +++ b/backend/framework/sdk/src/main/java/io/metersphere/sdk/mapper/BaseOperationLogMapper.xml @@ -22,10 +22,10 @@ AND t.create_time BETWEEN #{request.startTime} AND #{request.endTime} - AND t.project_id != 'system' + AND t.project_id ]]> 'SYSTEM' - AND t.project_id ]]> '' + AND t.project_id ]]> 'ORGANIZATION' AND t.project_id IN diff --git a/backend/framework/sdk/src/main/java/io/metersphere/sdk/service/SystemParameterService.java b/backend/framework/sdk/src/main/java/io/metersphere/sdk/service/SystemParameterService.java index f2356c57d3..4084463171 100644 --- a/backend/framework/sdk/src/main/java/io/metersphere/sdk/service/SystemParameterService.java +++ b/backend/framework/sdk/src/main/java/io/metersphere/sdk/service/SystemParameterService.java @@ -1,6 +1,7 @@ package io.metersphere.sdk.service; import io.metersphere.sdk.constants.HttpMethodConstants; +import io.metersphere.sdk.constants.OperationLogConstants; import io.metersphere.sdk.constants.ParamConstants; import io.metersphere.sdk.dto.BaseSystemConfigDTO; import io.metersphere.sdk.dto.EMailInfoDto; @@ -222,8 +223,8 @@ public class SystemParameterService { public LogDTO updateBaseLog(List systemParameter) { List originalValue = getOriginalValue(systemParameter); LogDTO dto = new LogDTO( - "system", - "", + OperationLogConstants.SYSTEM, + OperationLogConstants.SYSTEM, "system-parameter", null, OperationLogType.ADD.name(), @@ -239,8 +240,8 @@ public class SystemParameterService { public LogDTO updateLog(List systemParameter) { List originalValue = getOriginalValue(systemParameter); LogDTO dto = new LogDTO( - "system", - "", + OperationLogConstants.SYSTEM, + OperationLogConstants.SYSTEM, "system-parameter", null, OperationLogType.ADD.name(), diff --git a/backend/framework/sdk/src/main/java/io/metersphere/sdk/service/TestResourcePoolService.java b/backend/framework/sdk/src/main/java/io/metersphere/sdk/service/TestResourcePoolService.java index 4cf0bf4195..8584bcfbcb 100644 --- a/backend/framework/sdk/src/main/java/io/metersphere/sdk/service/TestResourcePoolService.java +++ b/backend/framework/sdk/src/main/java/io/metersphere/sdk/service/TestResourcePoolService.java @@ -1,6 +1,7 @@ package io.metersphere.sdk.service; import io.metersphere.sdk.constants.HttpMethodConstants; +import io.metersphere.sdk.constants.OperationLogConstants; import io.metersphere.sdk.constants.ResourcePoolTypeEnum; import io.metersphere.sdk.dto.*; import io.metersphere.sdk.exception.MSException; @@ -278,8 +279,8 @@ public class TestResourcePoolService { public LogDTO addLog(TestResourcePoolRequest request) { LogDTO dto = new LogDTO( - "system", - "", + OperationLogConstants.SYSTEM, + OperationLogConstants.SYSTEM, request.getId(), null, OperationLogType.ADD.name(), @@ -296,8 +297,8 @@ public class TestResourcePoolService { TestResourcePool pool = testResourcePoolMapper.selectByPrimaryKey(id); if (pool != null) { LogDTO dto = new LogDTO( - "system", - "", + OperationLogConstants.SYSTEM, + OperationLogConstants.SYSTEM, id, pool.getCreateUser(), OperationLogType.DELETE.name(), @@ -317,8 +318,8 @@ public class TestResourcePoolService { TestResourcePool pool = testResourcePoolMapper.selectByPrimaryKey(resourcePoolId); if (pool != null) { LogDTO dto = new LogDTO( - "system", - "", + OperationLogConstants.SYSTEM, + OperationLogConstants.SYSTEM, pool.getId(), pool.getCreateUser(), OperationLogType.UPDATE.name(), diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/service/OrganizationService.java b/backend/services/system-setting/src/main/java/io/metersphere/system/service/OrganizationService.java index 533d2ec5c5..07e1799768 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/service/OrganizationService.java +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/service/OrganizationService.java @@ -3,10 +3,7 @@ package io.metersphere.system.service; import io.metersphere.project.domain.Project; import io.metersphere.project.domain.ProjectExample; import io.metersphere.project.mapper.ProjectMapper; -import io.metersphere.sdk.constants.HttpMethodConstants; -import io.metersphere.sdk.constants.InternalUserRole; -import io.metersphere.sdk.constants.UserRoleEnum; -import io.metersphere.sdk.constants.UserRoleType; +import io.metersphere.sdk.constants.*; import io.metersphere.sdk.dto.LogDTO; import io.metersphere.sdk.dto.OptionDTO; import io.metersphere.sdk.exception.MSException; @@ -284,7 +281,7 @@ public class OrganizationService { userRoleRelationMapper.insert(userRoleRelation); //add Log String path = add ? "/organization/add-member" : "/organization/role/update-member"; - setLog(organizationId, "system", path, OperationLogModule.ORGANIZATION_MEMBER, "成员", logDTOList, memberId, userRoleRelation, add); + setLog(organizationId, OperationLogConstants.ORGANIZATION, path, OperationLogModule.ORGANIZATION_MEMBER, "成员", logDTOList, memberId, userRoleRelation, add); } } }); @@ -389,7 +386,7 @@ public class OrganizationService { } for (UserRoleRelation userRoleWidthOrgRelation : userRoleWidthOrgRelations) { LogDTO dto = new LogDTO( - "system", + OperationLogConstants.ORGANIZATION, organizationId, userRoleWidthOrgRelation.getId(), userRoleWidthOrgRelation.getCreateUser(), @@ -468,7 +465,7 @@ public class OrganizationService { userRoleRelationMapper.insert(userRoleRelation); //add Log String path = "/organization/update-member"; - setLog(organizationId, "system", path, OperationLogModule.ORGANIZATION_MEMBER, "成员", logDTOList, memberId, userRoleRelation, false); + setLog(organizationId, OperationLogConstants.ORGANIZATION, path, OperationLogModule.ORGANIZATION_MEMBER, "成员", logDTOList, memberId, userRoleRelation, false); }); } @@ -497,7 +494,7 @@ public class OrganizationService { userRoleRelationMapper.insert(userRoleRelation); //add Log String path = "/organization/update-member"; - setLog(organizationId, "system", path, OperationLogModule.ORGANIZATION_MEMBER, "成员", logDTOList, memberId, userRoleRelation, false); + setLog(organizationId, OperationLogConstants.ORGANIZATION, path, OperationLogModule.ORGANIZATION_MEMBER, "成员", logDTOList, memberId, userRoleRelation, false); }); } @@ -676,8 +673,8 @@ public class OrganizationService { */ private void setLog(String organizationId, String createUser, String type, String content, String path, Object originalValue, Object modifiedValue, List logs) { LogDTO dto = new LogDTO( - "system", - "system", + OperationLogConstants.SYSTEM, + OperationLogConstants.SYSTEM, organizationId, createUser, type, diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/service/OrganizationUserRoleLogService.java b/backend/services/system-setting/src/main/java/io/metersphere/system/service/OrganizationUserRoleLogService.java index 2c6b84ca07..dcc9a8d47d 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/service/OrganizationUserRoleLogService.java +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/service/OrganizationUserRoleLogService.java @@ -1,5 +1,6 @@ package io.metersphere.system.service; +import io.metersphere.sdk.constants.OperationLogConstants; import io.metersphere.sdk.dto.LogDTO; import io.metersphere.sdk.dto.request.PermissionSettingUpdateRequest; import io.metersphere.sdk.log.constants.OperationLogModule; @@ -27,7 +28,7 @@ public class OrganizationUserRoleLogService { */ public LogDTO addLog(OrganizationUserRoleEditRequest request) { LogDTO dto = new LogDTO( - "", + OperationLogConstants.ORGANIZATION, request.getScopeId(), null, null, @@ -46,7 +47,7 @@ public class OrganizationUserRoleLogService { */ public LogDTO updateLog(OrganizationUserRoleEditRequest request) { LogDTO dto = new LogDTO( - "", + OperationLogConstants.ORGANIZATION, request.getScopeId(), null, null, @@ -66,7 +67,7 @@ public class OrganizationUserRoleLogService { public LogDTO deleteLog(String id) { UserRole userRole = userRoleMapper.selectByPrimaryKey(id); LogDTO dto = new LogDTO( - "", + OperationLogConstants.ORGANIZATION, userRole.getScopeId(), null, null, @@ -105,7 +106,7 @@ public class OrganizationUserRoleLogService { private LogDTO getLog(String roleId) { UserRole userRole = userRoleMapper.selectByPrimaryKey(roleId); return new LogDTO( - "", + OperationLogConstants.ORGANIZATION, userRole.getScopeId(), null, null, diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/service/SystemProjectService.java b/backend/services/system-setting/src/main/java/io/metersphere/system/service/SystemProjectService.java index d1c56ba8de..0b55f41fce 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/service/SystemProjectService.java +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/service/SystemProjectService.java @@ -5,6 +5,7 @@ import io.metersphere.project.domain.ProjectExample; import io.metersphere.project.mapper.ProjectMapper; import io.metersphere.sdk.constants.HttpMethodConstants; import io.metersphere.sdk.constants.InternalUserRole; +import io.metersphere.sdk.constants.OperationLogConstants; import io.metersphere.sdk.dto.AddProjectRequest; import io.metersphere.sdk.dto.LogDTO; import io.metersphere.sdk.dto.ProjectDTO; @@ -346,7 +347,7 @@ public class SystemProjectService { // delete project projectMapper.deleteByPrimaryKey(project.getId()); setLog(project.getId(), "null", Translator.get("delete") + Translator.get("project") + ": " + project.getName(), - "system", "", OperationLogType.DELETE.name(), "", logDTOList); + OperationLogConstants.SYSTEM, OperationLogConstants.SYSTEM, OperationLogType.DELETE.name(), "", logDTOList); }); operationLogService.batchAdd(logDTOList); } @@ -364,8 +365,8 @@ public class SystemProjectService { private static void setLog(String projectId, String path, String content, String userId, Object originalValue, String type, String method, List logDTOList) { LogDTO dto = new LogDTO( - "system", - "system", + OperationLogConstants.SYSTEM, + OperationLogConstants.SYSTEM, projectId, userId, type, diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/service/UserRoleRelationService.java b/backend/services/system-setting/src/main/java/io/metersphere/system/service/UserRoleRelationService.java index 65903195f8..5c8dcb4658 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/service/UserRoleRelationService.java +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/service/UserRoleRelationService.java @@ -1,5 +1,6 @@ package io.metersphere.system.service; +import io.metersphere.sdk.constants.OperationLogConstants; import io.metersphere.sdk.constants.UserRoleEnum; import io.metersphere.sdk.dto.LogDTO; import io.metersphere.sdk.log.constants.OperationLogModule; @@ -61,8 +62,8 @@ public class UserRoleRelationService { userRoleList.forEach(userRole -> { LogDTO log = new LogDTO(); log.setId(UUID.randomUUID().toString()); - log.setProjectId("system"); - log.setOrganizationId(""); + log.setProjectId(OperationLogConstants.SYSTEM); + log.setOrganizationId(OperationLogConstants.SYSTEM); log.setType(operationType); log.setCreateUser(operator); log.setModule(OperationLogModule.SYSTEM_USER); 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 6f57670ab8..af40c3e352 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 @@ -2,6 +2,7 @@ package io.metersphere.system.service; import com.alibaba.excel.EasyExcelFactory; import io.metersphere.sdk.constants.HttpMethodConstants; +import io.metersphere.sdk.constants.OperationLogConstants; import io.metersphere.sdk.dto.BasePageRequest; import io.metersphere.sdk.dto.ExcelParseDTO; import io.metersphere.sdk.dto.LogDTO; @@ -71,8 +72,8 @@ public class UserService { LogDTO log = new LogDTO(); log.setId(UUID.randomUUID().toString()); log.setCreateUser(user.getCreateUser()); - log.setProjectId("system"); - log.setOrganizationId(""); + log.setProjectId(OperationLogConstants.SYSTEM); + log.setOrganizationId(OperationLogConstants.SYSTEM); log.setType(OperationLogType.ADD.name()); log.setModule(OperationLogModule.SYSTEM_USER); log.setMethod("addUser"); @@ -312,8 +313,8 @@ public class UserService { User user = userMapper.selectByPrimaryKey(request.getId()); if (user != null) { LogDTO dto = new LogDTO( - "system", - "", + OperationLogConstants.SYSTEM, + OperationLogConstants.SYSTEM, request.getId(), null, OperationLogType.UPDATE.name(), @@ -332,8 +333,8 @@ public class UserService { User user = userMapper.selectByPrimaryKey(userId); if (user != null) { LogDTO dto = new LogDTO( - "system", - "", + OperationLogConstants.SYSTEM, + OperationLogConstants.SYSTEM, userId, null, OperationLogType.UPDATE.name(), @@ -354,8 +355,8 @@ public class UserService { if (user != null) { LogDTO dto = new LogDTO( - "system", - "", + OperationLogConstants.SYSTEM, + OperationLogConstants.SYSTEM, user.getId(), user.getCreateUser(), OperationLogType.DELETE.name(), diff --git a/backend/services/system-setting/src/test/java/io/metersphere/system/controller/OperationLogControllerTests.java b/backend/services/system-setting/src/test/java/io/metersphere/system/controller/OperationLogControllerTests.java index d6115ab324..ebe598971c 100644 --- a/backend/services/system-setting/src/test/java/io/metersphere/system/controller/OperationLogControllerTests.java +++ b/backend/services/system-setting/src/test/java/io/metersphere/system/controller/OperationLogControllerTests.java @@ -141,7 +141,7 @@ public class OperationLogControllerTests extends BaseTest { this.requestGetWithOkAndReturn(USER_LIST); // @@校验权限 - // requestGetPermissionTest(PermissionConstants.SYSTEM_OPERATING_LOG_READ, OPTIONS_LIST); + // requestGetPermissionTest(PermissionConstants.SYSTEM_OPERATING_LOG_READ, USER_LIST); } @Test diff --git a/backend/services/system-setting/src/test/resources/dml/init_operation_log_test.sql b/backend/services/system-setting/src/test/resources/dml/init_operation_log_test.sql index d5551f88eb..72495b6801 100644 --- a/backend/services/system-setting/src/test/resources/dml/init_operation_log_test.sql +++ b/backend/services/system-setting/src/test/resources/dml/init_operation_log_test.sql @@ -7,10 +7,10 @@ INSERT INTO project (id, num, organization_id, name, description, create_user, u -- 初始化日志记录 -INSERT INTO operation_log(`id`, `project_id`, `organization_id`, `create_time`, `create_user`, `source_id`, `method`, `type`, `module`, `content`, `path`) VALUES (uuid(), 'system', '', 1689141859000, 'admin', '1', 'post', 'add', 'SYSTEM_PARAMETER_SETTING', '认证配置', '/system/authsource/add'); -INSERT INTO operation_log(`id`, `project_id`, `organization_id`, `create_time`, `create_user`, `source_id`, `method`, `type`, `module`, `content`, `path`) VALUES (uuid(), 'system', '', 1689141859000, 'admin', '1', 'post', 'update', 'SYSTEM_PARAMETER_SETTING', '认证配置', '/system/authsource/update'); -INSERT INTO operation_log(`id`, `project_id`, `organization_id`, `create_time`, `create_user`, `source_id`, `method`, `type`, `module`, `content`, `path`) VALUES (uuid(), '', 'organization_id_001', 1689141859000, 'admin', '1', 'post', 'add', 'SYSTEM_PARAMETER_SETTING', '认证配置', '/system/authsource/add'); -INSERT INTO operation_log(`id`, `project_id`, `organization_id`, `create_time`, `create_user`, `source_id`, `method`, `type`, `module`, `content`, `path`) VALUES (uuid(), '', 'organization_id_002', 1689141859000, 'admin', '1', 'post', 'update', 'SYSTEM_PARAMETER_SETTING', '认证配置', '/system/authsource/update'); +INSERT INTO operation_log(`id`, `project_id`, `organization_id`, `create_time`, `create_user`, `source_id`, `method`, `type`, `module`, `content`, `path`) VALUES (uuid(), 'SYSTEM', 'SYSTEM', 1689141859000, 'admin', '1', 'post', 'add', 'SYSTEM_PARAMETER_SETTING', '认证配置', '/system/authsource/add'); +INSERT INTO operation_log(`id`, `project_id`, `organization_id`, `create_time`, `create_user`, `source_id`, `method`, `type`, `module`, `content`, `path`) VALUES (uuid(), 'SYSTEM', 'SYSTEM', 1689141859000, 'admin', '1', 'post', 'update', 'SYSTEM_PARAMETER_SETTING', '认证配置', '/system/authsource/update'); +INSERT INTO operation_log(`id`, `project_id`, `organization_id`, `create_time`, `create_user`, `source_id`, `method`, `type`, `module`, `content`, `path`) VALUES (uuid(), 'ORGANIZATION', 'organization_id_001', 1689141859000, 'admin', '1', 'post', 'add', 'SYSTEM_PARAMETER_SETTING', '认证配置', '/system/authsource/add'); +INSERT INTO operation_log(`id`, `project_id`, `organization_id`, `create_time`, `create_user`, `source_id`, `method`, `type`, `module`, `content`, `path`) VALUES (uuid(), 'ORGANIZATION', 'organization_id_002', 1689141859000, 'admin', '1', 'post', 'update', 'SYSTEM_PARAMETER_SETTING', '认证配置', '/system/authsource/update'); INSERT INTO operation_log(`id`, `project_id`, `organization_id`, `create_time`, `create_user`, `source_id`, `method`, `type`, `module`, `content`, `path`) VALUES (uuid(), 'project_id_001', 'organization_id_001', 1689141859000, 'admin', '1', 'post', 'add', 'SYSTEM_PARAMETER_SETTING', '认证配置', '/system/authsource/add'); INSERT INTO operation_log(`id`, `project_id`, `organization_id`, `create_time`, `create_user`, `source_id`, `method`, `type`, `module`, `content`, `path`) VALUES (uuid(), 'project_id_001', 'organization_id_001', 1689141859000, 'admin', '1', 'post', 'update', 'SYSTEM_PARAMETER_SETTING', '认证配置', '/system/authsource/update'); INSERT INTO operation_log(`id`, `project_id`, `organization_id`, `create_time`, `create_user`, `source_id`, `method`, `type`, `module`, `content`, `path`) VALUES (uuid(), 'project_id_002', 'organization_id_001', 1689141859000, 'admin', '1', 'post', 'add', 'SYSTEM_PARAMETER_SETTING', '认证配置', '/system/authsource/add');