refactor(系统设置): 优化项目记录相关日志
This commit is contained in:
parent
6513e08b30
commit
684e3cf965
|
@ -2,11 +2,11 @@ package io.metersphere.project.service;
|
|||
|
||||
import io.metersphere.project.domain.Project;
|
||||
import io.metersphere.project.mapper.ProjectMapper;
|
||||
import io.metersphere.system.log.dto.LogDTO;
|
||||
import io.metersphere.system.dto.UpdateProjectRequest;
|
||||
import io.metersphere.sdk.util.JSON;
|
||||
import io.metersphere.system.dto.UpdateProjectRequest;
|
||||
import io.metersphere.system.log.constants.OperationLogModule;
|
||||
import io.metersphere.system.log.constants.OperationLogType;
|
||||
import io.metersphere.system.log.dto.LogDTO;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
@ -32,7 +32,7 @@ public class ProjectLogService {
|
|||
project.getCreateUser(),
|
||||
OperationLogType.UPDATE.name(),
|
||||
OperationLogModule.PROJECT_MANAGEMENT,
|
||||
project.getName());
|
||||
request.getName());
|
||||
|
||||
dto.setOriginalValue(JSON.toJSONBytes(project));
|
||||
return dto;
|
||||
|
|
|
@ -313,7 +313,11 @@ public class CommonProjectService {
|
|||
deleteExample.createCriteria().andSourceIdEqualTo(project.getId()).andUserIdIn(deleteIds).andRoleIdEqualTo(InternalUserRole.PROJECT_ADMIN.getValue());
|
||||
userRoleRelationMapper.selectByExample(deleteExample).forEach(userRoleRelation -> {
|
||||
User user = userMapper.selectByPrimaryKey(userRoleRelation.getUserId());
|
||||
LogDTO logDTO = new LogDTO(project.getId(), project.getOrganizationId(), userRoleRelation.getId(), updateUser, OperationLogType.DELETE.name(), module, Translator.get("delete") + Translator.get("project_admin") + ": " + user.getName());
|
||||
String logProjectId = OperationLogConstants.SYSTEM;
|
||||
if (StringUtils.equals(module, OperationLogModule.SETTING_ORGANIZATION_PROJECT)) {
|
||||
logProjectId = OperationLogConstants.ORGANIZATION;
|
||||
}
|
||||
LogDTO logDTO = new LogDTO(logProjectId, project.getOrganizationId(), userRoleRelation.getId(), updateUser, OperationLogType.DELETE.name(), module, Translator.get("delete") + Translator.get("project_admin") + ": " + user.getName());
|
||||
setLog(logDTO, path, HttpMethodConstants.POST.name(), logDTOList);
|
||||
});
|
||||
userRoleRelationMapper.deleteByExample(deleteExample);
|
||||
|
@ -332,7 +336,7 @@ public class CommonProjectService {
|
|||
deleteExample.createCriteria().andSourceIdEqualTo(project.getId()).andUserIdIn(orgUserIds).andRoleIdEqualTo(InternalUserRole.PROJECT_ADMIN.getValue());
|
||||
userRoleRelationMapper.selectByExample(deleteExample).forEach(userRoleRelation -> {
|
||||
User user = userMapper.selectByPrimaryKey(userRoleRelation.getUserId());
|
||||
LogDTO logDTO = new LogDTO(project.getId(), project.getOrganizationId(), userRoleRelation.getId(), updateUser, OperationLogType.DELETE.name(), module, Translator.get("delete") + Translator.get("project_admin") + ": " + user.getName());
|
||||
LogDTO logDTO = new LogDTO(OperationLogConstants.SYSTEM, project.getOrganizationId(), userRoleRelation.getId(), updateUser, OperationLogType.DELETE.name(), module, Translator.get("delete") + Translator.get("project_admin") + ": " + user.getName());
|
||||
setLog(logDTO, path, HttpMethodConstants.POST.name(), logDTOList);
|
||||
});
|
||||
userRoleRelationMapper.deleteByExample(deleteExample);
|
||||
|
@ -406,7 +410,11 @@ public class CommonProjectService {
|
|||
adminRole.setCreateUser(createUser);
|
||||
adminRole.setOrganizationId(project.getOrganizationId());
|
||||
userRoleRelations.add(adminRole);
|
||||
LogDTO logDTO = new LogDTO(projectId, project.getOrganizationId(), adminRole.getId(), createUser, type, module, content + Translator.get("project_admin") + ": " + nameMap.get(userId));
|
||||
String logProjectId = OperationLogConstants.SYSTEM;
|
||||
if (StringUtils.equals(module, OperationLogModule.SETTING_ORGANIZATION_PROJECT)) {
|
||||
logProjectId = OperationLogConstants.ORGANIZATION;
|
||||
}
|
||||
LogDTO logDTO = new LogDTO(logProjectId, project.getOrganizationId(), adminRole.getId(), createUser, type, module, content + Translator.get("project_admin") + ": " + nameMap.get(userId));
|
||||
setLog(logDTO, path, HttpMethodConstants.POST.name(), logDTOList);
|
||||
}
|
||||
});
|
||||
|
@ -462,7 +470,11 @@ public class CommonProjectService {
|
|||
memberRole.setCreateUser(createUser);
|
||||
memberRole.setOrganizationId(project.getOrganizationId());
|
||||
userRoleRelations.add(memberRole);
|
||||
LogDTO logDTO = new LogDTO(OperationLogConstants.SYSTEM, OperationLogConstants.SYSTEM, memberRole.getId(), createUser, type, module, content + Translator.get("project_member") + ": " + userMap.get(userId));
|
||||
String logProjectId = OperationLogConstants.SYSTEM;
|
||||
if (StringUtils.equals(module, OperationLogModule.SETTING_ORGANIZATION_PROJECT)) {
|
||||
logProjectId = OperationLogConstants.ORGANIZATION;
|
||||
}
|
||||
LogDTO logDTO = new LogDTO(logProjectId, OperationLogConstants.SYSTEM, memberRole.getId(), createUser, type, module, content + Translator.get("project_member") + ": " + userMap.get(userId));
|
||||
setLog(logDTO, path, HttpMethodConstants.POST.name(), logDTOList);
|
||||
}
|
||||
});
|
||||
|
@ -491,7 +503,11 @@ public class CommonProjectService {
|
|||
}
|
||||
List<LogDTO> logDTOList = new ArrayList<>();
|
||||
userRoleRelationMapper.selectByExample(userRoleRelationExample).forEach(userRoleRelation -> {
|
||||
LogDTO logDTO = new LogDTO(OperationLogConstants.SYSTEM, OperationLogConstants.SYSTEM, userRoleRelation.getId(), createUser, OperationLogType.DELETE.name(), module, Translator.get("delete") + Translator.get("project_member") + ": " + user.getName());
|
||||
String logProjectId = OperationLogConstants.SYSTEM;
|
||||
if (StringUtils.equals(module, OperationLogModule.SETTING_ORGANIZATION_PROJECT)) {
|
||||
logProjectId = OperationLogConstants.ORGANIZATION;
|
||||
}
|
||||
LogDTO logDTO = new LogDTO(logProjectId, OperationLogConstants.SYSTEM, userRoleRelation.getId(), createUser, OperationLogType.DELETE.name(), module, Translator.get("delete") + Translator.get("project_member") + ": " + user.getName());
|
||||
setLog(logDTO, path, HttpMethodConstants.GET.name(), logDTOList);
|
||||
});
|
||||
operationLogService.batchAdd(logDTOList);
|
||||
|
|
|
@ -3,13 +3,14 @@ package io.metersphere.system.service;
|
|||
import io.metersphere.project.domain.Project;
|
||||
import io.metersphere.project.mapper.ProjectMapper;
|
||||
import io.metersphere.sdk.constants.HttpMethodConstants;
|
||||
import io.metersphere.sdk.constants.OperationLogConstants;
|
||||
import io.metersphere.sdk.util.JSON;
|
||||
import io.metersphere.system.dto.AddProjectRequest;
|
||||
import io.metersphere.system.log.dto.LogDTO;
|
||||
import io.metersphere.system.dto.UpdateProjectNameRequest;
|
||||
import io.metersphere.system.dto.UpdateProjectRequest;
|
||||
import io.metersphere.system.log.constants.OperationLogModule;
|
||||
import io.metersphere.system.log.constants.OperationLogType;
|
||||
import io.metersphere.sdk.util.JSON;
|
||||
import io.metersphere.system.log.dto.LogDTO;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
@ -28,7 +29,7 @@ public class OrganizationProjectLogService {
|
|||
*/
|
||||
public LogDTO addLog(AddProjectRequest project) {
|
||||
LogDTO dto = new LogDTO(
|
||||
project.getId(),
|
||||
OperationLogConstants.ORGANIZATION,
|
||||
project.getOrganizationId(),
|
||||
null,
|
||||
null,
|
||||
|
@ -48,13 +49,13 @@ public class OrganizationProjectLogService {
|
|||
Project project = projectMapper.selectByPrimaryKey(request.getId());
|
||||
if (project != null) {
|
||||
LogDTO dto = new LogDTO(
|
||||
project.getId(),
|
||||
OperationLogConstants.ORGANIZATION,
|
||||
project.getOrganizationId(),
|
||||
project.getId(),
|
||||
project.getCreateUser(),
|
||||
OperationLogType.UPDATE.name(),
|
||||
OperationLogModule.SETTING_ORGANIZATION_PROJECT,
|
||||
project.getName());
|
||||
request.getName());
|
||||
|
||||
dto.setOriginalValue(JSON.toJSONBytes(project));
|
||||
return dto;
|
||||
|
@ -66,13 +67,13 @@ public class OrganizationProjectLogService {
|
|||
Project project = projectMapper.selectByPrimaryKey(request.getId());
|
||||
if (project != null) {
|
||||
LogDTO dto = new LogDTO(
|
||||
project.getId(),
|
||||
OperationLogConstants.ORGANIZATION,
|
||||
project.getOrganizationId(),
|
||||
project.getId(),
|
||||
project.getCreateUser(),
|
||||
OperationLogType.UPDATE.name(),
|
||||
OperationLogModule.SETTING_ORGANIZATION_PROJECT,
|
||||
project.getName());
|
||||
request.getName());
|
||||
|
||||
dto.setOriginalValue(JSON.toJSONBytes(project));
|
||||
return dto;
|
||||
|
@ -84,7 +85,7 @@ public class OrganizationProjectLogService {
|
|||
Project project = projectMapper.selectByPrimaryKey(id);
|
||||
if (project != null) {
|
||||
LogDTO dto = new LogDTO(
|
||||
project.getId(),
|
||||
OperationLogConstants.ORGANIZATION,
|
||||
project.getOrganizationId(),
|
||||
project.getId(),
|
||||
project.getCreateUser(),
|
||||
|
@ -109,7 +110,7 @@ public class OrganizationProjectLogService {
|
|||
Project project = projectMapper.selectByPrimaryKey(id);
|
||||
if (project != null) {
|
||||
LogDTO dto = new LogDTO(
|
||||
project.getId(),
|
||||
OperationLogConstants.ORGANIZATION,
|
||||
project.getOrganizationId(),
|
||||
id,
|
||||
project.getCreateUser(),
|
||||
|
@ -132,7 +133,7 @@ public class OrganizationProjectLogService {
|
|||
Project project = projectMapper.selectByPrimaryKey(id);
|
||||
if (project != null) {
|
||||
LogDTO dto = new LogDTO(
|
||||
project.getId(),
|
||||
OperationLogConstants.ORGANIZATION,
|
||||
project.getOrganizationId(),
|
||||
id,
|
||||
null,
|
||||
|
|
|
@ -4,13 +4,13 @@ import io.metersphere.project.domain.Project;
|
|||
import io.metersphere.project.mapper.ProjectMapper;
|
||||
import io.metersphere.sdk.constants.HttpMethodConstants;
|
||||
import io.metersphere.sdk.constants.OperationLogConstants;
|
||||
import io.metersphere.sdk.util.JSON;
|
||||
import io.metersphere.system.dto.AddProjectRequest;
|
||||
import io.metersphere.system.log.dto.LogDTO;
|
||||
import io.metersphere.system.dto.UpdateProjectNameRequest;
|
||||
import io.metersphere.system.dto.UpdateProjectRequest;
|
||||
import io.metersphere.system.log.constants.OperationLogModule;
|
||||
import io.metersphere.system.log.constants.OperationLogType;
|
||||
import io.metersphere.sdk.util.JSON;
|
||||
import io.metersphere.system.log.dto.LogDTO;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
@ -55,7 +55,7 @@ public class SystemProjectLogService {
|
|||
project.getCreateUser(),
|
||||
OperationLogType.UPDATE.name(),
|
||||
OperationLogModule.SETTING_SYSTEM_ORGANIZATION,
|
||||
project.getName());
|
||||
request.getName());
|
||||
|
||||
dto.setOriginalValue(JSON.toJSONBytes(project));
|
||||
return dto;
|
||||
|
@ -73,7 +73,7 @@ public class SystemProjectLogService {
|
|||
project.getCreateUser(),
|
||||
OperationLogType.UPDATE.name(),
|
||||
OperationLogModule.SETTING_SYSTEM_ORGANIZATION,
|
||||
project.getName());
|
||||
request.getName());
|
||||
|
||||
dto.setOriginalValue(JSON.toJSONBytes(project));
|
||||
return dto;
|
||||
|
|
|
@ -989,22 +989,22 @@ public class OrganizationProjectControllerTests extends BaseTest {
|
|||
project.setId("projectId2");
|
||||
project.setName("org-updateName");
|
||||
project.setOrganizationId(DEFAULT_ORGANIZATION_ID);
|
||||
this.requestPost(updateProject, project, ERROR_REQUEST_MATCHER);
|
||||
this.requestPost(updateName, project, ERROR_REQUEST_MATCHER);
|
||||
//参数组织Id为空
|
||||
project.setOrganizationId(null);
|
||||
this.requestPost(updateProject, project, BAD_REQUEST_MATCHER);
|
||||
this.requestPost(updateName, project, BAD_REQUEST_MATCHER);
|
||||
//项目Id为空
|
||||
project.setId(null);
|
||||
project.setOrganizationId(DEFAULT_ORGANIZATION_ID);
|
||||
this.requestPost(updateProject, project, BAD_REQUEST_MATCHER);
|
||||
this.requestPost(updateName, project, BAD_REQUEST_MATCHER);
|
||||
//项目名称为空
|
||||
project.setName(null);
|
||||
this.requestPost(updateProject, project, BAD_REQUEST_MATCHER);
|
||||
this.requestPost(updateName, project, BAD_REQUEST_MATCHER);
|
||||
//项目不存在
|
||||
project.setId("1111");
|
||||
project.setName("updateName");
|
||||
project.setOrganizationId(DEFAULT_ORGANIZATION_ID);
|
||||
this.requestPost(updateProject, project, ERROR_REQUEST_MATCHER);
|
||||
this.requestPost(updateName, project, ERROR_REQUEST_MATCHER);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1086,22 +1086,22 @@ public class SystemProjectControllerTests extends BaseTest {
|
|||
project.setId("projectId2");
|
||||
project.setName("updateName");
|
||||
project.setOrganizationId(DEFAULT_ORGANIZATION_ID);
|
||||
this.requestPost(updateProject, project, ERROR_REQUEST_MATCHER);
|
||||
this.requestPost(updateName, project, ERROR_REQUEST_MATCHER);
|
||||
//参数组织Id为空
|
||||
project.setOrganizationId(null);
|
||||
this.requestPost(updateProject, project, BAD_REQUEST_MATCHER);
|
||||
this.requestPost(updateName, project, BAD_REQUEST_MATCHER);
|
||||
//项目Id为空
|
||||
project.setId(null);
|
||||
project.setOrganizationId(DEFAULT_ORGANIZATION_ID);
|
||||
this.requestPost(updateProject, project, BAD_REQUEST_MATCHER);
|
||||
this.requestPost(updateName, project, BAD_REQUEST_MATCHER);
|
||||
//项目名称为空
|
||||
project.setName(null);
|
||||
this.requestPost(updateProject, project, BAD_REQUEST_MATCHER);
|
||||
this.requestPost(updateName, project, BAD_REQUEST_MATCHER);
|
||||
//项目不存在
|
||||
project.setId("1111");
|
||||
project.setName("updateName");
|
||||
project.setOrganizationId(DEFAULT_ORGANIZATION_ID);
|
||||
this.requestPost(updateProject, project, ERROR_REQUEST_MATCHER);
|
||||
this.requestPost(updateName, project, ERROR_REQUEST_MATCHER);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue