fix(系统): 修复修改用户组多条日志问题

【【系统】组织与项目中修改组织 一个成员的用户组,生成很多 多余操作日志】
https://www.tapd.cn/55049933/bugtrace/bugs/view/1155049933001046450
This commit is contained in:
WangXu10 2024-09-18 14:53:17 +08:00 committed by Craftsman
parent 0f715c095b
commit 1b3db8bbbc
6 changed files with 29 additions and 50 deletions

View File

@ -12,6 +12,7 @@ import io.metersphere.system.dto.request.UserInviteRequest;
import io.metersphere.system.dto.sdk.OptionDTO; import io.metersphere.system.dto.sdk.OptionDTO;
import io.metersphere.system.dto.user.UserExtendDTO; import io.metersphere.system.dto.user.UserExtendDTO;
import io.metersphere.system.dto.user.response.UserInviteResponse; import io.metersphere.system.dto.user.response.UserInviteResponse;
import io.metersphere.system.log.constants.OperationLogModule;
import io.metersphere.system.security.CheckOwner; import io.metersphere.system.security.CheckOwner;
import io.metersphere.system.service.SimpleUserService; import io.metersphere.system.service.SimpleUserService;
import io.metersphere.system.utils.PageUtils; import io.metersphere.system.utils.PageUtils;
@ -89,7 +90,7 @@ public class ProjectMemberController {
@RequiresPermissions(PermissionConstants.PROJECT_USER_UPDATE) @RequiresPermissions(PermissionConstants.PROJECT_USER_UPDATE)
@CheckOwner(resourceId = "#request.getProjectId()", resourceType = "project") @CheckOwner(resourceId = "#request.getProjectId()", resourceType = "project")
public void updateMember(@RequestBody ProjectMemberEditRequest request) { public void updateMember(@RequestBody ProjectMemberEditRequest request) {
projectMemberService.updateMember(request, SessionUtils.getUserId()); projectMemberService.updateMember(request, SessionUtils.getUserId(), "/project/member/update", OperationLogModule.PROJECT_MANAGEMENT_PERMISSION_MEMBER);
} }
@GetMapping("/remove/{projectId}/{userId}") @GetMapping("/remove/{projectId}/{userId}")
@ -131,6 +132,6 @@ public class ProjectMemberController {
@RequiresPermissions(PermissionConstants.ORGANIZATION_PROJECT_MEMBER_UPDATE) @RequiresPermissions(PermissionConstants.ORGANIZATION_PROJECT_MEMBER_UPDATE)
@CheckOwner(resourceId = "#request.getProjectId()", resourceType = "project") @CheckOwner(resourceId = "#request.getProjectId()", resourceType = "project")
public void updateProjectMemberRole(@RequestBody ProjectMemberEditRequest request) { public void updateProjectMemberRole(@RequestBody ProjectMemberEditRequest request) {
projectMemberService.updateMember(request, SessionUtils.getUserId()); projectMemberService.updateMember(request, SessionUtils.getUserId(), "/project/member/update-member", OperationLogModule.SETTING_ORGANIZATION_PROJECT);
} }
} }

View File

@ -171,7 +171,7 @@ public class ProjectMemberService {
* @param request 请求参数 * @param request 请求参数
* @param currentUserId 当前用户ID * @param currentUserId 当前用户ID
*/ */
public void updateMember(ProjectMemberEditRequest request, String currentUserId) { public void updateMember(ProjectMemberEditRequest request, String currentUserId, String path, String module) {
// 操作记录 // 操作记录
List<LogDTO> logs = new ArrayList<>(); List<LogDTO> logs = new ArrayList<>();
// 项目不存在 // 项目不存在
@ -214,7 +214,7 @@ public class ProjectMemberService {
roleExample.createCriteria().andIdIn(oldRoleIds); roleExample.createCriteria().andIdIn(oldRoleIds);
oldRoles = userRoleMapper.selectByExample(roleExample); oldRoles = userRoleMapper.selectByExample(roleExample);
} }
setLog(request.getProjectId(), request.getUserId(), currentUserId, OperationLogType.UPDATE.name(), "/project/member/update", HttpMethodConstants.POST.name(), oldRoles, newRoles, logs); setLog(request.getProjectId(), request.getUserId(), currentUserId, OperationLogType.UPDATE.name(), path, HttpMethodConstants.POST.name(), oldRoles, newRoles, logs, module);
operationLogService.batchAdd(logs); operationLogService.batchAdd(logs);
} }
@ -242,7 +242,7 @@ public class ProjectMemberService {
example.createCriteria().andSourceIdEqualTo(projectId).andUserIdEqualTo(userId); example.createCriteria().andSourceIdEqualTo(projectId).andUserIdEqualTo(userId);
userRoleRelationMapper.deleteByExample(example); userRoleRelationMapper.deleteByExample(example);
// 操作记录 // 操作记录
setLog(projectId, userId, currentUserId, OperationLogType.DELETE.name(), "/project/member/remove", HttpMethodConstants.GET.name(), null, null, logs); setLog(projectId, userId, currentUserId, OperationLogType.DELETE.name(), "/project/member/remove", HttpMethodConstants.GET.name(), null, null, logs, OperationLogModule.PROJECT_MANAGEMENT_PERMISSION_MEMBER);
operationLogService.batchAdd(logs); operationLogService.batchAdd(logs);
} }
@ -323,7 +323,7 @@ public class ProjectMemberService {
roleExample.createCriteria().andIdIn(roleIds); roleExample.createCriteria().andIdIn(roleIds);
List<UserRole> userRoles = userRoleMapper.selectByExample(roleExample); List<UserRole> userRoles = userRoleMapper.selectByExample(roleExample);
// 追加了哪些用户组 // 追加了哪些用户组
setLog(request.getProjectId(), userId, currentUserId, operationType, path, HttpMethodConstants.POST.name(), null, userRoles, logs); setLog(request.getProjectId(), userId, currentUserId, operationType, path, HttpMethodConstants.POST.name(), null, userRoles, logs, OperationLogModule.PROJECT_MANAGEMENT_PERMISSION_MEMBER);
} }
}); });
if (!CollectionUtils.isEmpty(relations)) { if (!CollectionUtils.isEmpty(relations)) {
@ -363,7 +363,7 @@ public class ProjectMemberService {
// 操作记录 // 操作记录
userIds.forEach(userId -> { userIds.forEach(userId -> {
// 操作记录 // 操作记录
setLog(request.getProjectId(), userId, currentUserId, OperationLogType.DELETE.name(), "/project/member/remove", HttpMethodConstants.GET.name(), null, null, logs); setLog(request.getProjectId(), userId, currentUserId, OperationLogType.DELETE.name(), "/project/member/remove", HttpMethodConstants.GET.name(), null, null, logs, OperationLogModule.PROJECT_MANAGEMENT_PERMISSION_MEMBER);
}); });
operationLogService.batchAdd(logs); operationLogService.batchAdd(logs);
} }
@ -416,7 +416,7 @@ public class ProjectMemberService {
* @param method 请求方法 * @param method 请求方法
* @param logs 日志集合 * @param logs 日志集合
*/ */
private void setLog(String projectId, String memberId, String createUserId, String type, String path, String method, Object originalVal, Object modifiedVal, List<LogDTO> logs) { private void setLog(String projectId, String memberId, String createUserId, String type, String path, String method, Object originalVal, Object modifiedVal, List<LogDTO> logs, String module) {
Project project = projectMapper.selectByPrimaryKey(projectId); Project project = projectMapper.selectByPrimaryKey(projectId);
User user = userMapper.selectByPrimaryKey(memberId); User user = userMapper.selectByPrimaryKey(memberId);
LogDTO dto = new LogDTO( LogDTO dto = new LogDTO(
@ -425,7 +425,7 @@ public class ProjectMemberService {
memberId, memberId,
createUserId, createUserId,
type, type,
OperationLogModule.PROJECT_MANAGEMENT_PERMISSION_MEMBER, module,
user.getName()); user.getName());
dto.setPath(path); dto.setPath(path);
dto.setMethod(method); dto.setMethod(method);

View File

@ -10,6 +10,7 @@ import io.metersphere.system.dto.request.*;
import io.metersphere.system.dto.sdk.OptionDTO; import io.metersphere.system.dto.sdk.OptionDTO;
import io.metersphere.system.dto.user.response.UserInviteResponse; import io.metersphere.system.dto.user.response.UserInviteResponse;
import io.metersphere.system.log.annotation.Log; import io.metersphere.system.log.annotation.Log;
import io.metersphere.system.log.constants.OperationLogModule;
import io.metersphere.system.log.constants.OperationLogType; import io.metersphere.system.log.constants.OperationLogType;
import io.metersphere.system.service.OrganizationService; import io.metersphere.system.service.OrganizationService;
import io.metersphere.system.service.SimpleUserService; import io.metersphere.system.service.SimpleUserService;
@ -75,7 +76,7 @@ public class OrganizationController {
@Operation(summary = "系统设置-组织-成员-更新用户") @Operation(summary = "系统设置-组织-成员-更新用户")
@RequiresPermissions(value = {PermissionConstants.ORGANIZATION_MEMBER_UPDATE, PermissionConstants.PROJECT_USER_READ_ADD, PermissionConstants.PROJECT_USER_READ_DELETE}, logical = Logical.OR) @RequiresPermissions(value = {PermissionConstants.ORGANIZATION_MEMBER_UPDATE, PermissionConstants.PROJECT_USER_READ_ADD, PermissionConstants.PROJECT_USER_READ_DELETE}, logical = Logical.OR)
public void updateMember(@Validated @RequestBody OrganizationMemberUpdateRequest organizationMemberExtendRequest) { public void updateMember(@Validated @RequestBody OrganizationMemberUpdateRequest organizationMemberExtendRequest) {
organizationService.updateMember(organizationMemberExtendRequest, SessionUtils.getUserId()); organizationService.updateMember(organizationMemberExtendRequest, SessionUtils.getUserId(), "/organization/update-member", OperationLogModule.SETTING_ORGANIZATION_MEMBER);
} }
@PostMapping("/project/add-member") @PostMapping("/project/add-member")

View File

@ -10,6 +10,7 @@ import io.metersphere.system.dto.request.*;
import io.metersphere.system.dto.sdk.OptionDTO; import io.metersphere.system.dto.sdk.OptionDTO;
import io.metersphere.system.dto.user.UserExtendDTO; import io.metersphere.system.dto.user.UserExtendDTO;
import io.metersphere.system.log.annotation.Log; import io.metersphere.system.log.annotation.Log;
import io.metersphere.system.log.constants.OperationLogModule;
import io.metersphere.system.log.constants.OperationLogType; import io.metersphere.system.log.constants.OperationLogType;
import io.metersphere.system.service.OrganizationService; import io.metersphere.system.service.OrganizationService;
import io.metersphere.system.service.SimpleUserService; import io.metersphere.system.service.SimpleUserService;
@ -198,6 +199,6 @@ public class SystemOrganizationController {
@Operation(summary = "系统设置-系统-组织与项目-组织-成员-更新成员用户组") @Operation(summary = "系统设置-系统-组织与项目-组织-成员-更新成员用户组")
@RequiresPermissions(PermissionConstants.SYSTEM_ORGANIZATION_PROJECT_MEMBER_UPDATE) @RequiresPermissions(PermissionConstants.SYSTEM_ORGANIZATION_PROJECT_MEMBER_UPDATE)
public void updateMember(@Validated @RequestBody OrganizationMemberUpdateRequest organizationMemberExtendRequest) { public void updateMember(@Validated @RequestBody OrganizationMemberUpdateRequest organizationMemberExtendRequest) {
organizationService.updateMember(organizationMemberExtendRequest, SessionUtils.getUserId()); organizationService.updateMember(organizationMemberExtendRequest, SessionUtils.getUserId(), "/system/organization/update-member", OperationLogModule.SETTING_SYSTEM_ORGANIZATION);
} }
} }

View File

@ -714,7 +714,7 @@ public class OrganizationService {
* @param organizationMemberUpdateRequest 请求参数 * @param organizationMemberUpdateRequest 请求参数
* @param createUserId 创建人ID * @param createUserId 创建人ID
*/ */
public void updateMember(OrganizationMemberUpdateRequest organizationMemberUpdateRequest, String createUserId) { public void updateMember(OrganizationMemberUpdateRequest organizationMemberUpdateRequest, String createUserId, String path, String module) {
String organizationId = organizationMemberUpdateRequest.getOrganizationId(); String organizationId = organizationMemberUpdateRequest.getOrganizationId();
//校验组织是否存在 //校验组织是否存在
checkOrgExistById(organizationId); checkOrgExistById(organizationId);
@ -735,7 +735,7 @@ public class OrganizationService {
List<LogDTO> logDTOList = new ArrayList<>(); List<LogDTO> logDTOList = new ArrayList<>();
//更新用户组 //更新用户组
List<String> userRoleIds = organizationMemberUpdateRequest.getUserRoleIds(); List<String> userRoleIds = organizationMemberUpdateRequest.getUserRoleIds();
updateUserRoleRelation(createUserId, organizationId, user, userRoleIds, sqlSession, logDTOList); updateUserRoleRelation(createUserId, organizationId, user, userRoleIds, sqlSession, logDTOList, path, module);
//更新项目 //更新项目
List<String> projectIds = organizationMemberUpdateRequest.getProjectIds(); List<String> projectIds = organizationMemberUpdateRequest.getProjectIds();
if (CollectionUtils.isNotEmpty(projectIds)) { if (CollectionUtils.isNotEmpty(projectIds)) {
@ -749,20 +749,6 @@ public class OrganizationService {
userRoleRelationExample = new UserRoleRelationExample(); userRoleRelationExample = new UserRoleRelationExample();
userRoleRelationExample.createCriteria().andUserIdEqualTo(memberId).andSourceIdIn(projectInDBInOrgIds); userRoleRelationExample.createCriteria().andUserIdEqualTo(memberId).andSourceIdIn(projectInDBInOrgIds);
userRoleRelationMapper.deleteByExample(userRoleRelationExample); userRoleRelationMapper.deleteByExample(userRoleRelationExample);
//add Log
for (String projectInDBInOrgId : projectInDBInOrgIds) {
String path = "/organization/update-member";
LogDTO dto = new LogDTO(
projectInDBInOrgId,
organizationId,
memberId,
createUserId,
OperationLogType.UPDATE.name(),
OperationLogModule.PROJECT_MANAGEMENT_PERMISSION_MEMBER,
user.getName());
setLog(dto, path, logDTOList, "");
}
} }
} }
@ -789,17 +775,6 @@ public class OrganizationService {
UserRoleRelation userRoleRelation = buildUserRoleRelation(createUserId, memberId, projectId, InternalUserRole.PROJECT_MEMBER.getValue(), organizationId); UserRoleRelation userRoleRelation = buildUserRoleRelation(createUserId, memberId, projectId, InternalUserRole.PROJECT_MEMBER.getValue(), organizationId);
userRoleRelation.setOrganizationId(organizationId); userRoleRelation.setOrganizationId(organizationId);
userRoleRelationMapper.insert(userRoleRelation); userRoleRelationMapper.insert(userRoleRelation);
//add Log
String path = "/organization/update-member";
LogDTO dto = new LogDTO(
projectId,
organizationId,
memberId,
createUserId,
OperationLogType.UPDATE.name(),
OperationLogModule.PROJECT_MANAGEMENT_PERMISSION_MEMBER,
user.getName());
setLog(dto, path, logDTOList, userRoleRelation);
}); });
} }
@ -815,7 +790,7 @@ public class OrganizationService {
return userRoleRelation; return userRoleRelation;
} }
private void updateUserRoleRelation(String createUserId, String organizationId, User user, List<String> userRoleIds, SqlSession sqlSession, List<LogDTO> logDTOList) { private void updateUserRoleRelation(String createUserId, String organizationId, User user, List<String> userRoleIds, SqlSession sqlSession, List<LogDTO> logDTOList, String path, String module) {
//检查用户组是否是组织级别用户组 //检查用户组是否是组织级别用户组
String memberId = user.getId(); String memberId = user.getId();
Map<String, UserRole> userRoleMap = checkUseRoleExist(userRoleIds, organizationId); Map<String, UserRole> userRoleMap = checkUseRoleExist(userRoleIds, organizationId);
@ -829,18 +804,17 @@ public class OrganizationService {
UserRoleRelation userRoleRelation = buildUserRoleRelation(createUserId, memberId, organizationId, userRoleId, organizationId); UserRoleRelation userRoleRelation = buildUserRoleRelation(createUserId, memberId, organizationId, userRoleId, organizationId);
userRoleRelation.setOrganizationId(organizationId); userRoleRelation.setOrganizationId(organizationId);
userRoleRelationMapper.insert(userRoleRelation); userRoleRelationMapper.insert(userRoleRelation);
//add Log
String path = "/organization/update-member";
LogDTO dto = new LogDTO(
OperationLogConstants.ORGANIZATION,
organizationId,
memberId,
createUserId,
OperationLogType.UPDATE.name(),
OperationLogModule.SETTING_ORGANIZATION_MEMBER,
user.getName());
setLog(dto, path, logDTOList, userRoleRelation);
}); });
//add Log
LogDTO dto = new LogDTO(
OperationLogConstants.ORGANIZATION,
organizationId,
memberId,
createUserId,
OperationLogType.UPDATE.name(),
module,
user.getName());
setLog(dto, path, logDTOList, userRoleInDBInOrgIds);
} }
/** /**

View File

@ -283,12 +283,14 @@
() => props.organizationId, () => props.organizationId,
() => { () => {
fetchData(); fetchData();
getUserGroupOptions();
} }
); );
watch( watch(
() => props.projectId, () => props.projectId,
() => { () => {
fetchData(); fetchData();
getUserGroupOptions();
} }
); );
watch( watch(