refactor(权限管理): 修改 checkowner

This commit is contained in:
Captain.B 2021-05-26 12:25:11 +08:00 committed by 刘瑞斌
parent 62f921bdec
commit 058b31af01
11 changed files with 44 additions and 47 deletions

View File

@ -15,6 +15,6 @@ public interface ExtApiTestMapper {
List<ApiTest> listByIds(@Param("ids") List<String> ids);
int checkApiTestOwner(@Param("testId") String testId, @Param("workspaceIds") Set<String> workspaceIds);
int checkApiTestOwner(@Param("testId") String testId, @Param("projectIds") Set<String> projectIds);
}

View File

@ -167,9 +167,9 @@
<if test="testId != null">
and api_test.id = #{testId}
</if>
<if test="workspaceIds != null and workspaceIds.size() > 0">
AND workspace_id IN
<foreach collection="workspaceIds" item="id" separator="," open="(" close=")">
<if test="projectIds != null and projectIds.size() > 0">
AND project_id IN
<foreach collection="projectIds" item="id" separator="," open="(" close=")">
#{id}
</foreach>
</if>

View File

@ -15,7 +15,7 @@ public interface ExtLoadTestMapper {
List<LoadTest> getLoadTestByProjectId(String projectId);
int checkLoadTestOwner(@Param("testId") String testId, @Param("workspaceIds") Set<String> workspaceIds);
int checkLoadTestOwner(@Param("testId") String testId, @Param("projectIds") Set<String> projectIds);
LoadTest getNextNum(@Param("projectId") String projectId);

View File

@ -125,9 +125,9 @@
<if test="testId != null">
and load_test.id = #{testId}
</if>
<if test="workspaceIds != null and workspaceIds.size() > 0">
AND workspace_id IN
<foreach collection="workspaceIds" item="id" separator="," open="(" close=")">
<if test="projectIds != null and projectIds.size() > 0">
AND project_id IN
<foreach collection="projectIds" item="id" separator="," open="(" close=")">
#{id}
</foreach>
</if>

View File

@ -54,10 +54,10 @@ public interface ExtTestCaseMapper {
* 检查某工作空间下是否有某用例
*
* @param caseId
* @param workspaceIds
* @param projectIds
* @return TestCase ID
*/
int checkIsHave(@Param("caseId") String caseId, @Param("workspaceIds") Set<String> workspaceIds);
int checkIsHave(@Param("caseId") String caseId, @Param("projectIds") Set<String> projectIds);
List<String> selectIds(@Param("request") BaseQueryRequest condition);

View File

@ -256,9 +256,9 @@
SELECT COUNT(1)
FROM test_case, project
WHERE test_case.project_id = project.id
<if test="workspaceIds != null and workspaceIds.size() > 0">
AND project.workspace_id IN
<foreach collection="workspaceIds" item="id" separator="," open="(" close=")">
<if test="projectIds != null and projectIds.size() > 0">
AND project.id IN
<foreach collection="projectIds" item="id" separator="," open="(" close=")">
#{id}
</foreach>
</if>

View File

@ -18,11 +18,11 @@ public interface ExtTestCaseReviewMapper {
List<TestReviewDTOWithMetric> listRelate(@Param("request") QueryTestReviewRequest request);
/**
* 检查某工作空间下是否有某测试评审
* 检查某项目是否有某测试评审
*
* @param reviewId
* @param workspaceIds
* @param projectIds
* @return Review ID
*/
int checkIsHave(@Param("reviewId") String reviewId, @Param("workspaceIds") Set<String> workspaceIds);
int checkIsHave(@Param("reviewId") String reviewId, @Param("projectIds") Set<String> projectIds);
}

View File

@ -79,18 +79,18 @@
SELECT COUNT(1) as c
FROM project, test_case_review_project
WHERE project.id = test_case_review_project.project_id AND test_case_review_project.review_id = #{reviewId}
<if test="workspaceIds != null and workspaceIds.size() > 0">
AND project.workspace_id IN
<foreach collection="workspaceIds" item="id" separator="," open="(" close=")">
<if test="projectIds != null and projectIds.size() > 0">
AND project.id IN
<foreach collection="projectIds" item="id" separator="," open="(" close=")">
#{id}
</foreach>
</if>
union
select count(1) as c from test_case_review, project
WHERE project_id = project.id AND test_case_review.id = #{reviewId}
<if test="workspaceIds != null and workspaceIds.size() > 0">
AND project.workspace_id IN
<foreach collection="workspaceIds" item="id" separator="," open="(" close=")">
<if test="projectIds != null and projectIds.size() > 0">
AND project_id IN
<foreach collection="projectIds" item="id" separator="," open="(" close=")">
#{id}
</foreach>
</if>) as temp

View File

@ -26,7 +26,7 @@ public interface ExtTestPlanMapper {
*/
List<TestPlanDTO> selectTestPlanByRelevancy(@Param("request") QueryTestPlanRequest params);
int checkIsHave(@Param("planId") String planId, @Param("workspaceIds") Set<String> workspaceIds);
int checkIsHave(@Param("planId") String planId, @Param("projectIds") Set<String> projectIds);
String findTestProjectNameByTestPlanID(String testPlanId);

View File

@ -196,18 +196,18 @@
SELECT COUNT(1) as c
FROM test_plan_project, project
WHERE project_id = project.id AND test_plan_id = #{planId}
<if test="workspaceIds != null and workspaceIds.size() > 0">
AND project.workspace_id IN
<foreach collection="workspaceIds" item="id" separator="," open="(" close=")">
<if test="projectIds != null and projectIds.size() > 0">
AND project.id IN
<foreach collection="projectIds" item="id" separator="," open="(" close=")">
#{id}
</foreach>
</if>
union
select count(1) as c from test_plan, project
WHERE project_id = project.id AND test_plan.id = #{planId}
<if test="workspaceIds != null and workspaceIds.size() > 0">
AND project.workspace_id IN
<foreach collection="workspaceIds" item="id" separator="," open="(" close=")">
<if test="projectIds != null and projectIds.size() > 0">
AND project.id IN
<foreach collection="projectIds" item="id" separator="," open="(" close=")">
#{id}
</foreach>
</if>) as temp

View File

@ -2,7 +2,6 @@ package io.metersphere.service;
import io.metersphere.base.domain.Group;
import io.metersphere.base.domain.UserGroup;
import io.metersphere.base.mapper.ProjectMapper;
import io.metersphere.base.mapper.ext.*;
import io.metersphere.commons.constants.UserGroupType;
import io.metersphere.commons.utils.SessionUtils;
@ -19,8 +18,6 @@ import java.util.stream.Collectors;
@Service
public class CheckPermissionService {
@Resource
private ProjectMapper projectMapper;
@Resource
private ExtApiTestMapper extApiTestMapper;
@Resource
@ -59,12 +56,12 @@ public class CheckPermissionService {
if (StringUtils.equals("other", testId)) {
return;
}
Set<String> workspaceIds = getUserRelatedProjectIds();
if (CollectionUtils.isEmpty(workspaceIds)) {
Set<String> projectIds = getUserRelatedProjectIds();
if (CollectionUtils.isEmpty(projectIds)) {
return;
}
int result = extApiTestMapper.checkApiTestOwner(testId, workspaceIds);
int result = extApiTestMapper.checkApiTestOwner(testId, projectIds);
if (result == 0) {
throw new RuntimeException(Translator.get("check_owner_test"));
@ -76,11 +73,11 @@ public class CheckPermissionService {
if (StringUtils.equals("other", testId)) {
return;
}
Set<String> workspaceIds = getUserRelatedProjectIds();
if (CollectionUtils.isEmpty(workspaceIds)) {
Set<String> projectIds = getUserRelatedProjectIds();
if (CollectionUtils.isEmpty(projectIds)) {
return;
}
int result = extLoadTestMapper.checkLoadTestOwner(testId, workspaceIds);
int result = extLoadTestMapper.checkLoadTestOwner(testId, projectIds);
if (result == 0) {
throw new RuntimeException(Translator.get("check_owner_test"));
@ -88,34 +85,34 @@ public class CheckPermissionService {
}
public void checkTestCaseOwner(String caseId) {
Set<String> workspaceIds = getUserRelatedProjectIds();
if (CollectionUtils.isEmpty(workspaceIds)) {
Set<String> projectIds = getUserRelatedProjectIds();
if (CollectionUtils.isEmpty(projectIds)) {
return;
}
int result = extTestCaseMapper.checkIsHave(caseId, workspaceIds);
int result = extTestCaseMapper.checkIsHave(caseId, projectIds);
if (result == 0) {
throw new RuntimeException(Translator.get("check_owner_case"));
}
}
public void checkTestPlanOwner(String planId) {
Set<String> workspaceIds = getUserRelatedProjectIds();
if (CollectionUtils.isEmpty(workspaceIds)) {
Set<String> projectIds = getUserRelatedProjectIds();
if (CollectionUtils.isEmpty(projectIds)) {
return;
}
int result = extTestPlanMapper.checkIsHave(planId, workspaceIds);
int result = extTestPlanMapper.checkIsHave(planId, projectIds);
if (result == 0) {
throw new RuntimeException(Translator.get("check_owner_plan"));
}
}
public void checkTestReviewOwner(String reviewId) {
Set<String> workspaceIds = getUserRelatedProjectIds();
if (CollectionUtils.isEmpty(workspaceIds)) {
Set<String> projectIds = getUserRelatedProjectIds();
if (CollectionUtils.isEmpty(projectIds)) {
return;
}
int result = extTestCaseReviewMapper.checkIsHave(reviewId, workspaceIds);
int result = extTestCaseReviewMapper.checkIsHave(reviewId, projectIds);
if (result == 0) {
throw new RuntimeException(Translator.get("check_owner_review"));
}