From 7de7304d4d201e8209f771ee18f4900336147ee6 Mon Sep 17 00:00:00 2001 From: Umesh Kumar <166806589+TangoBeeAkto@users.noreply.github.com> Date: Wed, 11 Dec 2024 14:50:47 +0530 Subject: [PATCH] fix: fetching sampleData from a random API only if it's not available for test editor --- .../java/com/akto/action/TrafficAction.java | 5 +++- apps/dashboard/src/main/resources/struts.xml | 25 ++++++++++++++++++- .../apps/dashboard/pages/test_editor/api.js | 4 +-- .../test_editor/components/SampleApi.jsx | 2 +- 4 files changed, 31 insertions(+), 5 deletions(-) diff --git a/apps/dashboard/src/main/java/com/akto/action/TrafficAction.java b/apps/dashboard/src/main/java/com/akto/action/TrafficAction.java index e96e0ab7fa..f4dd62a319 100644 --- a/apps/dashboard/src/main/java/com/akto/action/TrafficAction.java +++ b/apps/dashboard/src/main/java/com/akto/action/TrafficAction.java @@ -64,7 +64,11 @@ public String fetchSampleData() { Filters.gte("_id.bucketStartEpoch", 0), Filters.lte("_id.bucketEndEpoch", 0) )); + return Action.SUCCESS.toUpperCase(); + } + public String fetchSampleDataForTestEditor() { + fetchSampleData(); if(sampleDataList == null || sampleDataList.isEmpty()) { sampleDataList = new ArrayList<>(); ApiCollection randomActiveCollection = ApiCollectionsDao.instance.findOne(Filters.and( @@ -92,7 +96,6 @@ public String fetchSampleData() { Filters.lte("_id.bucketEndEpoch", 0) )); } - return Action.SUCCESS.toUpperCase(); } diff --git a/apps/dashboard/src/main/resources/struts.xml b/apps/dashboard/src/main/resources/struts.xml index 16bddac430..bc4025ca52 100644 --- a/apps/dashboard/src/main/resources/struts.xml +++ b/apps/dashboard/src/main/resources/struts.xml @@ -2400,7 +2400,7 @@ ^actionErrors.* - + @@ -2424,6 +2424,29 @@ ^actionErrors.* + + + + + SAMPLE_DATA + READ + + + 403 + false + ^actionErrors.* + + + + + 401 + + + 403 + false + ^actionErrors.* + + diff --git a/apps/dashboard/web/polaris_web/web/src/apps/dashboard/pages/test_editor/api.js b/apps/dashboard/web/polaris_web/web/src/apps/dashboard/pages/test_editor/api.js index 4dce55eb9c..65a159f5de 100644 --- a/apps/dashboard/web/polaris_web/web/src/apps/dashboard/pages/test_editor/api.js +++ b/apps/dashboard/web/polaris_web/web/src/apps/dashboard/pages/test_editor/api.js @@ -1,9 +1,9 @@ import request from "@/util/request" const testEditorRequests = { - fetchSampleData(collectionId, apiEndpointUrl, apiEndpointMethod) { + fetchSampleDataForTestEditor(collectionId, apiEndpointUrl, apiEndpointMethod) { return request({ - url: '/api/fetchSampleData', + url: '/api/fetchSampleDataForTestEditor', method: 'post', data: { apiCollectionId: collectionId, diff --git a/apps/dashboard/web/polaris_web/web/src/apps/dashboard/pages/test_editor/components/SampleApi.jsx b/apps/dashboard/web/polaris_web/web/src/apps/dashboard/pages/test_editor/components/SampleApi.jsx index 887c9c319c..92a2ca2ea2 100644 --- a/apps/dashboard/web/polaris_web/web/src/apps/dashboard/pages/test_editor/components/SampleApi.jsx +++ b/apps/dashboard/web/polaris_web/web/src/apps/dashboard/pages/test_editor/components/SampleApi.jsx @@ -179,7 +179,7 @@ const SampleApi = () => { const fetchSampleData = async (collectionId, apiEndpointUrl, apiEndpointMethod) => { setShowEmptyLayout(false) - const sampleDataResponse = await testEditorRequests.fetchSampleData(collectionId, apiEndpointUrl, apiEndpointMethod) + const sampleDataResponse = await testEditorRequests.fetchSampleDataForTestEditor(collectionId, apiEndpointUrl, apiEndpointMethod) if (sampleDataResponse) { if (sampleDataResponse.sampleDataList.length > 0 && sampleDataResponse.sampleDataList[0].samples && sampleDataResponse.sampleDataList[0].samples.length > 0) { const sampleDataJson = JSON.parse(sampleDataResponse.sampleDataList[0].samples[sampleDataResponse.sampleDataList[0].samples.length - 1])