Skip to content

Commit

Permalink
fix: separated pageId method from appId
Browse files Browse the repository at this point in the history
  • Loading branch information
“sneha122” committed Sep 5, 2024
1 parent a81cfd7 commit 1535b0c
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,9 @@ Flux<NewAction> findAllByApplicationIdAndViewMode(
Flux<NewAction> findAllByApplicationIdAndViewMode(
String applicationId, Boolean viewMode, Optional<AclPermission> permission, Optional<Sort> sort);

Flux<NewAction> findAllPublishedActionsByPageIdAndExcludedPluginTypes(
String pageId, AclPermission permission, Sort sort, List<String> excludedPluginTypes);
Flux<ActionViewDTO> getActionsForViewMode(String applicationId);

Flux<ActionViewDTO> getActionsForViewMode(String pageId);
Flux<ActionViewDTO> getActionsForViewModeByPageId(String pageId);

ActionViewDTO generateActionViewDTO(NewAction action, ActionDTO actionDTO, boolean viewMode);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -729,15 +729,6 @@ public Flux<NewAction> findByPageIdAndViewMode(String pageId, Boolean viewMode,
return repository.findByPageIdAndViewMode(pageId, viewMode, permission).flatMap(this::sanitizeAction);
}

@Override
public Flux<NewAction> findAllPublishedActionsByPageIdAndExcludedPluginTypes(
String pageId, AclPermission permission, Sort sort, List<String> excludedPluginTypes) {
return repository
.findPublishedActionsByPageIdAndExcludedPluginType(pageId, excludedPluginTypes, permission, sort)
.name(VIEW_MODE_FETCH_ACTIONS_FROM_DB)
.tap(Micrometer.observation(observationRegistry));
}

@Override
public Flux<NewAction> findAllByApplicationIdAndViewMode(
String applicationId, Boolean viewMode, AclPermission permission, Sort sort) {
Expand Down Expand Up @@ -772,8 +763,26 @@ public Flux<NewAction> findAllByApplicationIdAndViewMode(
.flatMapMany(this::addMissingPluginDetailsIntoAllActions);
}

public Flux<ActionViewDTO> getActionsForViewMode(String applicationId) {

if (applicationId == null || applicationId.isEmpty()) {
return Flux.error(new AppsmithException(AppsmithError.INVALID_PARAMETER, FieldName.PAGE_ID));
}

List<String> excludedPluginTypes = List.of(PluginType.JS.toString());

// fetch the published actions by appId
// No need to sort the results
return repository
.findPublishedActionsByAppIdAndExcludedPluginType(
applicationId, excludedPluginTypes, actionPermission.getExecutePermission(), null)
.name(VIEW_MODE_FETCH_ACTIONS_FROM_DB)
.tap(Micrometer.observation(observationRegistry))
.map(action -> generateActionViewDTO(action, action.getPublishedAction(), true));
}

@Override
public Flux<ActionViewDTO> getActionsForViewMode(String pageId) {
public Flux<ActionViewDTO> getActionsForViewModeByPageId(String pageId) {

if (pageId == null || pageId.isEmpty()) {
return Flux.error(new AppsmithException(AppsmithError.INVALID_PARAMETER, FieldName.PAGE_ID));
Expand All @@ -783,8 +792,11 @@ public Flux<ActionViewDTO> getActionsForViewMode(String pageId) {

// fetch the published actions by pageId
// No need to sort the results
return findAllPublishedActionsByPageIdAndExcludedPluginTypes(
pageId, actionPermission.getExecutePermission(), null, excludedPluginTypes)
return repository
.findPublishedActionsByPageIdAndExcludedPluginType(
pageId, excludedPluginTypes, actionPermission.getExecutePermission(), null)
.name(VIEW_MODE_FETCH_ACTIONS_FROM_DB)
.tap(Micrometer.observation(observationRegistry))
.map(action -> generateActionViewDTO(action, action.getPublishedAction(), true));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ Flux<NewAction> findAllActionsByNameAndPageIdsAndViewMode(
Flux<NewAction> findPublishedActionsByPageIdAndExcludedPluginType(
String pageId, List<String> pluginTypes, AclPermission aclPermission, Sort sort);

Flux<NewAction> findPublishedActionsByAppIdAndExcludedPluginType(
String appId, 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 @@ -202,18 +202,38 @@ protected BridgeQuery<NewAction> getCriterionForFindByApplicationId(String appli
return Bridge.equal(NewAction.Fields.applicationId, applicationId);
}

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

protected BridgeQuery<NewAction> getCriterionForFindPublishedActionsByAppIdAndExcludedPluginType(
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)));

q.isNotNull(NewAction.Fields.publishedAction_pageId);
return q;
}

@Override
public Flux<NewAction> findPublishedActionsByPageIdAndExcludedPluginType(
String pageId, List<String> excludedPluginTypes, AclPermission aclPermission, Sort sort) {
return queryBuilder()
.criteria(getCriterionForFindPublishedActionsByApplicationIdAndExcludedPluginType(
pageId, excludedPluginTypes))
.criteria(getCriterionForFindPublishedActionsByPageIdAndExcludedPluginType(pageId, excludedPluginTypes))
.permission(aclPermission)
.sort(sort)
.all();
}

protected BridgeQuery<NewAction> getCriterionForFindPublishedActionsByApplicationIdAndExcludedPluginType(
protected BridgeQuery<NewAction> getCriterionForFindPublishedActionsByPageIdAndExcludedPluginType(
String pageId, List<String> excludedPluginTypes) {
final BridgeQuery<NewAction> q = Bridge.equal(NewAction.Fields.publishedAction_pageId, pageId);
q.and(Bridge.or(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ public Mono<ConsolidatedAPIResponseDTO> getConsolidatedInfoForPageLoad(
: branchedPageMonoCached.map(NewPage::getId);
fetches.add(branchedPageIdMono
.flatMap(branchedPageId -> newActionService
.getActionsForViewMode(branchedPageId)
.getActionsForViewModeByPageId(branchedPageId)
.collectList())
.as(this::toResponseDTO)
.doOnError(e -> log.error("Error fetching actions for view mode", e))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ public void testPageLoadResponseForViewMode() {

ActionViewDTO sampleActionViewDTO = new ActionViewDTO();
sampleActionViewDTO.setName("sampleActionViewDTO");
doReturn(Flux.just(sampleActionViewDTO)).when(spyNewActionService).getActionsForViewMode(anyString());
doReturn(Flux.just(sampleActionViewDTO)).when(spyNewActionService).getActionsForViewModeByPageId(anyString());

ActionCollectionViewDTO sampleActionCollectionViewDTO = new ActionCollectionViewDTO();
sampleActionCollectionViewDTO.setName("sampleActionCollectionViewDTO");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -696,7 +696,7 @@ public void checkActionInViewMode() {
.then(layoutActionService.createSingleAction(action1, Boolean.FALSE))
.then(layoutActionService.createSingleAction(action2, Boolean.FALSE))
.then(applicationPageService.publish(testPage.getApplicationId(), true))
.then(newActionService.getActionsForViewMode(testPage.getId()).collectList());
.then(newActionService.getActionsForViewMode(testApp.getId()).collectList());

StepVerifier.create(actionsListMono)
.assertNext(actionsList -> {
Expand Down Expand Up @@ -752,7 +752,7 @@ public void getActionInViewMode() {
Mono<List<ActionViewDTO>> actionViewModeListMono = createActionMono
// Publish the application before fetching the action in view mode
.then(applicationPageService.publish(testApp.getId(), true))
.then(newActionService.getActionsForViewMode(testPage.getId()).collectList());
.then(newActionService.getActionsForViewMode(testApp.getId()).collectList());

StepVerifier.create(actionViewModeListMono)
.assertNext(actions -> {
Expand Down

0 comments on commit 1535b0c

Please sign in to comment.