From 62f921bdec1369b2677a19ddf300234582930911 Mon Sep 17 00:00:00 2001 From: "Captain.B" Date: Wed, 26 May 2021 12:10:04 +0800 Subject: [PATCH] =?UTF-8?q?refactor(=E6=9D=83=E9=99=90=E7=AE=A1=E7=90=86):?= =?UTF-8?q?=20=E4=BF=AE=E6=94=B9=20checkowner?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/CheckPermissionService.java | 39 +++++-------------- 1 file changed, 10 insertions(+), 29 deletions(-) diff --git a/backend/src/main/java/io/metersphere/service/CheckPermissionService.java b/backend/src/main/java/io/metersphere/service/CheckPermissionService.java index cd50a971c5..123afed15f 100644 --- a/backend/src/main/java/io/metersphere/service/CheckPermissionService.java +++ b/backend/src/main/java/io/metersphere/service/CheckPermissionService.java @@ -1,7 +1,6 @@ package io.metersphere.service; import io.metersphere.base.domain.Group; -import io.metersphere.base.domain.Project; import io.metersphere.base.domain.UserGroup; import io.metersphere.base.mapper.ProjectMapper; import io.metersphere.base.mapper.ext.*; @@ -33,38 +32,20 @@ public class CheckPermissionService { @Resource private ExtTestCaseReviewMapper extTestCaseReviewMapper; - -// public void checkReadOnlyUser() { -// String currentWorkspaceId = SessionUtils.getCurrentWorkspaceId(); -// Set collect = Objects.requireNonNull(SessionUtils.getUser()).getUserRoles().stream() -// .filter(ur -> -// StringUtils.equals(ur.getRoleId(), RoleConstants.TEST_VIEWER)) -// .map(UserRole::getSourceId) -// .filter(sourceId -> StringUtils.equals(currentWorkspaceId, sourceId)) -// .collect(Collectors.toSet()); -// if (CollectionUtils.isNotEmpty(collect)) { -// throw new RuntimeException(Translator.get("check_owner_read_only")); -// } -// } - public void checkProjectOwner(String projectId) { - Set workspaceIds = getUserRelatedWorkspaceIds(); - Project project = projectMapper.selectByPrimaryKey(projectId); - if (project == null) { + Set projectIds = getUserRelatedProjectIds(); + if (CollectionUtils.isEmpty(projectIds)) { return; } - if (CollectionUtils.isEmpty(workspaceIds)) { - return; - } - if (!workspaceIds.contains(project.getWorkspaceId())) { + if (!projectIds.contains(projectId)) { throw new RuntimeException(Translator.get("check_owner_project")); } } - private Set getUserRelatedWorkspaceIds() { + private Set getUserRelatedProjectIds() { List groupIds = Objects.requireNonNull(SessionUtils.getUser()).getGroups() .stream() - .filter(g -> StringUtils.equals(g.getType(), UserGroupType.WORKSPACE)) + .filter(g -> StringUtils.equals(g.getType(), UserGroupType.PROJECT)) .map(Group::getId) .collect(Collectors.toList()); return Objects.requireNonNull(SessionUtils.getUser()).getUserGroups().stream() @@ -78,7 +59,7 @@ public class CheckPermissionService { if (StringUtils.equals("other", testId)) { return; } - Set workspaceIds = getUserRelatedWorkspaceIds(); + Set workspaceIds = getUserRelatedProjectIds(); if (CollectionUtils.isEmpty(workspaceIds)) { return; } @@ -95,7 +76,7 @@ public class CheckPermissionService { if (StringUtils.equals("other", testId)) { return; } - Set workspaceIds = getUserRelatedWorkspaceIds(); + Set workspaceIds = getUserRelatedProjectIds(); if (CollectionUtils.isEmpty(workspaceIds)) { return; } @@ -107,7 +88,7 @@ public class CheckPermissionService { } public void checkTestCaseOwner(String caseId) { - Set workspaceIds = getUserRelatedWorkspaceIds(); + Set workspaceIds = getUserRelatedProjectIds(); if (CollectionUtils.isEmpty(workspaceIds)) { return; } @@ -119,7 +100,7 @@ public class CheckPermissionService { } public void checkTestPlanOwner(String planId) { - Set workspaceIds = getUserRelatedWorkspaceIds(); + Set workspaceIds = getUserRelatedProjectIds(); if (CollectionUtils.isEmpty(workspaceIds)) { return; } @@ -130,7 +111,7 @@ public class CheckPermissionService { } public void checkTestReviewOwner(String reviewId) { - Set workspaceIds = getUserRelatedWorkspaceIds(); + Set workspaceIds = getUserRelatedProjectIds(); if (CollectionUtils.isEmpty(workspaceIds)) { return; }