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_POOL = "SYSTEM_TEST_RESOURCE_POOL";
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 ORGANIZATION_USER_ROLE = "ORGANIZATION_USER_ROLE";
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_TEMPLATE_SETTINGS_FIELD = "ORGANIZATION_TEMPLATE_SETTINGS_FIELD";
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_API = "ORGANIZATION_TEMPLATE_SETTINGS_API";
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_REPORT = "UI_AUTOMATION_REPORT";
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_MEMBER = "SYSTEM_PROJECT_MEMBER";
public static final String ORGANIZATION_PROJECT = "ORGANIZATION_PROJECT";

View File

@ -38,7 +38,7 @@ public class GlobalUserRoleLogService {
null,
null,
OperationLogType.ADD.name(),
OperationLogModule.SYSTEM_PROJECT,
OperationLogModule.SETTING_SYSTEM_USER_GROUP,
request.getName());
dto.setOriginalValue(JSON.toJSONBytes(request));
@ -59,7 +59,7 @@ public class GlobalUserRoleLogService {
userRole.getId(),
userRole.getCreateUser(),
OperationLogType.UPDATE.name(),
OperationLogModule.SYSTEM_PROJECT,
OperationLogModule.SETTING_SYSTEM_USER_GROUP,
userRole.getName());
dto.setOriginalValue(JSON.toJSONBytes(userRole));
@ -77,7 +77,7 @@ public class GlobalUserRoleLogService {
request.getUserRoleId(),
userRole.getCreateUser(),
OperationLogType.UPDATE.name(),
OperationLogModule.SYSTEM_PROJECT,
OperationLogModule.SETTING_SYSTEM_USER_GROUP,
userRole.getName());
dto.setOriginalValue(JSON.toJSONBytes(request));
@ -103,7 +103,7 @@ public class GlobalUserRoleLogService {
userRole.getId(),
null,
OperationLogType.DELETE.name(),
OperationLogModule.SYSTEM_PROJECT,
OperationLogModule.SETTING_SYSTEM_USER_GROUP,
userRole.getName());
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.util.JSON;
import io.metersphere.system.domain.UserRole;
import io.metersphere.system.domain.UserRoleExample;
import io.metersphere.system.domain.UserRoleRelation;
import io.metersphere.system.mapper.UserRoleMapper;
import io.metersphere.system.mapper.UserRoleRelationMapper;
import io.metersphere.system.request.user.UserRoleBatchRelationRequest;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
/**
@ -34,10 +31,6 @@ public class GlobalUserRoleRelationLogService {
private BaseUserMapper baseUserMapper;
@Resource
private UserRoleMapper userRoleMapper;
@Resource
private UserService userService;
@Resource
private UserToolService userToolService;
/**
* 添加接口日志
@ -54,39 +47,14 @@ public class GlobalUserRoleRelationLogService {
OperationLogConstants.SYSTEM,
userRole.getId(),
null,
OperationLogType.ADD.name(),
OperationLogModule.SYSTEM_USER_ROLE_RELATION,
OperationLogType.UPDATE.name(),
OperationLogModule.SETTING_SYSTEM_USER_GROUP,
userRole.getName());
dto.setOriginalValue(JSON.toJSONBytes(users));
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,
userRole.getId(),
null,
OperationLogType.DELETE.name(),
OperationLogModule.SYSTEM_USER_ROLE_RELATION,
OperationLogType.UPDATE.name(),
OperationLogModule.SETTING_SYSTEM_USER_GROUP,
userRole.getName());
UserDTO userDTO = baseUserMapper.selectById(userRoleRelation.getUserId());

View File

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

View File

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

View File

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