From e941fe82f76fc90dc503eae7391f1bd365eafd44 Mon Sep 17 00:00:00 2001 From: song-cc-rock Date: Thu, 1 Feb 2024 16:02:49 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E7=B3=BB=E7=BB=9F=E8=AE=BE=E7=BD=AE):=20?= =?UTF-8?q?=E7=B3=BB=E7=BB=9F=E7=BB=84=E7=BB=87=E9=A1=B9=E7=9B=AE=E6=97=A5?= =?UTF-8?q?=E5=BF=97=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --bug=1034949 --user=宋昌昌 【系统设置】系统-日志-组织与项目移除成员-日志多了个删除项目的日志 https://www.tapd.cn/55049933/s/1458211 --- .../main/resources/i18n/commons.properties | 2 + .../resources/i18n/commons_en_US.properties | 2 + .../resources/i18n/commons_zh_CN.properties | 2 + .../resources/i18n/commons_zh_TW.properties | 2 + .../controller/OrganizationController.java | 10 ++-- .../SystemOrganizationController.java | 10 ++-- .../controller/SystemProjectController.java | 1 - .../system/mapper/ExtOrganizationMapper.xml | 7 +-- .../system/service/OrganizationService.java | 54 +++++++++---------- .../SystemOrganizationControllerTests.java | 10 ++-- 10 files changed, 53 insertions(+), 47 deletions(-) diff --git a/backend/framework/sdk/src/main/resources/i18n/commons.properties b/backend/framework/sdk/src/main/resources/i18n/commons.properties index 521cce2210..8a00b031d6 100644 --- a/backend/framework/sdk/src/main/resources/i18n/commons.properties +++ b/backend/framework/sdk/src/main/resources/i18n/commons.properties @@ -427,6 +427,8 @@ http_result_not_found=%s不存在 enum_value_valid_message=枚举值不合法,必须为 +#system organization +organization_member_log=组织成员 #system project project_admin=项目管理员 project_member=项目成员 diff --git a/backend/framework/sdk/src/main/resources/i18n/commons_en_US.properties b/backend/framework/sdk/src/main/resources/i18n/commons_en_US.properties index 7d01fe8e10..f3d27470dc 100644 --- a/backend/framework/sdk/src/main/resources/i18n/commons_en_US.properties +++ b/backend/framework/sdk/src/main/resources/i18n/commons_en_US.properties @@ -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 diff --git a/backend/framework/sdk/src/main/resources/i18n/commons_zh_CN.properties b/backend/framework/sdk/src/main/resources/i18n/commons_zh_CN.properties index b76a84475c..22f27bfe63 100644 --- a/backend/framework/sdk/src/main/resources/i18n/commons_zh_CN.properties +++ b/backend/framework/sdk/src/main/resources/i18n/commons_zh_CN.properties @@ -428,6 +428,8 @@ http_result_not_found=%s不存在 enum_value_valid_message=枚举值不合法,必须为 +#system organization +organization_member_log=组织成员 #system project project_admin=项目管理员 project_member=项目成员 diff --git a/backend/framework/sdk/src/main/resources/i18n/commons_zh_TW.properties b/backend/framework/sdk/src/main/resources/i18n/commons_zh_TW.properties index 42e656974d..3a6aa67b3d 100644 --- a/backend/framework/sdk/src/main/resources/i18n/commons_zh_TW.properties +++ b/backend/framework/sdk/src/main/resources/i18n/commons_zh_TW.properties @@ -426,6 +426,8 @@ http_result_forbidden=權限認證失敗 enum_value_valid_message=枚舉值不合法,必須為 +#system organization +organization_member_log=組織成員 #system project project_admin=項目管理員 project_member=項目成員 diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/controller/OrganizationController.java b/backend/services/system-setting/src/main/java/io/metersphere/system/controller/OrganizationController.java index 9a3690ad07..fe893f1509 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/controller/OrganizationController.java +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/controller/OrganizationController.java @@ -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}") diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/controller/SystemOrganizationController.java b/backend/services/system-setting/src/main/java/io/metersphere/system/controller/SystemOrganizationController.java index 3fa50458e1..20f4fec87d 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/controller/SystemOrganizationController.java +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/controller/SystemOrganizationController.java @@ -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") diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/controller/SystemProjectController.java b/backend/services/system-setting/src/main/java/io/metersphere/system/controller/SystemProjectController.java index 5fd0726238..094edd7d49 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/controller/SystemProjectController.java +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/controller/SystemProjectController.java @@ -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()); diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/mapper/ExtOrganizationMapper.xml b/backend/services/system-setting/src/main/java/io/metersphere/system/mapper/ExtOrganizationMapper.xml index e9953039be..51cc9f6e4a 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/mapper/ExtOrganizationMapper.xml +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/mapper/ExtOrganizationMapper.xml @@ -78,9 +78,9 @@ 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 diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/service/OrganizationService.java b/backend/services/system-setting/src/main/java/io/metersphere/system/service/OrganizationService.java index 69255343d8..731c6f2c24 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/service/OrganizationService.java +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/service/OrganizationService.java @@ -170,8 +170,8 @@ public class OrganizationService { UserExample example = new UserExample(); example.createCriteria().andIdIn(batchRequest.getUserIds()); List 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 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 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 batchDelLog(String organizationId, String userId) { List projectIds = getProjectIds(organizationId); UserRoleRelationExample example = new UserRoleRelationExample(); - if (CollectionUtils.isEmpty(projectIds)) { - return null; + List dtoList = new ArrayList<>(); + User user = userMapper.selectByPrimaryKey(userId); + if (CollectionUtils.isNotEmpty(projectIds)) { + // 项目层级日志 + example.createCriteria().andUserIdEqualTo(userId).andSourceIdIn(projectIds); + List 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 userRoleWidthProjectRelations = userRoleRelationMapper.selectByExample(example); + example = new UserRoleRelationExample(); example.createCriteria().andUserIdEqualTo(userId).andSourceIdEqualTo(organizationId); List userRoleWidthOrgRelations = userRoleRelationMapper.selectByExample(example); - List 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( diff --git a/backend/services/system-setting/src/test/java/io/metersphere/system/controller/SystemOrganizationControllerTests.java b/backend/services/system-setting/src/test/java/io/metersphere/system/controller/SystemOrganizationControllerTests.java index dd0568994d..0cebef3d68 100644 --- a/backend/services/system-setting/src/test/java/io/metersphere/system/controller/SystemOrganizationControllerTests.java +++ b/backend/services/system-setting/src/test/java/io/metersphere/system/controller/SystemOrganizationControllerTests.java @@ -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"); }