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 31813eddbe..a2719d9023 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 @@ -113,6 +113,7 @@ public class PermissionConstants { public static final String SYSTEM_LOG_READ = "SYSTEM_LOG:READ"; public static final String ORGANIZATION_LOG_READ = "ORGANIZATION_LOG:READ"; + public static final String PROJECT_LOG_READ = "PROJECT_LOG:READ"; public static final String PROJECT_USER_READ_ADD = "PROJECT_USER:READ+ADD"; public static final String PROJECT_USER_READ_DELETE = "PROJECT_USER:READ+DELETE"; diff --git a/backend/framework/sdk/src/main/resources/i18n/project_en_US.properties b/backend/framework/sdk/src/main/resources/i18n/project_en_US.properties index 17fef1aa08..bf3218afc2 100644 --- a/backend/framework/sdk/src/main/resources/i18n/project_en_US.properties +++ b/backend/framework/sdk/src/main/resources/i18n/project_en_US.properties @@ -108,4 +108,4 @@ permission.project_application.name=Project application permission.project_application_test_plan.read=Test plan read permission.project_application_test_plan.update=Test plan update permission.project_base_info.name=Project base info - +permission.project_log.name=Operation log diff --git a/backend/framework/sdk/src/main/resources/i18n/project_zh_CN.properties b/backend/framework/sdk/src/main/resources/i18n/project_zh_CN.properties index 55225d0a80..8076025181 100644 --- a/backend/framework/sdk/src/main/resources/i18n/project_zh_CN.properties +++ b/backend/framework/sdk/src/main/resources/i18n/project_zh_CN.properties @@ -108,3 +108,4 @@ permission.project_application.name=应用管理 permission.project_application_test_plan.read=测试计划-查询 permission.project_application_test_plan.update=测试计划-编辑 permission.project_base_info.name=基础信息 +permission.project_log.name=日志 diff --git a/backend/framework/sdk/src/main/resources/i18n/project_zh_TW.properties b/backend/framework/sdk/src/main/resources/i18n/project_zh_TW.properties index 6d617c4aa6..aca4791017 100644 --- a/backend/framework/sdk/src/main/resources/i18n/project_zh_TW.properties +++ b/backend/framework/sdk/src/main/resources/i18n/project_zh_TW.properties @@ -107,4 +107,5 @@ permission.project_fake_error.name=誤報庫 permission.project_application.name=應用管理 permission.project_application_test_plan.read=測試計劃-查詢 permission.project_application_test_plan.update=測試計劃-編輯 -permission.project_base_info.name=基礎信息 \ No newline at end of file +permission.project_base_info.name=基礎信息 +permission.project_log.name=日誌 \ No newline at end of file diff --git a/backend/services/project-management/src/main/java/io/metersphere/project/controller/ProjectLogController.java b/backend/services/project-management/src/main/java/io/metersphere/project/controller/ProjectLogController.java new file mode 100644 index 0000000000..230ac84404 --- /dev/null +++ b/backend/services/project-management/src/main/java/io/metersphere/project/controller/ProjectLogController.java @@ -0,0 +1,67 @@ +package io.metersphere.project.controller; + + +import com.github.pagehelper.Page; +import com.github.pagehelper.PageHelper; +import io.metersphere.sdk.constants.PermissionConstants; +import io.metersphere.sdk.log.service.OperationLogService; +import io.metersphere.sdk.log.vo.OperationLogRequest; +import io.metersphere.sdk.log.vo.OperationLogResponse; +import io.metersphere.sdk.util.PageUtils; +import io.metersphere.sdk.util.Pager; +import io.metersphere.sdk.util.SessionUtils; +import io.metersphere.system.domain.User; +import io.metersphere.system.service.UserService; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.tags.Tag; +import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.lang3.StringUtils; +import org.apache.shiro.authz.annotation.RequiresPermissions; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; + +import java.util.Arrays; +import java.util.List; + + +/** + * @author wx + */ + +@Tag(name = "项目管理-日志") +@RestController +@RequestMapping("/project/log") +public class ProjectLogController { + + @Autowired + private UserService userService; + + @Autowired + private OperationLogService operationLogService; + + @GetMapping("/user/list/{projectId}") + @Operation(summary = "项目管理-日志-获取用户列表-支持远程搜索") + @RequiresPermissions(PermissionConstants.PROJECT_LOG_READ) + public List getUserList(@PathVariable(value = "projectId") String projectId, + @Schema(description = "查询关键字,根据邮箱和用户名查询") + @RequestParam(value = "keyword", required = false) String keyword) { + return userService.getUserListByOrgId(StringUtils.defaultIfBlank(projectId,SessionUtils.getCurrentProjectId()), keyword); + } + + + @PostMapping("/list") + @Operation(summary = "项目管理-日志--操作日志列表查询") + @RequiresPermissions(PermissionConstants.PROJECT_LOG_READ) + public Pager> projectLogList(@Validated @RequestBody OperationLogRequest request) { + Page page = PageHelper.startPage(request.getCurrent(), request.getPageSize(), + StringUtils.isNotBlank(request.getSortString()) ? request.getSortString() : "create_time desc"); + if (CollectionUtils.isEmpty(request.getProjectIds())) { + //未传项目id 获取登录用户当前项目id + request.setProjectIds(Arrays.asList(SessionUtils.getCurrentProjectId())); + } + return PageUtils.setPageInfo(page, operationLogService.list(request)); + } + +} diff --git a/backend/services/project-management/src/main/resources/permission.json b/backend/services/project-management/src/main/resources/permission.json index c4c61fad1c..e1b1e08024 100644 --- a/backend/services/project-management/src/main/resources/permission.json +++ b/backend/services/project-management/src/main/resources/permission.json @@ -137,6 +137,16 @@ "name": "permission.project_application_test_plan.update" } ] + }, + { + "id": "PROJECT_LOG", + "name": "permission.project_log.name", + "license": true, + "permissions": [ + { + "id": "PROJECT_LOG:READ" + } + ] } ] } diff --git a/backend/services/project-management/src/test/java/io/metersphere/project/Application.java b/backend/services/project-management/src/test/java/io/metersphere/project/Application.java index 427879ff1d..62a857c55f 100644 --- a/backend/services/project-management/src/test/java/io/metersphere/project/Application.java +++ b/backend/services/project-management/src/test/java/io/metersphere/project/Application.java @@ -19,7 +19,7 @@ import org.springframework.context.annotation.ComponentScan; MinioProperties.class }) @ServletComponentScan -@ComponentScan(basePackages = {"io.metersphere.sdk", "io.metersphere.project"}) +@ComponentScan(basePackages = {"io.metersphere.sdk", "io.metersphere.system", "io.metersphere.project"}) public class Application { public static void main(String[] args) { diff --git a/backend/services/project-management/src/test/java/io/metersphere/project/controller/ProjectLogControllerTests.java b/backend/services/project-management/src/test/java/io/metersphere/project/controller/ProjectLogControllerTests.java new file mode 100644 index 0000000000..01634c14c1 --- /dev/null +++ b/backend/services/project-management/src/test/java/io/metersphere/project/controller/ProjectLogControllerTests.java @@ -0,0 +1,66 @@ +package io.metersphere.project.controller; + + +import io.metersphere.sdk.base.BaseTest; +import io.metersphere.sdk.constants.PermissionConstants; +import io.metersphere.sdk.log.vo.OperationLogRequest; +import org.junit.jupiter.api.MethodOrderer; +import org.junit.jupiter.api.Order; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestMethodOrder; +import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; +import org.springframework.boot.test.context.SpringBootTest; + +import java.util.Arrays; +import java.util.HashMap; + +@SpringBootTest +@TestMethodOrder(MethodOrderer.OrderAnnotation.class) +@AutoConfigureMockMvc +public class ProjectLogControllerTests extends BaseTest { + + public static final String PROJECT = "PROJECT"; + public static final String PROJECT_USER_LIST = "/project/log/user/list"; + public static final String PROJECT_LOG_LIST = "/project/log/list"; + + + @Test + @Order(1) + public void testProjectUserList() throws Exception { + String keyword = "o"; + this.requestGetWithOkAndReturn(PROJECT_USER_LIST+ "/default-organization-member-test" + "?keyword=" + keyword); + } + + @Test + @Order(3) + public void testProjectLogList() throws Exception { + OperationLogRequest request = buildParam(PROJECT); + //项目级别 全部 + this.requestPostWithOkAndReturn(PROJECT_LOG_LIST, request); + + //其他查询条件 + request.setOperUser("admin"); + request.setType("add"); + request.setModule("SYSTEM_PARAMETER_SETTING"); + request.setContent("认证配置"); + request.setProjectIds(Arrays.asList("project_id_001", "project_id_002")); + request.setSort(new HashMap<>() {{ + put("createTime", "desc"); + }}); + this.requestPostWithOkAndReturn(PROJECT_LOG_LIST, request); + + requestPostPermissionTest(PermissionConstants.PROJECT_LOG_READ, PROJECT_LOG_LIST, request); + + } + + + private OperationLogRequest buildParam(String level) { + OperationLogRequest request = new OperationLogRequest(); + request.setCurrent(1); + request.setPageSize(10); + request.setStartTime(1689131059000l); + request.setEndTime(1689149059000l); + request.setLevel(level); + return request; + } +} diff --git a/backend/services/project-management/src/test/resources/bootstrap.properties b/backend/services/project-management/src/test/resources/bootstrap.properties index 62e94d254a..df85de4cef 100644 --- a/backend/services/project-management/src/test/resources/bootstrap.properties +++ b/backend/services/project-management/src/test/resources/bootstrap.properties @@ -8,6 +8,6 @@ embedded.mysql.collation=utf8mb4_general_ci # redis embedded.redis.enabled=true # kafka -embedded.kafka.enabled=false +embedded.kafka.enabled=true # minio embedded.minio.enabled=true \ No newline at end of file diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/mapper/ExtUserMapper.xml b/backend/services/system-setting/src/main/java/io/metersphere/system/mapper/ExtUserMapper.xml index a2c4bab3f8..f3a09e4cb1 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/mapper/ExtUserMapper.xml +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/mapper/ExtUserMapper.xml @@ -13,7 +13,7 @@