fix(系统设置): 部分操作日志显示有误

This commit is contained in:
jianxing 2023-08-28 11:54:40 +08:00 committed by 刘瑞斌
parent 8b5c5d1af6
commit 1403e4f72e
6 changed files with 32 additions and 61 deletions

View File

@ -6,15 +6,12 @@ public class OperationLogModule {
public static final String SYSTEM_TEST_RESOURCE = "SYSTEM_TEST_RESOURCE"; public static final String SYSTEM_TEST_RESOURCE = "SYSTEM_TEST_RESOURCE";
public static final String SYSTEM_TEST_RESOURCE_POOL = "SYSTEM_TEST_RESOURCE_POOL"; public static final String SYSTEM_TEST_RESOURCE_POOL = "SYSTEM_TEST_RESOURCE_POOL";
public static final String SYSTEM_USER = "SYSTEM_USER"; public static final String SYSTEM_USER = "SYSTEM_USER";
public static final String SYSTEM_USER_ROLE = "SYSTEM_USER_ROLE";
public static final String SYSTEM_USER_ROLE_RELATION = "SYSTEM_USER_ROLE_RELATION";
public static final String SYSTEM_ORGANIZATION = "SYSTEM_ORGANIZATION"; public static final String SYSTEM_ORGANIZATION = "SYSTEM_ORGANIZATION";
public static final String ORGANIZATION_USER_ROLE = "ORGANIZATION_USER_ROLE"; public static final String ORGANIZATION_USER_ROLE = "ORGANIZATION_USER_ROLE";
public static final String ORGANIZATION_TEMPLATE_SETTINGS = "ORGANIZATION_TEMPLATE_SETTINGS"; public static final String ORGANIZATION_TEMPLATE_SETTINGS = "ORGANIZATION_TEMPLATE_SETTINGS";
public static final String ORGANIZATION_MESSAGE_SETTINGS = "ORGANIZATION_MESSAGE_SETTINGS"; public static final String ORGANIZATION_MESSAGE_SETTINGS = "ORGANIZATION_MESSAGE_SETTINGS";
public static final String ORGANIZATION_TEMPLATE_SETTINGS_FIELD = "ORGANIZATION_TEMPLATE_SETTINGS_FIELD"; public static final String ORGANIZATION_TEMPLATE_SETTINGS_FIELD = "ORGANIZATION_TEMPLATE_SETTINGS_FIELD";
public static final String ORGANIZATION_TEMPLATE_SETTINGS_ISSUE = "ORGANIZATION_TEMPLATE_SETTINGS_ISSUE"; public static final String ORGANIZATION_TEMPLATE_SETTINGS_ISSUE = "ORGANIZATION_TEMPLATE_SETTINGS_ISSUE";
public static final String ORGANIZATION_SERVICE_INTEGRATION = "ORGANIZATION_SERVICE_INTEGRATION";
public static final String ORGANIZATION_TEMPLATE_SETTINGS_CASE = "ORGANIZATION_TEMPLATE_SETTINGS_CASE"; public static final String ORGANIZATION_TEMPLATE_SETTINGS_CASE = "ORGANIZATION_TEMPLATE_SETTINGS_CASE";
public static final String ORGANIZATION_TEMPLATE_SETTINGS_API = "ORGANIZATION_TEMPLATE_SETTINGS_API"; public static final String ORGANIZATION_TEMPLATE_SETTINGS_API = "ORGANIZATION_TEMPLATE_SETTINGS_API";
public static final String ORGANIZATION_MEMBER = "ORGANIZATION_MEMBER"; public static final String ORGANIZATION_MEMBER = "ORGANIZATION_MEMBER";
@ -49,7 +46,6 @@ public class OperationLogModule {
public static final String UI_AUTOMATION = "UI_AUTOMATION"; public static final String UI_AUTOMATION = "UI_AUTOMATION";
public static final String UI_AUTOMATION_REPORT = "UI_AUTOMATION_REPORT"; public static final String UI_AUTOMATION_REPORT = "UI_AUTOMATION_REPORT";
public static final String UI_AUTOMATION_SCHEDULE = "UI_AUTOMATION_SCHEDULE"; public static final String UI_AUTOMATION_SCHEDULE = "UI_AUTOMATION_SCHEDULE";
public static final String SYSTEM_PLUGIN = "SYSTEM_PLUGIN";
public static final String SYSTEM_PROJECT = "SYSTEM_PROJECT"; public static final String SYSTEM_PROJECT = "SYSTEM_PROJECT";
public static final String SYSTEM_PROJECT_MEMBER = "SYSTEM_PROJECT_MEMBER"; public static final String SYSTEM_PROJECT_MEMBER = "SYSTEM_PROJECT_MEMBER";
public static final String ORGANIZATION_PROJECT = "ORGANIZATION_PROJECT"; public static final String ORGANIZATION_PROJECT = "ORGANIZATION_PROJECT";

View File

@ -38,7 +38,7 @@ public class GlobalUserRoleLogService {
null, null,
null, null,
OperationLogType.ADD.name(), OperationLogType.ADD.name(),
OperationLogModule.SYSTEM_PROJECT, OperationLogModule.SETTING_SYSTEM_USER_GROUP,
request.getName()); request.getName());
dto.setOriginalValue(JSON.toJSONBytes(request)); dto.setOriginalValue(JSON.toJSONBytes(request));
@ -59,7 +59,7 @@ public class GlobalUserRoleLogService {
userRole.getId(), userRole.getId(),
userRole.getCreateUser(), userRole.getCreateUser(),
OperationLogType.UPDATE.name(), OperationLogType.UPDATE.name(),
OperationLogModule.SYSTEM_PROJECT, OperationLogModule.SETTING_SYSTEM_USER_GROUP,
userRole.getName()); userRole.getName());
dto.setOriginalValue(JSON.toJSONBytes(userRole)); dto.setOriginalValue(JSON.toJSONBytes(userRole));
@ -77,7 +77,7 @@ public class GlobalUserRoleLogService {
request.getUserRoleId(), request.getUserRoleId(),
userRole.getCreateUser(), userRole.getCreateUser(),
OperationLogType.UPDATE.name(), OperationLogType.UPDATE.name(),
OperationLogModule.SYSTEM_PROJECT, OperationLogModule.SETTING_SYSTEM_USER_GROUP,
userRole.getName()); userRole.getName());
dto.setOriginalValue(JSON.toJSONBytes(request)); dto.setOriginalValue(JSON.toJSONBytes(request));
@ -103,7 +103,7 @@ public class GlobalUserRoleLogService {
userRole.getId(), userRole.getId(),
null, null,
OperationLogType.DELETE.name(), OperationLogType.DELETE.name(),
OperationLogModule.SYSTEM_PROJECT, OperationLogModule.SETTING_SYSTEM_USER_GROUP,
userRole.getName()); userRole.getName());
dto.setOriginalValue(JSON.toJSONBytes(userRole)); dto.setOriginalValue(JSON.toJSONBytes(userRole));

