fix(系统): 修复修改用户组多条日志问题
【【系统】组织与项目中修改组织 一个成员的用户组,生成很多 多余操作日志】 https://www.tapd.cn/55049933/bugtrace/bugs/view/1155049933001046450
This commit is contained in:
parent
0f715c095b
commit
1b3db8bbbc
|
@ -12,6 +12,7 @@ import io.metersphere.system.dto.request.UserInviteRequest;
|
|||
import io.metersphere.system.dto.sdk.OptionDTO;
|
||||
import io.metersphere.system.dto.user.UserExtendDTO;
|
||||
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.service.SimpleUserService;
|
||||
import io.metersphere.system.utils.PageUtils;
|
||||
|
@ -89,7 +90,7 @@ public class ProjectMemberController {
|
|||
@RequiresPermissions(PermissionConstants.PROJECT_USER_UPDATE)
|
||||
@CheckOwner(resourceId = "#request.getProjectId()", resourceType = "project")
|
||||
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}")
|
||||
|
@ -131,6 +132,6 @@ public class ProjectMemberController {
|
|||
@RequiresPermissions(PermissionConstants.ORGANIZATION_PROJECT_MEMBER_UPDATE)
|
||||
@CheckOwner(resourceId = "#request.getProjectId()", resourceType = "project")
|
||||
public void updateProjectMemberRole(@RequestBody ProjectMemberEditRequest request) {
|
||||
projectMemberService.updateMember(request, SessionUtils.getUserId());
|
||||
projectMemberService.updateMember(request, SessionUtils.getUserId(), "/project/member/update-member", OperationLogModule.SETTING_ORGANIZATION_PROJECT);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -171,7 +171,7 @@ public class ProjectMemberService {
|
|||
* @param request 请求参数
|
||||
* @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<>();
|
||||
// 项目不存在
|
||||
|
@ -214,7 +214,7 @@ public class ProjectMemberService {
|
|||
roleExample.createCriteria().andIdIn(oldRoleIds);
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -242,7 +242,7 @@ public class ProjectMemberService {
|
|||
example.createCriteria().andSourceIdEqualTo(projectId).andUserIdEqualTo(userId);
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -323,7 +323,7 @@ public class ProjectMemberService {
|
|||
roleExample.createCriteria().andIdIn(roleIds);
|
||||
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)) {
|
||||
|
@ -363,7 +363,7 @@ public class ProjectMemberService {
|
|||
// 操作记录
|
||||
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);
|
||||
}
|
||||
|
@ -416,7 +416,7 @@ public class ProjectMemberService {
|
|||
* @param method 请求方法
|
||||
* @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);
|
||||
User user = userMapper.selectByPrimaryKey(memberId);
|
||||
LogDTO dto = new LogDTO(
|
||||
|
@ -425,7 +425,7 @@ public class ProjectMemberService {
|
|||
memberId,
|
||||
createUserId,
|
||||
type,
|
||||
OperationLogModule.PROJECT_MANAGEMENT_PERMISSION_MEMBER,
|
||||
module,
|
||||
user.getName());
|
||||
dto.setPath(path);
|
||||
dto.setMethod(method);
|
||||
|
|
|
@ -10,6 +10,7 @@ import io.metersphere.system.dto.request.*;
|
|||
import io.metersphere.system.dto.sdk.OptionDTO;
|
||||
import io.metersphere.system.dto.user.response.UserInviteResponse;
|
||||
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.service.OrganizationService;
|
||||
import io.metersphere.system.service.SimpleUserService;
|
||||
|
@ -75,7 +76,7 @@ public class OrganizationController {
|
|||
@Operation(summary = "系统设置-组织-成员-更新用户")
|
||||
@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) {
|
||||
organizationService.updateMember(organizationMemberExtendRequest, SessionUtils.getUserId());
|
||||
organizationService.updateMember(organizationMemberExtendRequest, SessionUtils.getUserId(), "/organization/update-member", OperationLogModule.SETTING_ORGANIZATION_MEMBER);
|
||||
}
|
||||
|
||||
@PostMapping("/project/add-member")
|
||||
|
|
|
@ -10,6 +10,7 @@ import io.metersphere.system.dto.request.*;
|
|||
import io.metersphere.system.dto.sdk.OptionDTO;
|
||||
import io.metersphere.system.dto.user.UserExtendDTO;
|
||||
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.service.OrganizationService;
|
||||
import io.metersphere.system.service.SimpleUserService;
|
||||
|
@ -198,6 +199,6 @@ public class SystemOrganizationController {
|
|||
@Operation(summary = "系统设置-系统-组织与项目-组织-成员-更新成员用户组")
|
||||
@RequiresPermissions(PermissionConstants.SYSTEM_ORGANIZATION_PROJECT_MEMBER_UPDATE)
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -714,7 +714,7 @@ public class OrganizationService {
|
|||
* @param organizationMemberUpdateRequest 请求参数
|
||||
* @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();
|
||||
//校验组织是否存在
|
||||
checkOrgExistById(organizationId);
|
||||
|
@ -735,7 +735,7 @@ public class OrganizationService {
|
|||
List<LogDTO> logDTOList = new ArrayList<>();
|
||||
//更新用户组
|
||||
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();
|
||||
if (CollectionUtils.isNotEmpty(projectIds)) {
|
||||
|
@ -749,20 +749,6 @@ public class OrganizationService {
|
|||
userRoleRelationExample = new UserRoleRelationExample();
|
||||
userRoleRelationExample.createCriteria().andUserIdEqualTo(memberId).andSourceIdIn(projectInDBInOrgIds);
|
||||
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.setOrganizationId(organizationId);
|
||||
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;
|
||||
}
|
||||
|
||||
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();
|
||||
Map<String, UserRole> userRoleMap = checkUseRoleExist(userRoleIds, organizationId);
|
||||
|
@ -829,18 +804,17 @@ public class OrganizationService {
|
|||
UserRoleRelation userRoleRelation = buildUserRoleRelation(createUserId, memberId, organizationId, userRoleId, organizationId);
|
||||
userRoleRelation.setOrganizationId(organizationId);
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -283,12 +283,14 @@
|
|||
() => props.organizationId,
|
||||
() => {
|
||||
fetchData();
|
||||
getUserGroupOptions();
|
||||
}
|
||||
);
|
||||
watch(
|
||||
() => props.projectId,
|
||||
() => {
|
||||
fetchData();
|
||||
getUserGroupOptions();
|
||||
}
|
||||
);
|
||||
watch(
|
||||
|
|
Loading…
Reference in New Issue