diff --git a/backend/src/main/java/io/metersphere/controller/TestResourcePoolController.java b/backend/src/main/java/io/metersphere/controller/TestResourcePoolController.java index 2ce7bf4ff2..48f461b56c 100644 --- a/backend/src/main/java/io/metersphere/controller/TestResourcePoolController.java +++ b/backend/src/main/java/io/metersphere/controller/TestResourcePoolController.java @@ -14,6 +14,7 @@ import org.apache.shiro.authz.annotation.RequiresRoles; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; + import java.util.List; @RequestMapping("testresourcepool") @@ -56,5 +57,11 @@ public class TestResourcePoolController { return testResourcePoolService.listValidResourcePools(); } + @GetMapping("list/quota/valid") + @RequiresRoles(value = {RoleConstants.TEST_MANAGER, RoleConstants.TEST_USER, RoleConstants.TEST_VIEWER}, logical = Logical.OR) + public List listValidQuotaResourcePools() { + return testResourcePoolService.listValidQuotaResourcePools(); + } + } diff --git a/backend/src/main/java/io/metersphere/performance/service/PerformanceTestService.java b/backend/src/main/java/io/metersphere/performance/service/PerformanceTestService.java index 52f405b47c..08c36d9281 100644 --- a/backend/src/main/java/io/metersphere/performance/service/PerformanceTestService.java +++ b/backend/src/main/java/io/metersphere/performance/service/PerformanceTestService.java @@ -34,8 +34,6 @@ import org.springframework.transaction.annotation.Transactional; import org.springframework.util.CollectionUtils; import org.springframework.web.multipart.MultipartFile; -import javax.annotation.Resource; - import java.io.OutputStream; import java.net.InetSocketAddress; import java.net.Socket; @@ -44,6 +42,8 @@ import java.time.temporal.ChronoUnit; import java.util.*; import java.util.stream.Collectors; +import javax.annotation.Resource; + @Service @Transactional(rollbackFor = Exception.class) public class PerformanceTestService { @@ -131,7 +131,7 @@ public class PerformanceTestService { throw new IllegalArgumentException(Translator.get("file_cannot_be_null")); } - checkQuota(request); + checkQuota(request, true); final LoadTestWithBLOBs loadTest = saveLoadTest(request); files.forEach(file -> { @@ -168,6 +168,7 @@ public class PerformanceTestService { } public String edit(EditTestPlanRequest request, List files) { + checkQuota(request, false); // LoadTestWithBLOBs loadTest = loadTestMapper.selectByPrimaryKey(request.getId()); if (loadTest == null) { @@ -363,7 +364,7 @@ public class PerformanceTestService { } public void copy(SaveTestPlanRequest request) { - checkQuota(request); + checkQuota(request, true); // copy test LoadTestWithBLOBs copy = loadTestMapper.selectByPrimaryKey(request.getId()); copy.setId(UUID.randomUUID().toString()); @@ -441,10 +442,10 @@ public class PerformanceTestService { return schedules; } - private void checkQuota(SaveTestPlanRequest request) { + private void checkQuota(TestPlanRequest request, boolean create) { QuotaService quotaService = CommonBeanFactory.getBean(QuotaService.class); if (quotaService != null) { - quotaService.checkLoadTestQuota(request); + quotaService.checkLoadTestQuota(request, create); } } } diff --git a/backend/src/main/java/io/metersphere/service/QuotaService.java b/backend/src/main/java/io/metersphere/service/QuotaService.java index d3e94c7240..c570cac3d2 100644 --- a/backend/src/main/java/io/metersphere/service/QuotaService.java +++ b/backend/src/main/java/io/metersphere/service/QuotaService.java @@ -1,10 +1,14 @@ package io.metersphere.service; -import io.metersphere.track.request.testplan.SaveTestPlanRequest; +import io.metersphere.track.request.testplan.TestPlanRequest; + +import java.util.Set; public interface QuotaService { void checkAPITestQuota(); - void checkLoadTestQuota(SaveTestPlanRequest request); + void checkLoadTestQuota(TestPlanRequest request, boolean checkPerformance); + + Set getQuotaResourcePools(); } diff --git a/backend/src/main/java/io/metersphere/service/TestResourcePoolService.java b/backend/src/main/java/io/metersphere/service/TestResourcePoolService.java index d7919de2f7..84aefa198b 100644 --- a/backend/src/main/java/io/metersphere/service/TestResourcePoolService.java +++ b/backend/src/main/java/io/metersphere/service/TestResourcePoolService.java @@ -1,5 +1,8 @@ package io.metersphere.service; +import static io.metersphere.commons.constants.ResourceStatusEnum.INVALID; +import static io.metersphere.commons.constants.ResourceStatusEnum.VALID; + import com.alibaba.fastjson.JSON; import io.metersphere.base.domain.*; import io.metersphere.base.mapper.LoadTestMapper; @@ -7,6 +10,7 @@ import io.metersphere.base.mapper.TestResourceMapper; import io.metersphere.base.mapper.TestResourcePoolMapper; import io.metersphere.commons.constants.ResourceStatusEnum; import io.metersphere.commons.exception.MSException; +import io.metersphere.commons.utils.CommonBeanFactory; import io.metersphere.commons.utils.LogUtil; import io.metersphere.controller.request.resourcepool.QueryResourcePoolRequest; import io.metersphere.dto.NodeDTO; @@ -21,15 +25,14 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.web.client.RestTemplate; -import javax.annotation.Resource; import java.lang.reflect.InvocationTargetException; import java.util.ArrayList; import java.util.List; +import java.util.Set; import java.util.UUID; import java.util.stream.Collectors; -import static io.metersphere.commons.constants.ResourceStatusEnum.INVALID; -import static io.metersphere.commons.constants.ResourceStatusEnum.VALID; +import javax.annotation.Resource; /** * @author dongbin @@ -243,4 +246,19 @@ public class TestResourcePoolService { return testResourcePoolMapper.selectByExample(example); } + public List listValidQuotaResourcePools() { + return filterQuota(listValidResourcePools()); + } + + private List filterQuota(List list) { + QuotaService quotaService = CommonBeanFactory.getBean(QuotaService.class); + if (quotaService != null) { + Set pools = quotaService.getQuotaResourcePools(); + if (!pools.isEmpty()) { + return list.stream().filter(pool -> pools.contains(pool.getId())).collect(Collectors.toList()); + } + } + return list; + } + } diff --git a/backend/src/main/java/io/metersphere/xpack b/backend/src/main/java/io/metersphere/xpack index defbf12ffa..ecb30d83c5 160000 --- a/backend/src/main/java/io/metersphere/xpack +++ b/backend/src/main/java/io/metersphere/xpack @@ -1 +1 @@ -Subproject commit defbf12ffac99eef6a026b87491090f2263b769d +Subproject commit ecb30d83c575c6ed14adb1a1ebea389730f410a9 diff --git a/frontend/src/business/components/performance/test/components/PerformancePressureConfig.vue b/frontend/src/business/components/performance/test/components/PerformancePressureConfig.vue index a39e546498..71c1b091f8 100644 --- a/frontend/src/business/components/performance/test/components/PerformancePressureConfig.vue +++ b/frontend/src/business/components/performance/test/components/PerformancePressureConfig.vue @@ -166,7 +166,7 @@ }, methods: { getResourcePools() { - this.result = this.$get('/testresourcepool/list/all/valid', response => { + this.result = this.$get('/testresourcepool/list/quota/valid', response => { this.resourcePools = response.data; // 如果当前的资源池无效 设置 null if (response.data.filter(p => p.id === this.resourcePool).length === 0) { diff --git a/frontend/src/business/components/track/plan/view/comonents/TestPlanTestCaseEdit.vue b/frontend/src/business/components/track/plan/view/comonents/TestPlanTestCaseEdit.vue index ae8e3f3f95..c985ff5f80 100644 --- a/frontend/src/business/components/track/plan/view/comonents/TestPlanTestCaseEdit.vue +++ b/frontend/src/business/components/track/plan/view/comonents/TestPlanTestCaseEdit.vue @@ -208,7 +208,7 @@ - + diff --git a/frontend/src/business/components/track/plan/view/comonents/TestPlanTestCaseList.vue b/frontend/src/business/components/track/plan/view/comonents/TestPlanTestCaseList.vue index d662ca0206..977d553eaa 100644 --- a/frontend/src/business/components/track/plan/view/comonents/TestPlanTestCaseList.vue +++ b/frontend/src/business/components/track/plan/view/comonents/TestPlanTestCaseList.vue @@ -113,7 +113,7 @@ trigger="hover"> - + diff --git a/frontend/src/business/components/xpack b/frontend/src/business/components/xpack index 06fc0a321a..390943d21e 160000 --- a/frontend/src/business/components/xpack +++ b/frontend/src/business/components/xpack @@ -1 +1 @@ -Subproject commit 06fc0a321a9886419be5c607ddaa6b40efb5179b +Subproject commit 390943d21e7d0196e0d7d5faa66f0131cb631614 diff --git a/frontend/src/i18n/en-US.js b/frontend/src/i18n/en-US.js index 9841ec002f..3a4de71e7a 100644 --- a/frontend/src/i18n/en-US.js +++ b/frontend/src/i18n/en-US.js @@ -730,6 +730,7 @@ export default { close: "Close", title_description_required: "Title and description are required", close_success: "Closed successfully", + preview: "Preview" } }, test_resource_pool: { diff --git a/frontend/src/i18n/zh-CN.js b/frontend/src/i18n/zh-CN.js index fad70b1f14..4f66dd0c7d 100644 --- a/frontend/src/i18n/zh-CN.js +++ b/frontend/src/i18n/zh-CN.js @@ -733,6 +733,7 @@ export default { close: "关闭缺陷", title_description_required: "标题和描述必填", close_success: "关闭成功", + preview: "预览" } }, test_resource_pool: { diff --git a/frontend/src/i18n/zh-TW.js b/frontend/src/i18n/zh-TW.js index 274ed72c16..11e685dfb4 100644 --- a/frontend/src/i18n/zh-TW.js +++ b/frontend/src/i18n/zh-TW.js @@ -730,6 +730,7 @@ export default { close: "關閉缺陷", title_description_required: "標題和描述必填", close_success: "關閉成功", + preview: "預覽" } }, test_resource_pool: {