fix(系统设置): 系统组织项目日志问题

--bug=1034949 --user=宋昌昌 【系统设置】系统-日志-组织与项目移除成员-日志多了个删除项目的日志 https://www.tapd.cn/55049933/s/1458211
This commit is contained in:
song-cc-rock 2024-02-01 16:02:49 +08:00 committed by Craftsman
parent 82df20db05
commit e941fe82f7
10 changed files with 53 additions and 47 deletions

View File

@ -427,6 +427,8 @@ http_result_not_found=%s不存在
enum_value_valid_message=枚举值不合法,必须为
#system organization
organization_member_log=组织成员
#system project
project_admin=项目管理员
project_member=项目成员

View File

@ -430,6 +430,8 @@ http_result_forbidden=permission authentication failure
enum_value_valid_message=The enumeration value is invalid, must be
#system organization
organization_member_log=organization member
#system project
project_admin=Project admin
project_member=Project member

View File

@ -428,6 +428,8 @@ http_result_not_found=%s不存在
enum_value_valid_message=枚举值不合法,必须为
#system organization
organization_member_log=组织成员
#system project
project_admin=项目管理员
project_member=项目成员

View File

@ -426,6 +426,8 @@ http_result_forbidden=權限認證失敗
enum_value_valid_message=枚舉值不合法,必須為
#system organization
organization_member_log=組織成員
#system project
project_admin=項目管理員
project_member=項目成員

View File

@ -3,6 +3,8 @@ package io.metersphere.system.controller;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import io.metersphere.sdk.constants.PermissionConstants;
import io.metersphere.system.dto.OptionDisabledDTO;
import io.metersphere.system.dto.OrgUserExtend;
import io.metersphere.system.dto.request.OrgMemberExtendProjectRequest;
import io.metersphere.system.dto.request.OrganizationMemberExtendRequest;
import io.metersphere.system.dto.request.OrganizationMemberUpdateRequest;
@ -10,12 +12,10 @@ import io.metersphere.system.dto.request.OrganizationRequest;
import io.metersphere.system.dto.sdk.OptionDTO;
import io.metersphere.system.log.annotation.Log;
import io.metersphere.system.log.constants.OperationLogType;
import io.metersphere.system.service.OrganizationService;
import io.metersphere.system.utils.PageUtils;
import io.metersphere.system.utils.Pager;
import io.metersphere.system.utils.SessionUtils;
import io.metersphere.system.dto.OptionDisabledDTO;
import io.metersphere.system.dto.OrgUserExtend;
import io.metersphere.system.service.OrganizationService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
@ -24,8 +24,6 @@ import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
@ -87,7 +85,7 @@ public class OrganizationController {
@RequiresPermissions(PermissionConstants.ORGANIZATION_MEMBER_DELETE)
@Log(type = OperationLogType.DELETE, expression = "#msClass.batchDelLog(#organizationId, #userId)", msClass = OrganizationService.class)
public void removeMember(@PathVariable String organizationId, @PathVariable String userId) {
organizationService.removeMember(organizationId, userId);
organizationService.removeMember(organizationId, userId, SessionUtils.getUserId());
}
@GetMapping("/project/list/{organizationId}")

View File

@ -3,20 +3,20 @@ package io.metersphere.system.controller;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import io.metersphere.sdk.constants.PermissionConstants;
import io.metersphere.system.dto.sdk.OptionDTO;
import io.metersphere.system.dto.user.UserExtendDTO;
import io.metersphere.sdk.util.BeanUtils;
import io.metersphere.system.utils.PageUtils;
import io.metersphere.system.utils.Pager;
import io.metersphere.system.dto.OrganizationDTO;
import io.metersphere.system.dto.ProjectDTO;
import io.metersphere.system.dto.request.OrganizationMemberRequest;
import io.metersphere.system.dto.request.OrganizationProjectRequest;
import io.metersphere.system.dto.request.OrganizationRequest;
import io.metersphere.system.dto.request.ProjectRequest;
import io.metersphere.system.dto.sdk.OptionDTO;
import io.metersphere.system.dto.user.UserExtendDTO;
import io.metersphere.system.service.OrganizationService;
import io.metersphere.system.service.SystemProjectService;
import io.metersphere.system.service.UserService;
import io.metersphere.system.utils.PageUtils;
import io.metersphere.system.utils.Pager;
import io.metersphere.system.utils.SessionUtils;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
@ -86,7 +86,7 @@ public class SystemOrganizationController {
})
@RequiresPermissions(PermissionConstants.SYSTEM_ORGANIZATION_PROJECT_MEMBER_DELETE)
public void removeMember(@PathVariable String organizationId, @PathVariable String userId) {
organizationService.removeMember(organizationId, userId);
organizationService.removeMember(organizationId, userId, SessionUtils.getUserId());
}
@GetMapping("/default")

