feat(项目管理): 项目管理-日志功能

This commit is contained in:
WangXu10 2023-09-05 11:21:09 +08:00 committed by fit2-zhao
parent 9cc14d7bb8
commit d6d1724f45
10 changed files with 151 additions and 5 deletions

View File

@ -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";

View File

@ -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

View File

@ -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=日志

View File

@ -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=基礎信息
permission.project_base_info.name=基礎信息
permission.project_log.name=日誌

View File

@ -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<User> 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<List<OperationLogResponse>> projectLogList(@Validated @RequestBody OperationLogRequest request) {
Page<Object> 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));
}
}

View File

@ -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"
}
]
}
]
}

View File

@ -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) {

View File

@ -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;
}
}

View File

@ -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

View File

@ -13,7 +13,7 @@
</select>
<select id="getUserListByOrgId" resultType="io.metersphere.system.domain.User">
SELECT DISTINCT
SELECT
u.id,
u.NAME,
u.email