diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/newactions/base/NewActionServiceCE.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/newactions/base/NewActionServiceCE.java index 7b2c4b71384..b52362f4268 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/newactions/base/NewActionServiceCE.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/newactions/base/NewActionServiceCE.java @@ -78,6 +78,9 @@ Flux findAllByApplicationIdAndViewMode( Flux findAllByApplicationIdAndViewMode( String applicationId, Boolean viewMode, Optional permission, Optional sort); + Flux findAllByApplicationIdAndPluginType( + String applicationId, Boolean viewMode, AclPermission permission, Sort sort, List pluginTypes); + Flux getActionsForViewMode(String applicationId); ActionViewDTO generateActionViewDTO(NewAction action, ActionDTO actionDTO, boolean viewMode); diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/newactions/base/NewActionServiceCEImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/newactions/base/NewActionServiceCEImpl.java index 952a7605d80..127254e2600 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/newactions/base/NewActionServiceCEImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/newactions/base/NewActionServiceCEImpl.java @@ -734,26 +734,18 @@ public Flux findByPageIdAndViewMode(String pageId, Boolean viewMode, } @Override - public Flux findAllByApplicationIdAndViewMode( - String applicationId, Boolean viewMode, AclPermission permission, Sort sort) { + public Flux findAllByApplicationIdAndPluginType( + String applicationId, + Boolean viewMode, + AclPermission permission, + Sort sort, + List excludedPluginTypes) { return repository - .findByApplicationId(applicationId, permission, sort) + .findByApplicationIdAndPluginType(applicationId, excludedPluginTypes, permission, sort) .name(VIEW_MODE_FETCH_ACTIONS_FROM_DB) .tap(Micrometer.observation(observationRegistry)) // In case of view mode being true, filter out all the actions which haven't been published - .flatMap(action -> { - if (Boolean.TRUE.equals(viewMode)) { - // In case we are trying to fetch published actions but this action has not been published, do - // not return - if (action.getPublishedAction() == null) { - return Mono.empty(); - } - } - // No need to handle the edge case of unpublished action not being present. This is not possible - // because every created action starts from an unpublishedAction state. - - return Mono.just(action); - }) + .flatMap(action -> this.filterAction(action, viewMode)) .name(VIEW_MODE_FILTER_ACTION) .tap(Micrometer.observation(observationRegistry)) .flatMap(this::sanitizeAction) @@ -761,6 +753,16 @@ public Flux findAllByApplicationIdAndViewMode( .tap(Micrometer.observation(observationRegistry)); } + @Override + public Flux findAllByApplicationIdAndViewMode( + String applicationId, Boolean viewMode, AclPermission permission, Sort sort) { + return repository + .findByApplicationId(applicationId, permission, sort) + // In case of view mode being true, filter out all the actions which haven't been published + .flatMap(action -> this.filterAction(action, viewMode)) + .flatMap(this::sanitizeAction); + } + @Override public Flux findAllByApplicationIdAndViewMode( String applicationId, Boolean viewMode, Optional permission, Optional sort) { @@ -792,9 +794,12 @@ public Flux getActionsForViewMode(String applicationId) { return Flux.error(new AppsmithException(AppsmithError.INVALID_PARAMETER, FieldName.APPLICATION_ID)); } + List excludedPluginTypes = List.of(PluginType.JS.toString()); + // fetch the published actions by applicationId // No need to sort the results - return findAllByApplicationIdAndViewMode(applicationId, true, actionPermission.getExecutePermission(), null) + return findAllByApplicationIdAndPluginType( + applicationId, true, actionPermission.getExecutePermission(), null, excludedPluginTypes) .name(VIEW_MODE_INITIAL_ACTION) .tap(Micrometer.observation(observationRegistry)) .filter(newAction -> !PluginType.JS.equals(newAction.getPluginType())) @@ -1083,6 +1088,20 @@ public Mono sanitizeAction(NewAction action) { return actionMono; } + public Mono filterAction(NewAction action, Boolean viewMode) { + if (Boolean.TRUE.equals(viewMode)) { + // In case we are trying to fetch published actions but this action has not been published, do + // not return + if (action.getPublishedAction() == null) { + return Mono.empty(); + } + } + // No need to handle the edge case of unpublished action not being present. This is not possible + // because every created action starts from an unpublishedAction state. + + return Mono.just(action); + } + public Flux addMissingPluginDetailsIntoAllActions(List actionList) { Mono> pluginMapMono = Mono.just(defaultPluginMap); diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/CustomNewActionRepositoryCE.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/CustomNewActionRepositoryCE.java index 47957edb548..6026e79bc62 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/CustomNewActionRepositoryCE.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/CustomNewActionRepositoryCE.java @@ -37,6 +37,9 @@ Flux findAllActionsByNameAndPageIdsAndViewMode( Flux findByApplicationId(String applicationId, AclPermission aclPermission, Sort sort); + Flux findByApplicationIdAndPluginType( + String applicationId, List pluginTypes, AclPermission aclPermission, Sort sort); + Flux findByApplicationId( String applicationId, Optional aclPermission, Optional sort); diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/CustomNewActionRepositoryCEImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/CustomNewActionRepositoryCEImpl.java index 37de19d0f3d..5913e10ced0 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/CustomNewActionRepositoryCEImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/CustomNewActionRepositoryCEImpl.java @@ -22,7 +22,6 @@ import org.springframework.data.mongodb.core.aggregation.MatchOperation; import org.springframework.data.mongodb.core.aggregation.ProjectionOperation; import org.springframework.data.mongodb.core.query.Criteria; -import reactor.core.observability.micrometer.Micrometer; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; @@ -31,7 +30,6 @@ import java.util.Optional; import java.util.Set; -import static com.appsmith.external.constants.spans.ce.ActionSpanCE.VIEW_MODE_FETCH_ACTIONS_FROM_DB_QUERY; import static org.springframework.data.mongodb.core.aggregation.Aggregation.group; import static org.springframework.data.mongodb.core.aggregation.Aggregation.match; import static org.springframework.data.mongodb.core.aggregation.Aggregation.newAggregation; @@ -52,9 +50,7 @@ public Flux findByApplicationId(String applicationId, AclPermission a return queryBuilder() .criteria(getCriterionForFindByApplicationId(applicationId)) .permission(aclPermission) - .all() - .name(VIEW_MODE_FETCH_ACTIONS_FROM_DB_QUERY) - .tap(Micrometer.observation(observationRegistry)); + .all(); } @Override @@ -206,6 +202,26 @@ protected BridgeQuery getCriterionForFindByApplicationId(String appli return Bridge.equal(NewAction.Fields.applicationId, applicationId); } + @Override + public Flux findByApplicationIdAndPluginType( + String applicationId, List excludedPluginTypes, AclPermission aclPermission, Sort sort) { + return queryBuilder() + .criteria(getCriterionForFindByApplicationIdAndPluginType(applicationId, excludedPluginTypes)) + .permission(aclPermission) + .sort(sort) + .all(); + } + + protected BridgeQuery getCriterionForFindByApplicationIdAndPluginType( + String applicationId, List excludedPluginTypes) { + final BridgeQuery q = getCriterionForFindByApplicationId(applicationId); + q.and(Bridge.or( + Bridge.notIn(NewAction.Fields.pluginType, excludedPluginTypes), + Bridge.isNull(NewAction.Fields.pluginType))); + + return q; + } + @Override public Flux findByApplicationIdAndViewMode( String applicationId, Boolean viewMode, AclPermission aclPermission) {