fix(测试跟踪): 分享测试计划报告后页面报错401

This commit is contained in:
chenjianxing 2023-02-23 13:18:55 +08:00 committed by jianxing
parent 7c9388ee5a
commit 2d20362fee
3 changed files with 16 additions and 5 deletions

View File

@ -2,6 +2,7 @@ package io.metersphere.controller;
import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.JsonProcessingException;
import io.metersphere.commons.utils.HttpHeaderUtils; import io.metersphere.commons.utils.HttpHeaderUtils;
import io.metersphere.commons.utils.SessionUtils;
import io.metersphere.dto.TestPlanCaseDTO; import io.metersphere.dto.TestPlanCaseDTO;
import io.metersphere.plan.dto.TestPlanExtReportDTO; import io.metersphere.plan.dto.TestPlanExtReportDTO;
import io.metersphere.plan.dto.TestPlanSimpleReportDTO; import io.metersphere.plan.dto.TestPlanSimpleReportDTO;
@ -68,7 +69,9 @@ public class ShareController {
@GetMapping("test/plan/ext/report/{shareId}/{reportId}") @GetMapping("test/plan/ext/report/{shareId}/{reportId}")
public TestPlanExtReportDTO getExtReport(@PathVariable String shareId, @PathVariable String reportId) throws JsonProcessingException { public TestPlanExtReportDTO getExtReport(@PathVariable String shareId, @PathVariable String reportId) throws JsonProcessingException {
shareInfoService.validate(shareId, reportId); shareInfoService.validate(shareId, reportId);
if (SessionUtils.getUser() == null) {
HttpHeaderUtils.runAsUser("admin"); HttpHeaderUtils.runAsUser("admin");
}
TestPlanExtReportDTO reportExtInfo = testPlanService.getExtInfoByReportId(reportId); TestPlanExtReportDTO reportExtInfo = testPlanService.getExtInfoByReportId(reportId);
HttpHeaderUtils.clearUser(); HttpHeaderUtils.clearUser();
return reportExtInfo; return reportExtInfo;
@ -77,7 +80,9 @@ public class ShareController {
@GetMapping("test/plan/ext/plan/{shareId}/{planId}") @GetMapping("test/plan/ext/plan/{shareId}/{planId}")
public TestPlanExtReportDTO getExtPlan(@PathVariable String shareId, @PathVariable String planId) throws JsonProcessingException { public TestPlanExtReportDTO getExtPlan(@PathVariable String shareId, @PathVariable String planId) throws JsonProcessingException {
shareInfoService.validate(shareId, planId); shareInfoService.validate(shareId, planId);
if (SessionUtils.getUser() == null) {
HttpHeaderUtils.runAsUser("admin"); HttpHeaderUtils.runAsUser("admin");
}
TestPlanExtReportDTO reportExtInfo = testPlanService.getExtInfoByPlanId(planId); TestPlanExtReportDTO reportExtInfo = testPlanService.getExtInfoByPlanId(planId);
HttpHeaderUtils.clearUser(); HttpHeaderUtils.clearUser();
return reportExtInfo; return reportExtInfo;

View File

@ -742,7 +742,9 @@ public class TestPlanReportService {
runRequest.setReportId(testPlanExecutionQueue.getReportId()); runRequest.setReportId(testPlanExecutionQueue.getReportId());
runRequest.setTestPlanId(testPlan.getId()); runRequest.setTestPlanId(testPlan.getId());
try { try {
if (SessionUtils.getUser() == null) {
HttpHeaderUtils.runAsUser("admin"); HttpHeaderUtils.runAsUser("admin");
}
//如果运行测试计划的过程中出现异常则整个事务会回滚 删除队列的事务也不会提交也不会执行后面的测试计划 //如果运行测试计划的过程中出现异常则整个事务会回滚 删除队列的事务也不会提交也不会执行后面的测试计划
testPlanService.runPlan(runRequest); testPlanService.runPlan(runRequest);
} catch (Exception e) { } catch (Exception e) {
@ -1125,7 +1127,9 @@ public class TestPlanReportService {
} }
public TestPlanSimpleReportDTO getShareDbReport(ShareInfo shareInfo, String reportId) { public TestPlanSimpleReportDTO getShareDbReport(ShareInfo shareInfo, String reportId) {
if (SessionUtils.getUser() == null) {
HttpHeaderUtils.runAsUser(shareInfo.getCreateUserId()); HttpHeaderUtils.runAsUser(shareInfo.getCreateUserId());
}
try { try {
return getReport(reportId); return getReport(reportId);
} finally { } finally {

View File

@ -1482,7 +1482,9 @@ public class TestPlanService {
} }
public TestPlanSimpleReportDTO getShareReport(ShareInfo shareInfo, String planId) { public TestPlanSimpleReportDTO getShareReport(ShareInfo shareInfo, String planId) {
if (SessionUtils.getUser() == null) {
HttpHeaderUtils.runAsUser(shareInfo.getCreateUserId()); HttpHeaderUtils.runAsUser(shareInfo.getCreateUserId());
}
try { try {
return getReport(planId, null); return getReport(planId, null);
} finally { } finally {