View File

@ -146,7 +146,6 @@ public class SystemProjectController {
@Parameter(name = "userId", description = "用户id", schema = @Schema(requiredMode = Schema.RequiredMode.REQUIRED))
@Parameter(name = "projectId", description = "项目id", schema = @Schema(requiredMode = Schema.RequiredMode.REQUIRED))
@RequiresPermissions(PermissionConstants.SYSTEM_ORGANIZATION_PROJECT_MEMBER_DELETE)
@Log(type = OperationLogType.DELETE, expression = "#msClass.deleteLog(#projectId)", msClass = SystemProjectLogService.class)
@CheckOwner(resourceId = "#projectId", resourceType = "project")
public int removeProjectMember(@PathVariable String projectId, @PathVariable String userId) {
return systemProjectService.removeProjectMember(projectId, userId, SessionUtils.getUserId());

View File

@ -78,9 +78,9 @@
</select>
<select id="listMemberByOrg" resultType="io.metersphere.system.dto.OrgUserExtend">
select temp.*
select temp.*, min(temp.memberTime) as groupTime
from (
select u.*, urr.role_id
select u.*, urr.role_id, urr.create_time as memberTime
from user_role_relation urr
join `user` u on urr.user_id = u.id and u.deleted = false
<where>
@ -96,6 +96,7 @@
order by u.update_time desc
) temp
group by temp.id
order by groupTime desc
</select>
<select id="selectListMemberByOrg" resultType="io.metersphere.system.dto.OptionDisabledDTO">
@ -136,7 +137,7 @@
<select id="getRelatedOrganizationIds" resultType="java.lang.String">
select distinct o.id
from user_role_relation urr join organization o on urr.organization_id = o.id
where user_id = #{userId}
where user_id = #{userId} and o.enable = true
</select>
<sql id="queryWhereCondition">

View File

@ -170,8 +170,8 @@ public class OrganizationService {
UserExample example = new UserExample();
example.createCriteria().andIdIn(batchRequest.getUserIds());
List<User> users = userMapper.selectByExample(example);
Organization organization = organizationMapper.selectByPrimaryKey(organizationMemberRequest.getOrganizationId());
setLog(organizationMemberRequest.getOrganizationId(), createUserId, OperationLogType.UPDATE.name(), organization.getName(), ADD_MEMBER_PATH, null, users, logs);
List<String> nameList = users.stream().map(User::getName).collect(Collectors.toList());
setLog(organizationMemberRequest.getOrganizationId(), createUserId, OperationLogType.ADD.name(), Translator.get("add") + Translator.get("organization_member_log") + ": " + StringUtils.join(nameList, ","), ADD_MEMBER_PATH, null, null, logs);
operationLogService.batchAdd(logs);
}
@ -218,7 +218,7 @@ public class OrganizationService {
* @param organizationId 组织ID
* @param userId 成员ID
*/
public void removeMember(String organizationId, String userId) {
public void removeMember(String organizationId, String userId, String currentUser) {
List<LogDTO> logs = new ArrayList<>();
checkOrgExistById(organizationId);
//删除组织下项目与成员的关系
@ -234,8 +234,7 @@ public class OrganizationService {
userRoleRelationMapper.deleteByExample(example);
// 操作记录
User user = userMapper.selectByPrimaryKey(userId);
Organization organization = organizationMapper.selectByPrimaryKey(organizationId);
setLog(organizationId, userId, OperationLogType.UPDATE.name(), organization.getName(), REMOVE_MEMBER_PATH, user, null, logs);
setLog(organizationId, currentUser, OperationLogType.DELETE.name(), Translator.get("delete") + Translator.get("organization_member_log") + ": " + user.getName(), REMOVE_MEMBER_PATH, user, null, logs);
operationLogService.batchAdd(logs);
}
@ -465,32 +464,33 @@ public class OrganizationService {
public List<LogDTO> batchDelLog(String organizationId, String userId) {
List<String> projectIds = getProjectIds(organizationId);
UserRoleRelationExample example = new UserRoleRelationExample();
if (CollectionUtils.isEmpty(projectIds)) {
return null;
List<LogDTO> dtoList = new ArrayList<>();
User user = userMapper.selectByPrimaryKey(userId);
if (CollectionUtils.isNotEmpty(projectIds)) {
// 项目层级日志
example.createCriteria().andUserIdEqualTo(userId).andSourceIdIn(projectIds);
List<UserRoleRelation> userRoleWidthProjectRelations = userRoleRelationMapper.selectByExample(example);
//记录项目日志
for (UserRoleRelation userRoleWidthProjectRelation : userRoleWidthProjectRelations) {
LogDTO dto = new LogDTO(
userRoleWidthProjectRelation.getSourceId(),
organizationId,
userId,
userRoleWidthProjectRelation.getCreateUser(),
OperationLogType.DELETE.name(),
OperationLogModule.PROJECT_MANAGEMENT_PERMISSION_MEMBER,
user.getName());
dto.setPath("/organization/remove-member/{organizationId}/{userId}");
dto.setMethod(HttpMethodConstants.POST.name());
dto.setOriginalValue(JSON.toJSONBytes(userRoleWidthProjectRelation));
dtoList.add(dto);
}
}
example.createCriteria().andUserIdEqualTo(userId).andSourceIdIn(projectIds);
List<UserRoleRelation> userRoleWidthProjectRelations = userRoleRelationMapper.selectByExample(example);
example = new UserRoleRelationExample();
example.createCriteria().andUserIdEqualTo(userId).andSourceIdEqualTo(organizationId);
List<UserRoleRelation> userRoleWidthOrgRelations = userRoleRelationMapper.selectByExample(example);
List<LogDTO> dtoList = new ArrayList<>();
User user = userMapper.selectByPrimaryKey(userId);
//记录项目日志
for (UserRoleRelation userRoleWidthProjectRelation : userRoleWidthProjectRelations) {
LogDTO dto = new LogDTO(
userRoleWidthProjectRelation.getSourceId(),
organizationId,
userId,
userRoleWidthProjectRelation.getCreateUser(),
OperationLogType.DELETE.name(),
OperationLogModule.PROJECT_MANAGEMENT_PERMISSION_MEMBER,
user.getName());
dto.setPath("/organization/remove-member/{organizationId}/{userId}");
dto.setMethod(HttpMethodConstants.POST.name());
dto.setOriginalValue(JSON.toJSONBytes(userRoleWidthProjectRelation));
dtoList.add(dto);
}
//记录组织日志
for (UserRoleRelation userRoleWidthOrgRelation : userRoleWidthOrgRelations) {
LogDTO dto = new LogDTO(

View File

@ -2,17 +2,17 @@ package io.metersphere.system.controller;
import io.metersphere.sdk.constants.PermissionConstants;
import io.metersphere.sdk.constants.SessionConstants;
import io.metersphere.system.dto.user.UserExtendDTO;
import io.metersphere.sdk.util.JSON;
import io.metersphere.system.utils.Pager;
import io.metersphere.system.base.BaseTest;
import io.metersphere.system.controller.handler.ResultHolder;
import io.metersphere.system.dto.OrganizationDTO;
import io.metersphere.system.dto.ProjectDTO;
import io.metersphere.system.log.constants.OperationLogType;
import io.metersphere.system.dto.request.OrganizationMemberRequest;
import io.metersphere.system.dto.request.OrganizationRequest;
import io.metersphere.system.dto.request.ProjectRequest;
import io.metersphere.system.dto.user.UserExtendDTO;
import io.metersphere.system.log.constants.OperationLogType;
import io.metersphere.system.utils.Pager;
import jakarta.annotation.Resource;
import org.apache.commons.lang3.StringUtils;
import org.junit.jupiter.api.*;
@ -220,7 +220,7 @@ public class SystemOrganizationControllerTests extends BaseTest{
organizationMemberRequest.setUserIds(List.of("admin", "default-admin"));
this.requestPost(ORGANIZATION_ADD_MEMBER, organizationMemberRequest, status().isOk());
// 日志校验
checkLog(organizationMemberRequest.getOrganizationId(), OperationLogType.UPDATE);
checkLog(organizationMemberRequest.getOrganizationId(), OperationLogType.ADD);
// 批量添加成员成功后, 验证是否添加成功
OrganizationRequest organizationRequest = new OrganizationRequest();
organizationRequest.setCurrent(1);
@ -313,7 +313,7 @@ public class SystemOrganizationControllerTests extends BaseTest{
public void testRemoveOrganizationMemberSuccess() throws Exception {
this.requestGet(ORGANIZATION_REMOVE_MEMBER + "/default-organization-3/admin", status().isOk());
// 日志校验
checkLog("default-organization-3", OperationLogType.UPDATE);
checkLog("default-organization-3", OperationLogType.DELETE);
// 权限校验
requestGetPermissionTest(PermissionConstants.SYSTEM_ORGANIZATION_PROJECT_MEMBER_DELETE, ORGANIZATION_REMOVE_MEMBER + "/default-organization-3/admin");
}