fix: 修复 check owner project 时出现的问题
This commit is contained in:
parent
61f78bb4d0
commit
181b5c11cc
|
@ -3,20 +3,25 @@ package io.metersphere.service;
|
|||
import io.metersphere.api.dto.APITestResult;
|
||||
import io.metersphere.api.dto.QueryAPITestRequest;
|
||||
import io.metersphere.base.domain.Project;
|
||||
import io.metersphere.base.domain.UserRole;
|
||||
import io.metersphere.base.mapper.ProjectMapper;
|
||||
import io.metersphere.base.mapper.ext.*;
|
||||
import io.metersphere.commons.constants.RoleConstants;
|
||||
import io.metersphere.commons.utils.SessionUtils;
|
||||
import io.metersphere.dto.LoadTestDTO;
|
||||
import io.metersphere.i18n.Translator;
|
||||
import io.metersphere.track.dto.TestPlanDTOWithMetric;
|
||||
import io.metersphere.track.request.testplan.QueryTestPlanRequest;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.shiro.authz.UnauthorizedException;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
public class CheckOwnerService {
|
||||
|
@ -34,16 +39,24 @@ public class CheckOwnerService {
|
|||
private ExtTestCaseReviewMapper extTestCaseReviewMapper;
|
||||
|
||||
public void checkProjectOwner(String projectId) {
|
||||
String workspaceId = SessionUtils.getCurrentWorkspaceId();
|
||||
Set<String> workspaceIds = getUserRelatedWorkspaceIds();
|
||||
Project project = projectMapper.selectByPrimaryKey(projectId);
|
||||
if (project == null) {
|
||||
return;
|
||||
}
|
||||
if (!StringUtils.equals(workspaceId, project.getWorkspaceId())) {
|
||||
if (!workspaceIds.contains(project.getWorkspaceId())) {
|
||||
throw new UnauthorizedException(Translator.get("check_owner_project"));
|
||||
}
|
||||
}
|
||||
|
||||
private Set<String> getUserRelatedWorkspaceIds() {
|
||||
return Objects.requireNonNull(SessionUtils.getUser()).getUserRoles().stream()
|
||||
.filter(ur ->
|
||||
StringUtils.equalsAny(ur.getRoleId(), RoleConstants.TEST_MANAGER, RoleConstants.TEST_USER, RoleConstants.TEST_VIEWER))
|
||||
.map(UserRole::getSourceId)
|
||||
.collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
public void checkApiTestOwner(String testId) {
|
||||
// 关联为其他时
|
||||
if (StringUtils.equals("other", testId)) {
|
||||
|
|
Loading…
Reference in New Issue