fix(配额管理): 修复接口测试没有验证配额的问题

--bug=1008092 --user=刘瑞斌 【系统设置】配额管理,接口测试数量没限制住 https://www.tapd.cn/55049933/s/1070718
This commit is contained in:
CaptainB 2021-11-19 18:50:57 +08:00 committed by 刘瑞斌
parent 737f3d7819
commit bf128be591
6 changed files with 25 additions and 23 deletions

View File

@ -97,7 +97,6 @@ public class APITestService {
if (file == null) { if (file == null) {
throw new IllegalArgumentException(Translator.get("file_cannot_be_null")); throw new IllegalArgumentException(Translator.get("file_cannot_be_null"));
} }
checkQuota();
request.setBodyUploadIds(null); request.setBodyUploadIds(null);
ApiTest test = createTest(request); ApiTest test = createTest(request);
saveFile(test, file); saveFile(test, file);
@ -140,7 +139,6 @@ public class APITestService {
} }
public void copy(SaveAPITestRequest request) { public void copy(SaveAPITestRequest request) {
checkQuota();
ApiTestExample example = new ApiTestExample(); ApiTestExample example = new ApiTestExample();
example.createCriteria().andNameEqualTo(request.getName()).andProjectIdEqualTo(request.getProjectId()); example.createCriteria().andNameEqualTo(request.getName()).andProjectIdEqualTo(request.getProjectId());
@ -452,13 +450,6 @@ public class APITestService {
return reportId; return reportId;
} }
private void checkQuota() {
QuotaService quotaService = CommonBeanFactory.getBean(QuotaService.class);
if (quotaService != null) {
quotaService.checkAPITestQuota();
}
}
public void mergeCreate(SaveAPITestRequest request, MultipartFile file, List<String> selectIds) { public void mergeCreate(SaveAPITestRequest request, MultipartFile file, List<String> selectIds) {
ApiTest test = createTest(request, file); ApiTest test = createTest(request, file);
selectIds.forEach(sourceId -> { selectIds.forEach(sourceId -> {

View File

@ -46,6 +46,7 @@ import io.metersphere.log.vo.DetailColumn;
import io.metersphere.log.vo.OperatingLogDetails; import io.metersphere.log.vo.OperatingLogDetails;
import io.metersphere.log.vo.api.AutomationReference; import io.metersphere.log.vo.api.AutomationReference;
import io.metersphere.plugin.core.MsTestElement; import io.metersphere.plugin.core.MsTestElement;
import io.metersphere.service.QuotaService;
import io.metersphere.service.RelationshipEdgeService; import io.metersphere.service.RelationshipEdgeService;
import io.metersphere.service.ScheduleService; import io.metersphere.service.ScheduleService;
import io.metersphere.service.SystemParameterService; import io.metersphere.service.SystemParameterService;
@ -295,6 +296,7 @@ public class ApiAutomationService {
} }
public ApiScenario create(SaveApiScenarioRequest request, List<MultipartFile> bodyFiles, List<MultipartFile> scenarioFiles) { public ApiScenario create(SaveApiScenarioRequest request, List<MultipartFile> bodyFiles, List<MultipartFile> scenarioFiles) {
checkQuota();
request.setId(UUID.randomUUID().toString()); request.setId(UUID.randomUUID().toString());
checkNameExist(request); checkNameExist(request);
int nextNum = getNextNum(request.getProjectId()); int nextNum = getNextNum(request.getProjectId());
@ -326,6 +328,13 @@ public class ApiAutomationService {
return scenario; return scenario;
} }
private void checkQuota() {
QuotaService quotaService = CommonBeanFactory.getBean(QuotaService.class);
if (quotaService != null) {
quotaService.checkAPIAutomationQuota();
}
}
private void uploadFiles(SaveApiScenarioRequest request, List<MultipartFile> bodyFiles, List<MultipartFile> scenarioFiles) { private void uploadFiles(SaveApiScenarioRequest request, List<MultipartFile> bodyFiles, List<MultipartFile> scenarioFiles) {
FileUtils.createBodyFiles(request.getScenarioFileIds(), scenarioFiles); FileUtils.createBodyFiles(request.getScenarioFileIds(), scenarioFiles);
List<String> bodyFileRequestIds = request.getBodyFileRequestIds(); List<String> bodyFileRequestIds = request.getBodyFileRequestIds();
@ -394,6 +403,7 @@ public class ApiAutomationService {
} }
public ApiScenario update(SaveApiScenarioRequest request, List<MultipartFile> bodyFiles, List<MultipartFile> scenarioFiles) { public ApiScenario update(SaveApiScenarioRequest request, List<MultipartFile> bodyFiles, List<MultipartFile> scenarioFiles) {
checkQuota();
checkNameExist(request); checkNameExist(request);
checkScenarioNum(request); checkScenarioNum(request);

View File

@ -49,10 +49,7 @@ import io.metersphere.log.vo.StatusReference;
import io.metersphere.log.vo.api.DefinitionReference; import io.metersphere.log.vo.api.DefinitionReference;
import io.metersphere.notice.sender.NoticeModel; import io.metersphere.notice.sender.NoticeModel;
import io.metersphere.notice.service.NoticeSendService; import io.metersphere.notice.service.NoticeSendService;
import io.metersphere.service.FileService; import io.metersphere.service.*;
import io.metersphere.service.RelationshipEdgeService;
import io.metersphere.service.ScheduleService;
import io.metersphere.service.SystemParameterService;
import io.metersphere.track.request.testcase.ApiCaseRelevanceRequest; import io.metersphere.track.request.testcase.ApiCaseRelevanceRequest;
import io.metersphere.track.request.testcase.QueryTestPlanRequest; import io.metersphere.track.request.testcase.QueryTestPlanRequest;
import io.metersphere.track.service.TestPlanService; import io.metersphere.track.service.TestPlanService;
@ -269,6 +266,7 @@ public class ApiDefinitionService {
} }
public ApiDefinitionWithBLOBs create(SaveApiDefinitionRequest request, List<MultipartFile> bodyFiles) { public ApiDefinitionWithBLOBs create(SaveApiDefinitionRequest request, List<MultipartFile> bodyFiles) {
checkQuota();
if (StringUtils.equals(request.getProtocol(), "DUBBO")) { if (StringUtils.equals(request.getProtocol(), "DUBBO")) {
request.setMethod("dubbo://"); request.setMethod("dubbo://");
} }
@ -278,6 +276,7 @@ public class ApiDefinitionService {
} }
public ApiDefinitionWithBLOBs update(SaveApiDefinitionRequest request, List<MultipartFile> bodyFiles) { public ApiDefinitionWithBLOBs update(SaveApiDefinitionRequest request, List<MultipartFile> bodyFiles) {
checkQuota();
if (request.getRequest() != null) { if (request.getRequest() != null) {
deleteFileByTestId(request.getRequest().getId()); deleteFileByTestId(request.getRequest().getId());
} }
@ -292,6 +291,13 @@ public class ApiDefinitionService {
return returnModel; return returnModel;
} }
private void checkQuota() {
QuotaService quotaService = CommonBeanFactory.getBean(QuotaService.class);
if (quotaService != null) {
quotaService.checkAPIDefinitionQuota();
}
}
public void delete(String apiId) { public void delete(String apiId) {
apiTestCaseService.deleteTestCase(apiId); apiTestCaseService.deleteTestCase(apiId);
deleteFileByTestId(apiId); deleteFileByTestId(apiId);
@ -1748,7 +1754,7 @@ public class ApiDefinitionService {
String format = body.getString("format"); String format = body.getString("format");
if (StringUtils.equals(format, "JSON-SCHEMA") && StringUtils.isNotEmpty(body.getString("jsonSchema"))) { if (StringUtils.equals(format, "JSON-SCHEMA") && StringUtils.isNotEmpty(body.getString("jsonSchema"))) {
elements = JSONSchemaToDocumentUtils.getDocument(body.getString("jsonSchema")); elements = JSONSchemaToDocumentUtils.getDocument(body.getString("jsonSchema"));
}else { } else {
elements = JSONToDocumentUtils.getDocument(raw, dataType); elements = JSONToDocumentUtils.getDocument(raw, dataType);
} }
} else if (StringUtils.equals(dataType, "XML")) { } else if (StringUtils.equals(dataType, "XML")) {

View File

@ -231,13 +231,6 @@ public class ApiTestCaseService {
return test; return test;
} }
private void checkQuota() {
QuotaService quotaService = CommonBeanFactory.getBean(QuotaService.class);
if (quotaService != null) {
quotaService.checkAPITestQuota();
}
}
public ApiTestCase update(SaveApiTestCaseRequest request, List<MultipartFile> bodyFiles) { public ApiTestCase update(SaveApiTestCaseRequest request, List<MultipartFile> bodyFiles) {
deleteFileByTestId(request.getId()); deleteFileByTestId(request.getId());
request.setBodyUploadIds(null); request.setBodyUploadIds(null);

View File

@ -7,7 +7,9 @@ import java.util.Set;
public interface QuotaService { public interface QuotaService {
void checkAPITestQuota(); void checkAPIDefinitionQuota();
void checkAPIAutomationQuota();
void checkLoadTestQuota(TestPlanRequest request, boolean checkPerformance); void checkLoadTestQuota(TestPlanRequest request, boolean checkPerformance);

@ -1 +1 @@
Subproject commit 9a24f644b842d930da6019383fc70e11b8973af2 Subproject commit 1a1a00814f367d827975b524781771b74a7e7938