From f70987c52f7a3ef324ea6fa97e96b162affa2480 Mon Sep 17 00:00:00 2001 From: Nilansh Bansal Date: Thu, 5 Jan 2023 12:28:47 +0530 Subject: [PATCH] fix: Updated isPublic field to fetch from Permission groups (#19132) ## Description > Fixes the `isPublic` field in the update application API `/applications/{applicationId} (PUT)` response. Fixes #19131 ### Media https://user-images.githubusercontent.com/25542733/209096894-2d88d20d-6636-4d8a-9bf0-7a04a95f75dd.mov ## Type of change - Bug fix (non-breaking change which fixes an issue) ## How Has This Been Tested? - Manual ## Checklist: ### Dev activity - [x] My code follows the style guidelines of this project - [x] I have performed a self-review of my own code - [ ] I have commented my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [x] My changes generate no new warnings - [ ] I have added tests that prove my fix is effective or that my feature works - [ ] New and existing unit tests pass locally with my changes - [ ] PR is being merged under a feature flag ### QA activity: - [ ] Test plan has been approved by relevant developers - [ ] Test plan has been peer reviewed by QA - [ ] Cypress test cases have been added and approved by either SDET or manual QA - [ ] Organized project review call with relevant stakeholders after Round 1/2 of QA - [ ] Added Test Plan Approved label after reveiwing all Cypress test --- .../services/ce/ApplicationServiceCEImpl.java | 1 + .../services/ce/ApplicationServiceCETest.java | 88 +++++++++++++++++++ 2 files changed, 89 insertions(+) diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/ApplicationServiceCEImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/ApplicationServiceCEImpl.java index decb9719a9..a4d53c4f15 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/ApplicationServiceCEImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/ApplicationServiceCEImpl.java @@ -281,6 +281,7 @@ public class ApplicationServiceCEImpl extends BaseService this.setTransientFields(application1)) .flatMap(application1 -> { final Map eventData = Map.of( FieldName.APP_MODE, ApplicationMode.EDIT.toString(), diff --git a/app/server/appsmith-server/src/test/java/com/appsmith/server/services/ce/ApplicationServiceCETest.java b/app/server/appsmith-server/src/test/java/com/appsmith/server/services/ce/ApplicationServiceCETest.java index 8d59745fe4..10793194f7 100644 --- a/app/server/appsmith-server/src/test/java/com/appsmith/server/services/ce/ApplicationServiceCETest.java +++ b/app/server/appsmith-server/src/test/java/com/appsmith/server/services/ce/ApplicationServiceCETest.java @@ -3298,4 +3298,92 @@ public class ApplicationServiceCETest { .verifyComplete(); } + + + /** + * Test case which proves the non-dependency of isPublic Field in Update Application API Response + * on the deprecated Application collection isPublic field for a public application + * The following steps are followed: + * 1. Create a new app + * 2. Invoke the changeViewAccess method to set the App "Public" + * 3. Invoke the update method and assert the "isPublic" field in the response + */ + @Test + @WithUserDetails(value = "api_user") + public void validPublicAppUpdateApplication() { + Application application = new Application(); + application.setName("validPublicAppUpdateApplication-Test"); + + Application createdApplication = applicationPageService.createApplication(application, workspaceId).block(); + + /** + * Making the App public using changeViewAccess method which changes the permission groups of the app to allow public access + */ + ApplicationAccessDTO applicationAccessDTO = new ApplicationAccessDTO(); + applicationAccessDTO.setPublicAccess(true); + Application publicAccessApplication = applicationService.changeViewAccess(createdApplication.getId(), applicationAccessDTO).block(); + + /** + * setIsPublic to False, purposely set to prove non-dependency on this field of the output + */ + publicAccessApplication.setIsPublic(false); + + /** + * Using the Update App method and asserting the response to verify the isPublic field in the response is True + * which proves it's non-dependency on the deprecated Application collection isPublic field + * and shows it dependency on the actual app permissions and state of the app which has been set public in this case + **/ + Mono updatedApplication = applicationService.update(createdApplication.getId(), publicAccessApplication); + StepVerifier.create(updatedApplication) + .assertNext(t -> { + assertThat(t).isNotNull(); + assertThat(t.getId()).isNotNull(); + assertThat(t.getIsPublic()).isTrue(); + }) + .verifyComplete(); + } + + /** + * Test case which proves the non-dependency of isPublic Field in Update Application API Response + * on the deprecated Application collection isPublic field for a public application + * The following steps are followed: + * 1. Create a new app + * 2. Invoke the changeViewAccess method to set the App "Public" + * 3. Invoke the update method and assert the "isPublic" field in the response + */ + @Test + @WithUserDetails(value = "api_user") + public void validPrivateAppUpdateApplication() { + Application application = new Application(); + application.setName("validPrivateAppUpdateApplication-Test"); + + Application createdApplication = applicationPageService.createApplication(application, workspaceId).block(); + + /** + * Making the App private using changeViewAccess method which changes the permission groups of the app to restrict public access + */ + ApplicationAccessDTO applicationAccessDTO = new ApplicationAccessDTO(); + applicationAccessDTO.setPublicAccess(false); + + Application privateAccessApplication = applicationService.changeViewAccess(createdApplication.getId(), applicationAccessDTO).block(); + + /** + * setIsPublic to True, purposely set to prove non-dependency on this field of the output + */ + privateAccessApplication.setIsPublic(true); + + /** + * Using the Update App method and asserting the response to verify the isPublic field in the response is False + * which proves it's non-dependency on the deprecated Application collection isPublic field + * and shows it dependency on the actual app permissions and state of the app which has been set private in this case + **/ + Mono updatedApplication = applicationService.update(createdApplication.getId(), privateAccessApplication); + StepVerifier.create(updatedApplication) + .assertNext(t -> { + assertThat(t).isNotNull(); + assertThat(t.getId()).isNotNull(); + assertThat(t.getIsPublic()).isFalse(); + }) + .verifyComplete(); + } }