View File

@ -10,15 +10,12 @@ import io.metersphere.sdk.log.constants.OperationLogType;
import io.metersphere.sdk.mapper.BaseUserMapper; import io.metersphere.sdk.mapper.BaseUserMapper;
import io.metersphere.sdk.util.JSON; import io.metersphere.sdk.util.JSON;
import io.metersphere.system.domain.UserRole; import io.metersphere.system.domain.UserRole;
import io.metersphere.system.domain.UserRoleExample;
import io.metersphere.system.domain.UserRoleRelation; import io.metersphere.system.domain.UserRoleRelation;
import io.metersphere.system.mapper.UserRoleMapper; import io.metersphere.system.mapper.UserRoleMapper;
import io.metersphere.system.mapper.UserRoleRelationMapper; import io.metersphere.system.mapper.UserRoleRelationMapper;
import io.metersphere.system.request.user.UserRoleBatchRelationRequest;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List; import java.util.List;
/** /**
@ -34,10 +31,6 @@ public class GlobalUserRoleRelationLogService {
private BaseUserMapper baseUserMapper; private BaseUserMapper baseUserMapper;
@Resource @Resource
private UserRoleMapper userRoleMapper; private UserRoleMapper userRoleMapper;
@Resource
private UserService userService;
@Resource
private UserToolService userToolService;
/** /**
* 添加接口日志 * 添加接口日志
@ -54,39 +47,14 @@ public class GlobalUserRoleRelationLogService {
OperationLogConstants.SYSTEM, OperationLogConstants.SYSTEM,
userRole.getId(), userRole.getId(),
null, null,
OperationLogType.ADD.name(), OperationLogType.UPDATE.name(),
OperationLogModule.SYSTEM_USER_ROLE_RELATION, OperationLogModule.SETTING_SYSTEM_USER_GROUP,
userRole.getName()); userRole.getName());
dto.setOriginalValue(JSON.toJSONBytes(users)); dto.setOriginalValue(JSON.toJSONBytes(users));
return dto; return dto;
} }
public List<LogDTO> batchAddLog(UserRoleBatchRelationRequest request) {
UserRoleExample example = new UserRoleExample();
example.createCriteria().andIdIn(request.getRoleIds());
List<UserRole> userRoles = userRoleMapper.selectByExample(example);
List<String> userIds = userToolService.getBatchUserIds(request);
List<OptionDTO> users = baseUserMapper.selectUserOptionByIds(userIds);
List<LogDTO> returnList = new ArrayList<>();
for (UserRole userRole : userRoles) {
LogDTO dto = new LogDTO(
OperationLogConstants.SYSTEM,
OperationLogConstants.SYSTEM,
userRole.getId(),
null,
OperationLogType.ADD.name(),
OperationLogModule.SYSTEM_USER_ROLE_RELATION,
userRole.getName());
dto.setOriginalValue(JSON.toJSONBytes(users));
returnList.add(dto);
}
return returnList;
}
/** /**
* 删除接口日志 * 删除接口日志
* *
@ -101,8 +69,8 @@ public class GlobalUserRoleRelationLogService {
OperationLogConstants.SYSTEM, OperationLogConstants.SYSTEM,
userRole.getId(), userRole.getId(),
null, null,
OperationLogType.DELETE.name(), OperationLogType.UPDATE.name(),
OperationLogModule.SYSTEM_USER_ROLE_RELATION, OperationLogModule.SETTING_SYSTEM_USER_GROUP,
userRole.getName()); userRole.getName());
UserDTO userDTO = baseUserMapper.selectById(userRoleRelation.getUserId()); UserDTO userDTO = baseUserMapper.selectById(userRoleRelation.getUserId());

View File

@ -29,7 +29,7 @@ public class PluginLogService {
null, null,
null, null,
OperationLogType.ADD.name(), OperationLogType.ADD.name(),
OperationLogModule.SYSTEM_PLUGIN, OperationLogModule.SETTING_SYSTEM_PLUGIN_MANAGEMENT,
request.getName()); request.getName());
dto.setOriginalValue(JSON.toJSONBytes(request)); dto.setOriginalValue(JSON.toJSONBytes(request));
return dto; return dto;
@ -43,7 +43,7 @@ public class PluginLogService {
plugin.getId(), plugin.getId(),
null, null,
OperationLogType.UPDATE.name(), OperationLogType.UPDATE.name(),
OperationLogModule.SYSTEM_PLUGIN, OperationLogModule.SETTING_SYSTEM_PLUGIN_MANAGEMENT,
plugin.getName()); plugin.getName());
dto.setOriginalValue(JSON.toJSONBytes(plugin)); dto.setOriginalValue(JSON.toJSONBytes(plugin));
return dto; return dto;
@ -60,7 +60,7 @@ public class PluginLogService {
plugin.getId(), plugin.getId(),
null, null,
OperationLogType.DELETE.name(), OperationLogType.DELETE.name(),
OperationLogModule.SYSTEM_PLUGIN, OperationLogModule.SETTING_SYSTEM_PLUGIN_MANAGEMENT,
plugin.getName()); plugin.getName());
dto.setOriginalValue(JSON.toJSONBytes(plugin)); dto.setOriginalValue(JSON.toJSONBytes(plugin));
return dto; return dto;

View File

@ -1,5 +1,6 @@
package io.metersphere.system.service; package io.metersphere.system.service;
import io.metersphere.sdk.service.PluginLoadService;
import io.metersphere.system.domain.ServiceIntegration; import io.metersphere.system.domain.ServiceIntegration;
import io.metersphere.system.request.ServiceIntegrationUpdateRequest; import io.metersphere.system.request.ServiceIntegrationUpdateRequest;
import io.metersphere.sdk.constants.OperationLogConstants; import io.metersphere.sdk.constants.OperationLogConstants;
@ -20,32 +21,38 @@ public class ServiceIntegrationLogService {
@Resource @Resource
private ServiceIntegrationService serviceIntegrationService; private ServiceIntegrationService serviceIntegrationService;
@Resource
private PluginLoadService pluginLoadService;
public LogDTO addLog(ServiceIntegrationUpdateRequest request) { public LogDTO addLog(ServiceIntegrationUpdateRequest request) {
LogDTO dto = new LogDTO( LogDTO dto = new LogDTO(
OperationLogConstants.SYSTEM, OperationLogConstants.ORGANIZATION,
OperationLogConstants.SYSTEM, null,
null, null,
null, null,
OperationLogType.ADD.name(), OperationLogType.ADD.name(),
OperationLogModule.ORGANIZATION_SERVICE_INTEGRATION, OperationLogModule.SETTING_ORGANIZATION_SERVICE,
"创建服务集成"); getName(request.getPluginId()));
dto.setOriginalValue(JSON.toJSONBytes(request)); dto.setOriginalValue(JSON.toJSONBytes(request));
return dto; return dto;
} }
private String getName(String pluginId) {
return pluginLoadService.getPlatformPluginInstance(pluginId).getName();
}
public LogDTO updateLog(ServiceIntegrationUpdateRequest request) { public LogDTO updateLog(ServiceIntegrationUpdateRequest request) {
ServiceIntegration serviceIntegration = serviceIntegrationService.get(request.getId()); ServiceIntegration serviceIntegration = serviceIntegrationService.get(request.getId());
LogDTO dto = null; LogDTO dto = null;
if (serviceIntegration != null) { if (serviceIntegration != null) {
dto = new LogDTO( dto = new LogDTO(
OperationLogConstants.SYSTEM, OperationLogConstants.ORGANIZATION,
OperationLogConstants.SYSTEM, null,
serviceIntegration.getId(), serviceIntegration.getId(),
null, null,
OperationLogType.UPDATE.name(), OperationLogType.UPDATE.name(),
OperationLogModule.ORGANIZATION_SERVICE_INTEGRATION, OperationLogModule.SETTING_ORGANIZATION_SERVICE,
"更新服务集成"); getName(serviceIntegration.getPluginId()));
dto.setOriginalValue(JSON.toJSONBytes(serviceIntegration)); dto.setOriginalValue(JSON.toJSONBytes(serviceIntegration));
} }
return dto; return dto;
@ -57,13 +64,13 @@ public class ServiceIntegrationLogService {
return null; return null;
} }
LogDTO dto = new LogDTO( LogDTO dto = new LogDTO(
OperationLogConstants.SYSTEM, OperationLogConstants.ORGANIZATION,
OperationLogConstants.SYSTEM, null,
serviceIntegration.getId(), serviceIntegration.getId(),
null, null,
OperationLogType.DELETE.name(), OperationLogType.DELETE.name(),
OperationLogModule.ORGANIZATION_SERVICE_INTEGRATION, OperationLogModule.SETTING_ORGANIZATION_SERVICE,
"删除服务集成"); getName(serviceIntegration.getPluginId()));
dto.setOriginalValue(JSON.toJSONBytes(serviceIntegration)); dto.setOriginalValue(JSON.toJSONBytes(serviceIntegration));
return dto; return dto;
} }

View File

@ -122,7 +122,7 @@ class GlobalUserRoleRelationControllerTests extends BaseTest {
addUserRoleRelation = userRoleRelations.get(0); addUserRoleRelation = userRoleRelations.get(0);
// @@校验日志 // @@校验日志
checkLog(addUserRoleRelation.getRoleId(), OperationLogType.ADD); checkLog(addUserRoleRelation.getRoleId(), OperationLogType.UPDATE);
// @@重复添加校验 // @@重复添加校验
request.setUserIds(Arrays.asList(ADMIN.getValue())); request.setUserIds(Arrays.asList(ADMIN.getValue()));
@ -182,7 +182,7 @@ class GlobalUserRoleRelationControllerTests extends BaseTest {
Assertions.assertNull(userRoleRelation); Assertions.assertNull(userRoleRelation);
// @@校验日志 // @@校验日志
checkLog(addUserRoleRelation.getRoleId(), OperationLogType.DELETE); checkLog(addUserRoleRelation.getRoleId(), OperationLogType.UPDATE);
// @@操作非系统级别用户组异常 // @@操作非系统级别用户组异常
assertErrorCode(this.requestGet(DEFAULT_DELETE, getNonSystemUserRoleRelation().getId()), assertErrorCode(this.requestGet(DEFAULT_DELETE, getNonSystemUserRoleRelation().getId()),