fix(接口测试): 修复checkOwner报错的缺陷

This commit is contained in:
wxg0103 2024-06-27 19:31:14 +08:00 committed by 刘瑞斌
parent 32bdfe2c53
commit 3d047b2daa
5 changed files with 40 additions and 6 deletions

View File

@ -2197,18 +2197,19 @@ public class ApiScenarioService {
}
public void checkOwner(String scenarioId, String userId) {
ApiScenarioWithBLOBs scenario = apiScenarioMapper.selectByPrimaryKey(scenarioId);
if (scenario == null) {
return;
}
long count = SessionUtils.getUser().getGroups()
.stream()
.filter(g -> StringUtils.equals(userId, UserGroupConstants.SUPER_GROUP))
.filter(g -> StringUtils.equals(g.getId(), UserGroupConstants.SUPER_GROUP))
.count();
if (count > 0) {
return;
}
ApiScenarioWithBLOBs scenario = apiScenarioMapper.selectByPrimaryKey(scenarioId);
if (scenario == null) {
return;
}
if (!extCheckOwnerMapper.checkoutOwner("api_scenario", userId, List.of(scenarioId))) {
MSException.throwException(Translator.get("check_owner_case"));
}

View File

@ -26,4 +26,6 @@ public interface ExtTestPlanReportMapper {
void updateAllStatus();
String selectLastReportByTestPlanId(@Param("testPlanId") String testPlanId);
boolean checkoutOwner(@Param("userId") String userId, @Param("ids") List<String> ids);
}

View File

@ -157,6 +157,21 @@
<select id="selectLastReportByTestPlanId" resultType="java.lang.String">
select `status` from test_plan_report where test_plan_id = #{testPlanId} and trigger_mode = 'SCHEDULE' ORDER BY create_time DESC LIMIT 1
</select>
<select id="checkoutOwner" resultType="java.lang.Boolean">
SELECT count(1) > 0
FROM user_group
WHERE source_id IN (
SELECT project_id
FROM test_plan_report
left join test_plan on test_plan_report.test_plan_id = test_plan.id
Left JOIN project ON test_plan.project_id = project.id
WHERE test_plan_report.id IN
<foreach collection="ids" item="id" separator="," open="(" close=")">
#{id}
</foreach>
)
AND user_id = #{userId}
</select>
<update id="setApiBaseCountAndPassRateIsNullById">

View File

@ -69,8 +69,8 @@ public class TestPlanReportController {
@GetMapping("/status/{planId}")
@RequiresPermissions(PermissionConstants.PROJECT_TRACK_REPORT_READ)
@CheckOwner(resourceId = "#planId", resourceType = "test_plan_report")
public String getStatus(@PathVariable String planId) {
testPlanReportService.checkOwner(planId, SessionUtils.getUserId());
TestPlanReport report = testPlanReportService.getTestPlanReport(planId);
String status = report.getStatus();
return status;

View File

@ -5,6 +5,7 @@ import io.metersphere.base.domain.*;
import io.metersphere.base.mapper.*;
import io.metersphere.base.mapper.ext.*;
import io.metersphere.commons.constants.*;
import io.metersphere.commons.exception.MSException;
import io.metersphere.commons.utils.*;
import io.metersphere.constants.RunModeConstants;
import io.metersphere.dto.*;
@ -1757,4 +1758,19 @@ public class TestPlanReportService {
BatchProcessingUtil.consumerByStringList(deletedTestPlanReportIds, this::deleteReportBatch);
LogUtil.info(" check illegality resource report over");
}
public void checkOwner(String reportId, String userId) {
long count = SessionUtils.getUser().getGroups()
.stream()
.filter(g -> StringUtils.equals(g.getId(), UserGroupConstants.SUPER_GROUP))
.count();
if (count > 0) {
return;
}
if (!extTestPlanReportMapper.checkoutOwner(userId, List.of(reportId))) {
MSException.throwException(Translator.get("check_owner_case"));
}
}
}