refactor(系统设置): 系统日志调整

This commit is contained in:
WangXu10 2023-08-01 14:04:18 +08:00 committed by WangXu10
parent 0c165eb746
commit 7df2b2d9d0
12 changed files with 54 additions and 44 deletions

View File

@ -2,4 +2,5 @@ package io.metersphere.sdk.constants;
public class OperationLogConstants {
public static final String SYSTEM = "SYSTEM";
public static final String ORGANIZATION = "ORGANIZATION";
}

View File

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

View File

@ -22,10 +22,10 @@
AND t.create_time BETWEEN #{request.startTime} AND #{request.endTime}
</if>
<if test="request.level != null and request.level != 'system'">
AND t.project_id != 'system'
AND t.project_id <![CDATA[<>]]> 'SYSTEM'
</if>
<if test="request.level != null and request.level == 'project'">
AND t.project_id <![CDATA[<>]]> ''
AND t.project_id <![CDATA[<>]]> 'ORGANIZATION'
</if>
<if test="request.projectIds != null and request.projectIds.size > 0 ">
AND t.project_id IN

View File

@ -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> systemParameter) {
List<SystemParameter> 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> systemParameter) {
List<SystemParameter> originalValue = getOriginalValue(systemParameter);
LogDTO dto = new LogDTO(
"system",
"",
OperationLogConstants.SYSTEM,
OperationLogConstants.SYSTEM,
"system-parameter",
null,
OperationLogType.ADD.name(),

View File

@ -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(),

View File

@ -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<LogDTO> logs) {
LogDTO dto = new LogDTO(
"system",
"system",
OperationLogConstants.SYSTEM,
OperationLogConstants.SYSTEM,
organizationId,
createUser,
type,

View File

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

View File

@ -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<LogDTO> logDTOList) {
LogDTO dto = new LogDTO(
"system",
"system",
OperationLogConstants.SYSTEM,
OperationLogConstants.SYSTEM,
projectId,
userId,
type,

View File

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

View File

@ -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(),

View File

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

View File

@ -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');