diff --git a/app/server/appsmith-interfaces/src/main/java/com/appsmith/external/models/DefaultResources.java b/app/server/appsmith-interfaces/src/main/java/com/appsmith/external/models/DefaultResources.java index 6878a16defe7..967b46dedcaf 100644 --- a/app/server/appsmith-interfaces/src/main/java/com/appsmith/external/models/DefaultResources.java +++ b/app/server/appsmith-interfaces/src/main/java/com/appsmith/external/models/DefaultResources.java @@ -8,13 +8,30 @@ */ @Data public class DefaultResources { + /** + * When present, actionId will hold the default action id + */ String actionId; + /** + * When present, applicationId will hold the default application id + */ String applicationId; + /** + * When present, pageId will hold the default page id + */ String pageId; + /** + * When present, collectionId will hold the default collection id + */ String collectionId; + /** + * When present, branchName will hold the current branch name. + * For example, if we've a page in both main and develop branch, then default resources of those two pages will + * have same applicationId, pageId but branchName will contain the corresponding branch name. + */ String branchName; } diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/actioncollections/base/ActionCollectionServiceCEImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/actioncollections/base/ActionCollectionServiceCEImpl.java index 390324d2b151..a02e57886ad9 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/actioncollections/base/ActionCollectionServiceCEImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/actioncollections/base/ActionCollectionServiceCEImpl.java @@ -313,7 +313,7 @@ public Flux getActionCollectionsByViewMode( pageIds.add(params.getFirst(FieldName.PAGE_ID)); } return repository - .findAllActionCollectionsByNamePageIdsViewModeAndBranch( + .findAllActionCollectionsByNameDefaultPageIdsViewModeAndBranch( name, pageIds, viewMode, branch, actionPermission.getReadPermission(), sort) .flatMap(actionCollection -> generateActionCollectionByViewMode(actionCollection, viewMode)); } diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/CustomActionCollectionRepositoryCE.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/CustomActionCollectionRepositoryCE.java index 6e31c8b72aad..5cf44152cda8 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/CustomActionCollectionRepositoryCE.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/CustomActionCollectionRepositoryCE.java @@ -23,7 +23,7 @@ Flux findByApplicationId( Flux findByApplicationIdAndViewMode( String applicationId, boolean viewMode, AclPermission aclPermission); - Flux findAllActionCollectionsByNamePageIdsViewModeAndBranch( + Flux findAllActionCollectionsByNameDefaultPageIdsViewModeAndBranch( String name, List pageIds, boolean viewMode, diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/CustomActionCollectionRepositoryCEImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/CustomActionCollectionRepositoryCEImpl.java index 2af549e48170..13c40b4c45a4 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/CustomActionCollectionRepositoryCEImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/CustomActionCollectionRepositoryCEImpl.java @@ -84,7 +84,7 @@ public Flux findByApplicationIdAndViewMode( } @Override - public Flux findAllActionCollectionsByNamePageIdsViewModeAndBranch( + public Flux findAllActionCollectionsByNameDefaultPageIdsViewModeAndBranch( String name, List pageIds, boolean viewMode, @@ -114,9 +114,12 @@ public Flux findAllActionCollectionsByNamePageIdsViewModeAndBr } if (pageIds != null && !pageIds.isEmpty()) { - Criteria pageCriteria = where(fieldName(QActionCollection.actionCollection.publishedCollection) + "." - + fieldName(QActionCollection.actionCollection.publishedCollection.pageId)) - .in(pageIds); + String pageIdFieldPath = String.format( + "%s.%s.%s", + fieldName(QActionCollection.actionCollection.publishedCollection), + fieldName(QActionCollection.actionCollection.publishedCollection.defaultResources), + fieldName(QActionCollection.actionCollection.publishedCollection.pageId)); + Criteria pageCriteria = where(pageIdFieldPath).in(pageIds); criteriaList.add(pageCriteria); } } @@ -131,9 +134,12 @@ public Flux findAllActionCollectionsByNamePageIdsViewModeAndBr } if (pageIds != null && !pageIds.isEmpty()) { - Criteria pageCriteria = where(fieldName(QActionCollection.actionCollection.unpublishedCollection) + "." - + fieldName(QActionCollection.actionCollection.unpublishedCollection.pageId)) - .in(pageIds); + String pageIdFieldPath = String.format( + "%s.%s.%s", + fieldName(QActionCollection.actionCollection.unpublishedCollection), + fieldName(QActionCollection.actionCollection.unpublishedCollection.defaultResources), + fieldName(QActionCollection.actionCollection.unpublishedCollection.pageId)); + Criteria pageCriteria = where(pageIdFieldPath).in(pageIds); criteriaList.add(pageCriteria); } diff --git a/app/server/appsmith-server/src/test/java/com/appsmith/server/repositories/ce/CustomActionCollectionRepositoryCEImplTest.java b/app/server/appsmith-server/src/test/java/com/appsmith/server/repositories/ce/CustomActionCollectionRepositoryCEImplTest.java index a00fb88f7987..d16307fafb15 100644 --- a/app/server/appsmith-server/src/test/java/com/appsmith/server/repositories/ce/CustomActionCollectionRepositoryCEImplTest.java +++ b/app/server/appsmith-server/src/test/java/com/appsmith/server/repositories/ce/CustomActionCollectionRepositoryCEImplTest.java @@ -1,6 +1,8 @@ package com.appsmith.server.repositories.ce; +import com.appsmith.external.models.DefaultResources; import com.appsmith.server.domains.ActionCollection; +import com.appsmith.server.dtos.ActionCollectionDTO; import com.appsmith.server.repositories.ActionCollectionRepository; import org.bson.types.ObjectId; import org.junit.jupiter.api.Test; @@ -102,4 +104,69 @@ public void bulkInsert_WhenInsertedWithProvidedId_InsertedWithProvidedId() { }) .verifyComplete(); } + + private void testFindAllActionCollectionsByNamePageIdsViewModeAndBranch(boolean isViewMode) { + String defaultPageId = "default-page-id", branchName = "main", childPageId = "child-page-id"; + + // create action collection that has different values in pageId and defaultResources.pageId + ActionCollection actionCollection = new ActionCollection(); + ActionCollectionDTO actionCollectionDTO = new ActionCollectionDTO(); + actionCollectionDTO.setPageId(childPageId); + actionCollectionDTO.setDefaultResources(new DefaultResources()); + actionCollectionDTO.getDefaultResources().setPageId(defaultPageId); + + if (isViewMode) { + actionCollection.setPublishedCollection(actionCollectionDTO); + } else { + actionCollection.setUnpublishedCollection(actionCollectionDTO); + } + + actionCollection.setDefaultResources(new DefaultResources()); + actionCollection.getDefaultResources().setBranchName(branchName); + + Mono createActionCollectionMono = + actionCollectionRepository.save(actionCollection).cache(); + + // check whether action collection is found when branch and default page id matches + Mono> actionCollectionListMono = createActionCollectionMono + .thenMany(actionCollectionRepository.findAllActionCollectionsByNameDefaultPageIdsViewModeAndBranch( + null, List.of(defaultPageId), isViewMode, branchName, null, null)) + .collectList(); + + StepVerifier.create(actionCollectionListMono) + .assertNext(actionCollectionList -> { + assertThat(actionCollectionList.size()).isEqualTo(1); + }) + .verifyComplete(); + + // check whether action collection is not found when branch name does not match + Mono> actionCollectionListMono2 = createActionCollectionMono + .thenMany(actionCollectionRepository.findAllActionCollectionsByNameDefaultPageIdsViewModeAndBranch( + null, List.of(defaultPageId), isViewMode, "feature", null, null)) + .collectList(); + + StepVerifier.create(actionCollectionListMono2) + .assertNext(actionCollectionList -> { + assertThat(actionCollectionList.size()).isEqualTo(0); + }) + .verifyComplete(); + + // check whether action collection is not found when default page id does not match + Mono> actionCollectionListMono3 = createActionCollectionMono + .thenMany(actionCollectionRepository.findAllActionCollectionsByNameDefaultPageIdsViewModeAndBranch( + null, List.of(childPageId), isViewMode, branchName, null, null)) + .collectList(); + + StepVerifier.create(actionCollectionListMono3) + .assertNext(actionCollectionList -> { + assertThat(actionCollectionList.size()).isEqualTo(0); + }) + .verifyComplete(); + } + + @Test + public void findAllActionCollectionsByNamePageIdsViewModeAndBranch_ForChildBranch_Successful() { + testFindAllActionCollectionsByNamePageIdsViewModeAndBranch(false); + testFindAllActionCollectionsByNamePageIdsViewModeAndBranch(true); + } } diff --git a/app/server/appsmith-server/src/test/java/com/appsmith/server/services/ActionCollectionServiceImplTest.java b/app/server/appsmith-server/src/test/java/com/appsmith/server/services/ActionCollectionServiceImplTest.java index 4b4ac455417e..8714548e2959 100644 --- a/app/server/appsmith-server/src/test/java/com/appsmith/server/services/ActionCollectionServiceImplTest.java +++ b/app/server/appsmith-server/src/test/java/com/appsmith/server/services/ActionCollectionServiceImplTest.java @@ -237,7 +237,7 @@ public void testCreateCollection_withRepeatedActionName_throwsError() throws IOE Mockito.when(refactoringService.isNameAllowed(Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any())) .thenReturn(Mono.just(false)); - Mockito.when(actionCollectionRepository.findAllActionCollectionsByNamePageIdsViewModeAndBranch( + Mockito.when(actionCollectionRepository.findAllActionCollectionsByNameDefaultPageIdsViewModeAndBranch( Mockito.any(), Mockito.any(), Mockito.anyBoolean(), @@ -278,7 +278,7 @@ public void testCreateCollection_createActionFailure_returnsWithIncompleteCollec Mockito.when(refactoringService.isNameAllowed(Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any())) .thenReturn(Mono.just(true)); - Mockito.when(actionCollectionRepository.findAllActionCollectionsByNamePageIdsViewModeAndBranch( + Mockito.when(actionCollectionRepository.findAllActionCollectionsByNameDefaultPageIdsViewModeAndBranch( Mockito.any(), Mockito.any(), Mockito.anyBoolean(), @@ -343,7 +343,7 @@ public void testCreateCollection_validCollection_returnsPopulatedCollection() th Mockito.when(refactoringService.isNameAllowed(Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any())) .thenReturn(Mono.just(true)); - Mockito.when(actionCollectionRepository.findAllActionCollectionsByNamePageIdsViewModeAndBranch( + Mockito.when(actionCollectionRepository.findAllActionCollectionsByNameDefaultPageIdsViewModeAndBranch( Mockito.any(), Mockito.any(), Mockito.anyBoolean(),