refactor(权限管理): 修改 checkowner
This commit is contained in:
parent
781eed964b
commit
62f921bdec
|
@ -1,7 +1,6 @@
|
||||||
package io.metersphere.service;
|
package io.metersphere.service;
|
||||||
|
|
||||||
import io.metersphere.base.domain.Group;
|
import io.metersphere.base.domain.Group;
|
||||||
import io.metersphere.base.domain.Project;
|
|
||||||
import io.metersphere.base.domain.UserGroup;
|
import io.metersphere.base.domain.UserGroup;
|
||||||
import io.metersphere.base.mapper.ProjectMapper;
|
import io.metersphere.base.mapper.ProjectMapper;
|
||||||
import io.metersphere.base.mapper.ext.*;
|
import io.metersphere.base.mapper.ext.*;
|
||||||
|
@ -33,38 +32,20 @@ public class CheckPermissionService {
|
||||||
@Resource
|
@Resource
|
||||||
private ExtTestCaseReviewMapper extTestCaseReviewMapper;
|
private ExtTestCaseReviewMapper extTestCaseReviewMapper;
|
||||||
|
|
||||||
|
|
||||||
// public void checkReadOnlyUser() {
|
|
||||||
// String currentWorkspaceId = SessionUtils.getCurrentWorkspaceId();
|
|
||||||
// Set<String> 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) {
|
public void checkProjectOwner(String projectId) {
|
||||||
Set<String> workspaceIds = getUserRelatedWorkspaceIds();
|
Set<String> projectIds = getUserRelatedProjectIds();
|
||||||
Project project = projectMapper.selectByPrimaryKey(projectId);
|
if (CollectionUtils.isEmpty(projectIds)) {
|
||||||
if (project == null) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (CollectionUtils.isEmpty(workspaceIds)) {
|
if (!projectIds.contains(projectId)) {
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!workspaceIds.contains(project.getWorkspaceId())) {
|
|
||||||
throw new RuntimeException(Translator.get("check_owner_project"));
|
throw new RuntimeException(Translator.get("check_owner_project"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Set<String> getUserRelatedWorkspaceIds() {
|
private Set<String> getUserRelatedProjectIds() {
|
||||||
List<String> groupIds = Objects.requireNonNull(SessionUtils.getUser()).getGroups()
|
List<String> groupIds = Objects.requireNonNull(SessionUtils.getUser()).getGroups()
|
||||||
.stream()
|
.stream()
|
||||||
.filter(g -> StringUtils.equals(g.getType(), UserGroupType.WORKSPACE))
|
.filter(g -> StringUtils.equals(g.getType(), UserGroupType.PROJECT))
|
||||||
.map(Group::getId)
|
.map(Group::getId)
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
return Objects.requireNonNull(SessionUtils.getUser()).getUserGroups().stream()
|
return Objects.requireNonNull(SessionUtils.getUser()).getUserGroups().stream()
|
||||||
|
@ -78,7 +59,7 @@ public class CheckPermissionService {
|
||||||
if (StringUtils.equals("other", testId)) {
|
if (StringUtils.equals("other", testId)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Set<String> workspaceIds = getUserRelatedWorkspaceIds();
|
Set<String> workspaceIds = getUserRelatedProjectIds();
|
||||||
if (CollectionUtils.isEmpty(workspaceIds)) {
|
if (CollectionUtils.isEmpty(workspaceIds)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -95,7 +76,7 @@ public class CheckPermissionService {
|
||||||
if (StringUtils.equals("other", testId)) {
|
if (StringUtils.equals("other", testId)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Set<String> workspaceIds = getUserRelatedWorkspaceIds();
|
Set<String> workspaceIds = getUserRelatedProjectIds();
|
||||||
if (CollectionUtils.isEmpty(workspaceIds)) {
|
if (CollectionUtils.isEmpty(workspaceIds)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -107,7 +88,7 @@ public class CheckPermissionService {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void checkTestCaseOwner(String caseId) {
|
public void checkTestCaseOwner(String caseId) {
|
||||||
Set<String> workspaceIds = getUserRelatedWorkspaceIds();
|
Set<String> workspaceIds = getUserRelatedProjectIds();
|
||||||
if (CollectionUtils.isEmpty(workspaceIds)) {
|
if (CollectionUtils.isEmpty(workspaceIds)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -119,7 +100,7 @@ public class CheckPermissionService {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void checkTestPlanOwner(String planId) {
|
public void checkTestPlanOwner(String planId) {
|
||||||
Set<String> workspaceIds = getUserRelatedWorkspaceIds();
|
Set<String> workspaceIds = getUserRelatedProjectIds();
|
||||||
if (CollectionUtils.isEmpty(workspaceIds)) {
|
if (CollectionUtils.isEmpty(workspaceIds)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -130,7 +111,7 @@ public class CheckPermissionService {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void checkTestReviewOwner(String reviewId) {
|
public void checkTestReviewOwner(String reviewId) {
|
||||||
Set<String> workspaceIds = getUserRelatedWorkspaceIds();
|
Set<String> workspaceIds = getUserRelatedProjectIds();
|
||||||
if (CollectionUtils.isEmpty(workspaceIds)) {
|
if (CollectionUtils.isEmpty(workspaceIds)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue