diff --git a/backend/framework/sdk/src/main/java/io/metersphere/sdk/log/service/OperationLogService.java b/backend/framework/sdk/src/main/java/io/metersphere/sdk/log/service/OperationLogService.java index a22231d9f9..e719f62ee0 100644 --- a/backend/framework/sdk/src/main/java/io/metersphere/sdk/log/service/OperationLogService.java +++ b/backend/framework/sdk/src/main/java/io/metersphere/sdk/log/service/OperationLogService.java @@ -101,7 +101,7 @@ public class OperationLogService { } List list = baseOperationLogMapper.list(request); - if (CollectionUtils.isNotEmpty(list) && !"system".equals(request.getLevel())) { + if (CollectionUtils.isNotEmpty(list)) { List userIds = list.stream().map(OperationLogResponse::getCreateUser).collect(Collectors.toList()); List projectIds = list.stream().map(OperationLogResponse::getProjectId).collect(Collectors.toList()); List organizationIds = list.stream().map(OperationLogResponse::getOrganizationId).collect(Collectors.toList()); 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 0d678b36c7..95d3084299 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 @@ -2,13 +2,14 @@ - SELECT t.id, t.project_id, t.organization_id, t.create_time, t.create_user, + t.module, t.type, t.content FROM @@ -23,6 +24,9 @@ AND t.project_id != 'system' + + AND t.project_id ]]> '' + AND t.project_id IN @@ -36,13 +40,13 @@ - AND t.type = #{request.type, jdbcType=VARCHAR} + AND t.type = #{request.type} - AND t.module = #{module, jdbcType=VARCHAR} + AND t.module = #{request.module} - AND t.content like #{request.content, jdbcType=VARCHAR} + AND t.content like CONCAT('%', #{request.content},'%') ORDER BY t.oper_time DESC 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 ad57798d75..05c8f210c5 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 @@ -221,7 +221,7 @@ public class SystemParameterService { "system-parameter", null, OperationLogType.ADD.name(), - OperationLogModule.SYSTEM_USER_ROLE_RELATION, + OperationLogModule.SYSTEM_PARAMETER_SETTING, "系统参数"); dto.setPath("/system/parameter/save/base-info"); @@ -237,7 +237,7 @@ public class SystemParameterService { "system-parameter", null, OperationLogType.ADD.name(), - OperationLogModule.SYSTEM_USER_ROLE_RELATION, + OperationLogModule.SYSTEM_PARAMETER_SETTING, "编辑邮件信息"); dto.setPath("/system/parameter/edit/email-info"); diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/controller/OperationLogController.java b/backend/services/system-setting/src/main/java/io/metersphere/system/controller/OperationLogController.java index 6f04821ed2..66e6b1558d 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/controller/OperationLogController.java +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/controller/OperationLogController.java @@ -25,7 +25,7 @@ import org.springframework.web.bind.annotation.*; import java.util.List; @RestController -@RequestMapping("/operating/log") +@RequestMapping("/operation/log") public class OperationLogController { @Resource diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/controller/SystemProjectController.java b/backend/services/system-setting/src/main/java/io/metersphere/system/controller/SystemProjectController.java index 6e8c828229..ac1db37761 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/controller/SystemProjectController.java +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/controller/SystemProjectController.java @@ -80,7 +80,7 @@ public class SystemProjectController { @GetMapping("/revoke/{id}") @RequiresPermissions(PermissionConstants.SYSTEM_ORGANIZATION_PROJECT_READ_RECOVER) - @Log(type = OperationLogType.UPDATE, expression = "#msClass.updateLog(#project)", msClass = SystemProjectLogService.class) + @Log(type = OperationLogType.UPDATE, expression = "#msClass.updateLog(#id)", msClass = SystemProjectLogService.class) public int revokeProject(@PathVariable String id) { return systemProjectService.revoke(id); } 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 4148a8a636..7777bf92ad 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 @@ -12,27 +12,32 @@ import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMock import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.jdbc.Sql; import org.springframework.test.context.jdbc.SqlConfig; +import org.springframework.test.web.servlet.ResultActions; import java.util.Arrays; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + @SpringBootTest @AutoConfigureMockMvc @TestMethodOrder(MethodOrderer.OrderAnnotation.class) public class OperationLogControllerTests extends BaseTest { - public static final String OPERATION_LOG_LIST = "/operating/log/list"; + public static final String OPERATION_LOG_LIST = "/operation/log/list"; - public static final String OPTIONS_LIST = "/operating/log/get/options"; + public static final String OPTIONS_LIST = "/operation/log/get/options"; public static final String USER_LIST = "/system/user/list"; public static final String SYSTEM = "system"; public static final String ORGANIZATION = "organization"; + public static final String PROJECT = "project"; /** * 系统级别 查询 用例 + * * @throws Exception */ @Test @@ -45,6 +50,13 @@ public class OperationLogControllerTests extends BaseTest { OperationLogRequest request = buildParam(SYSTEM); this.requestPostWithOkAndReturn(OPERATION_LOG_LIST, request); + //其他查询条件 + request.setOperUser("admin"); + request.setType("add"); + request.setModule("SYSTEM_PARAMETER_SETTING"); + request.setContent("认证配置"); + this.requestPostWithOkAndReturn(OPERATION_LOG_LIST, request); + // @@异常参数校验 updatedGroupParamValidateTest(OperationLogRequestDefinition.class, OPERATION_LOG_LIST); // @@校验权限 @@ -55,17 +67,26 @@ public class OperationLogControllerTests extends BaseTest { /** * 组织级别 查询 用例 + * * @throws Exception */ @Test - @Order(3) + @Order(4) public void testOrganizationOperationLogList() throws Exception { OperationLogRequest request = buildParam(ORGANIZATION); //组织级别 全部 this.requestPostWithOkAndReturn(OPERATION_LOG_LIST, request); + //其他查询条件 + request.setOperUser("admin"); + request.setType("add"); + request.setModule("SYSTEM_PARAMETER_SETTING"); + request.setContent("认证配置"); + this.requestPostWithOkAndReturn(OPERATION_LOG_LIST, request); + + //组织级别 指定组织查询 - request.setOrganizationIds(Arrays.asList("organization_id_001","organization_id_002")); + request.setOrganizationIds(Arrays.asList("organization_id_001", "organization_id_002")); this.requestPostWithOkAndReturn(OPERATION_LOG_LIST, request); // @@异常参数校验 @@ -75,7 +96,35 @@ public class OperationLogControllerTests extends BaseTest { } - //TODO 项目级别 查询 用例 + /** + * 项目级别 查询 用例 + * + * @throws Exception + */ + @Test + @Order(5) + public void testProjectOperationLogList() throws Exception { + OperationLogRequest request = buildParam(PROJECT); + //项目级别 全部 + this.requestPostWithOkAndReturn(OPERATION_LOG_LIST, request); + + //其他查询条件 + request.setOperUser("admin"); + request.setType("add"); + request.setModule("SYSTEM_PARAMETER_SETTING"); + request.setContent("认证配置"); + this.requestPostWithOkAndReturn(OPERATION_LOG_LIST, request); + + //项目级别 指定项目查询 + request.setProjectIds(Arrays.asList("project_id_001", "project_id_002")); + this.requestPostWithOkAndReturn(OPERATION_LOG_LIST, request); + + // @@异常参数校验 + updatedGroupParamValidateTest(OperationLogRequestDefinition.class, OPERATION_LOG_LIST); + // @@校验权限 + requestPostPermissionTest(PermissionConstants.SYSTEM_OPERATING_LOG_READ, OPERATION_LOG_LIST, request); + } + @Test @Order(2) @@ -95,7 +144,15 @@ public class OperationLogControllerTests extends BaseTest { requestGetPermissionTest(PermissionConstants.SYSTEM_OPERATING_LOG_READ, OPTIONS_LIST); } - //TODO 异常用例补充 + @Test + @Order(6) + public void testGetOperationLogParamsError() throws Exception { + OperationLogRequest request = buildParam(SYSTEM); + request.setStartTime(1689149059000l); + request.setEndTime(1689131059000l); + ResultActions resultActions = this.requestPost(OPERATION_LOG_LIST, request); + resultActions.andExpect(status().is5xxServerError()); + } private OperationLogRequest buildParam(String level) { 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 9bf851339e..a9f46b2df9 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 @@ -1,11 +1,22 @@ -- 模拟数据 INSERT INTO organization (id, num, name, description, create_user, update_user, create_time, update_time) VALUES ('organization_id_001', 100010, '测试日志组织', '测试日志的组织', 'admin', 'admin', unix_timestamp() * 1000, unix_timestamp() * 1000); +INSERT INTO organization (id, num, name, description, create_user, update_user, create_time, update_time) VALUES ('organization_id_002', 100011, '测试日志组织2', '测试日志的组织2', 'admin', 'admin', unix_timestamp() * 1000, unix_timestamp() * 1000); INSERT INTO project (id, num, organization_id, name, description, create_user, update_user, create_time, update_time) VALUES ('project_id_001', 100010, 'organization_id_001', '测试日志项目', '测试日志的项目', 'admin', 'admin', unix_timestamp() * 1000, unix_timestamp() * 1000); +INSERT INTO project (id, num, organization_id, name, description, create_user, update_user, create_time, update_time) VALUES ('project_id_002', 100011, 'organization_id_002', '测试日志项目2', '测试日志的项目2', 'admin', 'admin', unix_timestamp() * 1000, unix_timestamp() * 1000); -- 初始化日志记录 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(), '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'); +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', '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_002', 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_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_002', 'organization_id_002', 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_002', 'organization_id_002', 1689141859000, 'admin', '1', 'post', 'update', 'SYSTEM_PARAMETER_SETTING', '认证配置', '/system/authsource/update');