Skip to content

Commit

Permalink
fix: code review changes done
Browse files Browse the repository at this point in the history
  • Loading branch information
“sneha122” committed Aug 23, 2024
1 parent 475f0db commit f0cf9b2
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -735,25 +735,17 @@ public Flux<NewAction> findByPageIdAndViewMode(String pageId, Boolean viewMode,

@Override
public Flux<NewAction> findAllByApplicationIdAndPluginType(
String applicationId, Boolean viewMode, AclPermission permission, Sort sort, List<String> pluginTypes) {
String applicationId,
Boolean viewMode,
AclPermission permission,
Sort sort,
List<String> excludedPluginTypes) {
return repository
.findByApplicationIdAndPluginType(applicationId, pluginTypes, 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)
Expand All @@ -767,19 +759,7 @@ public Flux<NewAction> findAllByApplicationIdAndViewMode(
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 -> {
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))
.flatMap(this::sanitizeAction);
}

Expand Down Expand Up @@ -814,18 +794,12 @@ public Flux<ActionViewDTO> getActionsForViewMode(String applicationId) {
return Flux.error(new AppsmithException(AppsmithError.INVALID_PARAMETER, FieldName.APPLICATION_ID));
}

List<String> pluginTypes = List.of(
PluginType.DB.toString(),
PluginType.API.toString(),
PluginType.SAAS.toString(),
PluginType.REMOTE.toString(),
PluginType.AI.toString(),
PluginType.INTERNAL.toString());
List<String> excludedPluginTypes = List.of(PluginType.JS.toString());

// fetch the published actions by applicationId
// No need to sort the results
return findAllByApplicationIdAndPluginType(
applicationId, true, actionPermission.getExecutePermission(), null, pluginTypes)
applicationId, true, actionPermission.getExecutePermission(), null, excludedPluginTypes)
.name(VIEW_MODE_INITIAL_ACTION)
.tap(Micrometer.observation(observationRegistry))
.filter(newAction -> !PluginType.JS.equals(newAction.getPluginType()))
Expand Down Expand Up @@ -1114,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 @@ -204,19 +204,20 @@ protected BridgeQuery<NewAction> getCriterionForFindByApplicationId(String appli

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

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

return q;
}
Expand Down

0 comments on commit f0cf9b2

Please sign in to comment.