From 4dc62f7077b5e949ca6b3bd8848def7c854134d3 Mon Sep 17 00:00:00 2001 From: Ark2307 Date: Mon, 30 Dec 2024 16:52:18 +0530 Subject: [PATCH 1/2] Fixing count for api groups --- .../com/akto/action/ApiCollectionsAction.java | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/apps/dashboard/src/main/java/com/akto/action/ApiCollectionsAction.java b/apps/dashboard/src/main/java/com/akto/action/ApiCollectionsAction.java index db9372f096..440c3ad77e 100644 --- a/apps/dashboard/src/main/java/com/akto/action/ApiCollectionsAction.java +++ b/apps/dashboard/src/main/java/com/akto/action/ApiCollectionsAction.java @@ -84,11 +84,25 @@ public List fillApiCollectionsUrlCount(List apiCol int apiCollectionId = apiCollection.getId(); Integer count = countMap.get(apiCollectionId); int fallbackCount = apiCollection.getUrls()!=null ? apiCollection.getUrls().size() : apiCollection.getUrlsCount(); - if (count != null && (apiCollection.getHostName() != null)) { apiCollection.setUrlsCount(count); } else if(ApiCollection.Type.API_GROUP.equals(apiCollection.getType())){ - if (count == null) { + int conditionsCount = 0; + if(!apiCollection.getAutomated()){ + ApiCollection apiCollectionWithCond = ApiCollectionsDao.instance.findOne(Filters.eq(Constants.ID, apiCollection.getId()), Projections.include("conditions")); + if(apiCollectionWithCond.getConditions() != null && apiCollectionWithCond.getConditions().get(0) != null){ + if(apiCollectionWithCond.getConditions().get(0).getType().equals(TestingEndpoints.Type.CUSTOM)){ + CustomTestingEndpoints testingEndpoints = (CustomTestingEndpoints) apiCollectionWithCond.getConditions().get(0); + if(testingEndpoints.getApisList() != null && !testingEndpoints.getApisList().isEmpty()){ + conditionsCount = testingEndpoints.getApisList().size(); + } + } + } + } + + if(conditionsCount != 0){ + count = conditionsCount; + }else if (count == null) { count = fallbackCount; } apiCollection.setUrlsCount(count); From 84f93778d0a16b9d1b2f00ab269aecc32f5369e3 Mon Sep 17 00:00:00 2001 From: Ark2307 Date: Mon, 30 Dec 2024 17:36:40 +0530 Subject: [PATCH 2/2] Added debug logs --- .../src/main/java/com/akto/action/ApiCollectionsAction.java | 3 +++ libs/dao/src/main/java/com/akto/dto/ApiCollection.java | 1 - 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/apps/dashboard/src/main/java/com/akto/action/ApiCollectionsAction.java b/apps/dashboard/src/main/java/com/akto/action/ApiCollectionsAction.java index 440c3ad77e..efb90f2876 100644 --- a/apps/dashboard/src/main/java/com/akto/action/ApiCollectionsAction.java +++ b/apps/dashboard/src/main/java/com/akto/action/ApiCollectionsAction.java @@ -410,8 +410,11 @@ public String addApisToCustomCollection(){ return ERROR.toUpperCase(); } + loggerMaker.infoAndAddToDb("Started adding " + this.apiList.size() + " apis into custom collection.", LogDb.DASHBOARD); + CustomTestingEndpoints condition = new CustomTestingEndpoints(apiList, CustomTestingEndpoints.Operator.OR); apiCollection.addToConditions(condition); + loggerMaker.infoAndAddToDb("Final conditions for collection: " + apiCollection.getName() + " are: " + apiCollection.getConditions().toString()); ApiCollectionUsers.updateApiCollection(apiCollection.getConditions(), apiCollection.getId()); ApiCollectionUsers.addToCollectionsForCollectionId(apiCollection.getConditions(), apiCollection.getId()); diff --git a/libs/dao/src/main/java/com/akto/dto/ApiCollection.java b/libs/dao/src/main/java/com/akto/dto/ApiCollection.java index 56f479ffa0..d98a692060 100644 --- a/libs/dao/src/main/java/com/akto/dto/ApiCollection.java +++ b/libs/dao/src/main/java/com/akto/dto/ApiCollection.java @@ -4,7 +4,6 @@ import java.util.Arrays; import java.util.HashSet; import java.util.List; -import java.util.Objects; import java.util.Set; import org.bson.codecs.pojo.annotations.BsonId;