fix(接口测试): 修复checkOwner报错的缺陷
This commit is contained in:
parent
32bdfe2c53
commit
3d047b2daa
|
@ -2197,18 +2197,19 @@ public class ApiScenarioService {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void checkOwner(String scenarioId, String userId) {
|
public void checkOwner(String scenarioId, String userId) {
|
||||||
ApiScenarioWithBLOBs scenario = apiScenarioMapper.selectByPrimaryKey(scenarioId);
|
|
||||||
if (scenario == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
long count = SessionUtils.getUser().getGroups()
|
long count = SessionUtils.getUser().getGroups()
|
||||||
.stream()
|
.stream()
|
||||||
.filter(g -> StringUtils.equals(userId, UserGroupConstants.SUPER_GROUP))
|
.filter(g -> StringUtils.equals(g.getId(), UserGroupConstants.SUPER_GROUP))
|
||||||
.count();
|
.count();
|
||||||
|
|
||||||
if (count > 0) {
|
if (count > 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ApiScenarioWithBLOBs scenario = apiScenarioMapper.selectByPrimaryKey(scenarioId);
|
||||||
|
if (scenario == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (!extCheckOwnerMapper.checkoutOwner("api_scenario", userId, List.of(scenarioId))) {
|
if (!extCheckOwnerMapper.checkoutOwner("api_scenario", userId, List.of(scenarioId))) {
|
||||||
MSException.throwException(Translator.get("check_owner_case"));
|
MSException.throwException(Translator.get("check_owner_case"));
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,4 +26,6 @@ public interface ExtTestPlanReportMapper {
|
||||||
void updateAllStatus();
|
void updateAllStatus();
|
||||||
|
|
||||||
String selectLastReportByTestPlanId(@Param("testPlanId") String testPlanId);
|
String selectLastReportByTestPlanId(@Param("testPlanId") String testPlanId);
|
||||||
|
|
||||||
|
boolean checkoutOwner(@Param("userId") String userId, @Param("ids") List<String> ids);
|
||||||
}
|
}
|
||||||
|
|
|
@ -157,6 +157,21 @@
|
||||||
<select id="selectLastReportByTestPlanId" resultType="java.lang.String">
|
<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 `status` from test_plan_report where test_plan_id = #{testPlanId} and trigger_mode = 'SCHEDULE' ORDER BY create_time DESC LIMIT 1
|
||||||
</select>
|
</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">
|
<update id="setApiBaseCountAndPassRateIsNullById">
|
||||||
|
|
|
@ -69,8 +69,8 @@ public class TestPlanReportController {
|
||||||
|
|
||||||
@GetMapping("/status/{planId}")
|
@GetMapping("/status/{planId}")
|
||||||
@RequiresPermissions(PermissionConstants.PROJECT_TRACK_REPORT_READ)
|
@RequiresPermissions(PermissionConstants.PROJECT_TRACK_REPORT_READ)
|
||||||
@CheckOwner(resourceId = "#planId", resourceType = "test_plan_report")
|
|
||||||
public String getStatus(@PathVariable String planId) {
|
public String getStatus(@PathVariable String planId) {
|
||||||
|
testPlanReportService.checkOwner(planId, SessionUtils.getUserId());
|
||||||
TestPlanReport report = testPlanReportService.getTestPlanReport(planId);
|
TestPlanReport report = testPlanReportService.getTestPlanReport(planId);
|
||||||
String status = report.getStatus();
|
String status = report.getStatus();
|
||||||
return status;
|
return status;
|
||||||
|
|
|
@ -5,6 +5,7 @@ import io.metersphere.base.domain.*;
|
||||||
import io.metersphere.base.mapper.*;
|
import io.metersphere.base.mapper.*;
|
||||||
import io.metersphere.base.mapper.ext.*;
|
import io.metersphere.base.mapper.ext.*;
|
||||||
import io.metersphere.commons.constants.*;
|
import io.metersphere.commons.constants.*;
|
||||||
|
import io.metersphere.commons.exception.MSException;
|
||||||
import io.metersphere.commons.utils.*;
|
import io.metersphere.commons.utils.*;
|
||||||
import io.metersphere.constants.RunModeConstants;
|
import io.metersphere.constants.RunModeConstants;
|
||||||
import io.metersphere.dto.*;
|
import io.metersphere.dto.*;
|
||||||
|
@ -1757,4 +1758,19 @@ public class TestPlanReportService {
|
||||||
BatchProcessingUtil.consumerByStringList(deletedTestPlanReportIds, this::deleteReportBatch);
|
BatchProcessingUtil.consumerByStringList(deletedTestPlanReportIds, this::deleteReportBatch);
|
||||||
LogUtil.info(" check illegality resource report over");
|
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"));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue