Skip to content

Commit

Permalink
Merge pull request #1870 from akto-api-security/hotfix/fix_add_to_gro…
Browse files Browse the repository at this point in the history
…ups_count

Hotfix/fix add to groups count
  • Loading branch information
Ark2307 authored Dec 30, 2024
2 parents bff0279 + 84f9377 commit 5e02f5e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,25 @@ public List<ApiCollection> fillApiCollectionsUrlCount(List<ApiCollection> 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);
Expand Down Expand Up @@ -396,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());

Expand Down
1 change: 0 additions & 1 deletion libs/dao/src/main/java/com/akto/dto/ApiCollection.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 5e02f5e

Please sign in to comment.