Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: moved js filter to mongoDB #35826

Merged
merged 2 commits into from
Aug 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ Flux<NewAction> findAllByApplicationIdAndViewMode(
Flux<NewAction> findAllByApplicationIdAndViewMode(
String applicationId, Boolean viewMode, Optional<AclPermission> permission, Optional<Sort> sort);

Flux<NewAction> findAllByApplicationIdAndPluginType(
String applicationId, Boolean viewMode, AclPermission permission, Sort sort, List<String> pluginTypes);

Flux<ActionViewDTO> getActionsForViewMode(String applicationId);

ActionViewDTO generateActionViewDTO(NewAction action, ActionDTO actionDTO, boolean viewMode);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -734,33 +734,35 @@ public Flux<NewAction> findByPageIdAndViewMode(String pageId, Boolean viewMode,
}

@Override
public Flux<NewAction> findAllByApplicationIdAndViewMode(
String applicationId, Boolean viewMode, AclPermission permission, Sort sort) {
public Flux<NewAction> findAllByApplicationIdAndPluginType(
String applicationId,
Boolean viewMode,
AclPermission permission,
Sort sort,
List<String> 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)
.name(VIEW_MODE_SANITISE_ACTION)
.tap(Micrometer.observation(observationRegistry));
}

@Override
public Flux<NewAction> 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<NewAction> findAllByApplicationIdAndViewMode(
String applicationId, Boolean viewMode, Optional<AclPermission> permission, Optional<Sort> sort) {
Expand Down Expand Up @@ -792,9 +794,12 @@ public Flux<ActionViewDTO> getActionsForViewMode(String applicationId) {
return Flux.error(new AppsmithException(AppsmithError.INVALID_PARAMETER, FieldName.APPLICATION_ID));
}

List<String> 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()))
sneha122 marked this conversation as resolved.
Show resolved Hide resolved
Expand Down Expand Up @@ -1083,6 +1088,20 @@ public Mono<NewAction> sanitizeAction(NewAction action) {
return actionMono;
}

public Mono<NewAction> 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<NewAction> addMissingPluginDetailsIntoAllActions(List<NewAction> actionList) {

Mono<Map<String, Plugin>> pluginMapMono = Mono.just(defaultPluginMap);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ Flux<NewAction> findAllActionsByNameAndPageIdsAndViewMode(

Flux<NewAction> findByApplicationId(String applicationId, AclPermission aclPermission, Sort sort);

Flux<NewAction> findByApplicationIdAndPluginType(
String applicationId, List<String> pluginTypes, AclPermission aclPermission, Sort sort);

Flux<NewAction> findByApplicationId(
String applicationId, Optional<AclPermission> aclPermission, Optional<Sort> sort);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
Expand All @@ -52,9 +50,7 @@ public Flux<NewAction> 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
Expand Down Expand Up @@ -206,6 +202,26 @@ protected BridgeQuery<NewAction> getCriterionForFindByApplicationId(String appli
return Bridge.equal(NewAction.Fields.applicationId, applicationId);
}

@Override
public Flux<NewAction> findByApplicationIdAndPluginType(
String applicationId, List<String> excludedPluginTypes, AclPermission aclPermission, Sort sort) {
return queryBuilder()
.criteria(getCriterionForFindByApplicationIdAndPluginType(applicationId, excludedPluginTypes))
.permission(aclPermission)
.sort(sort)
.all();
}

protected BridgeQuery<NewAction> getCriterionForFindByApplicationIdAndPluginType(
String applicationId, List<String> excludedPluginTypes) {
final BridgeQuery<NewAction> q = getCriterionForFindByApplicationId(applicationId);
q.and(Bridge.or(
Bridge.notIn(NewAction.Fields.pluginType, excludedPluginTypes),
Bridge.isNull(NewAction.Fields.pluginType)));

return q;
}

@Override
public Flux<NewAction> findByApplicationIdAndViewMode(
String applicationId, Boolean viewMode, AclPermission aclPermission) {
Expand Down
Loading