From 23652a185baa288e23ffb76bb29d436398a96f03 Mon Sep 17 00:00:00 2001 From: Nidhi Date: Thu, 29 Dec 2022 11:24:59 +0530 Subject: [PATCH] chore: Back merge v1.8.15 (#19288) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Should only contain what is already in master branch. Signed-off-by: Shrikant Sharat Kandula Co-authored-by: Arpit Mohan Co-authored-by: Trisha Anand Co-authored-by: Aman Agarwal Co-authored-by: Anand Srinivasan <66776129+eco-monk@users.noreply.github.com> Co-authored-by: Aishwarya-U-R <91450662+Aishwarya-U-R@users.noreply.github.com> Co-authored-by: Goutham Pratapa Co-authored-by: Rohit Agarwal Co-authored-by: Arsalan Yaldram Co-authored-by: Ashit Rath Co-authored-by: balajisoundar Co-authored-by: Anagh Hegde Co-authored-by: Shrikant Sharat Kandula Co-authored-by: Rishabh Rathod Co-authored-by: Manish Kumar <107841575+sondermanish@users.noreply.github.com> Co-authored-by: Arpit Mohan Co-authored-by: keyurparalkar Co-authored-by: Ayush Pahwa Co-authored-by: Parthvi <80334441+Parthvi12@users.noreply.github.com> Co-authored-by: Parthvi Goswami Co-authored-by: Jacob Gillespie Co-authored-by: yatinappsmith <84702014+yatinappsmith@users.noreply.github.com> Co-authored-by: Vishnu Gp Co-authored-by: f0c1s Co-authored-by: Ayangade Adeoluwa <37867493+Irongade@users.noreply.github.com> Co-authored-by: Pawan Kumar Co-authored-by: Dhruvik Neharia Co-authored-by: subratadeypappu Co-authored-by: ChandanBalajiBP Co-authored-by: Tanvi Bhakta Co-authored-by: Anand Srinivasan Co-authored-by: Albin Co-authored-by: arunvjn <32433245+arunvjn@users.noreply.github.com> Co-authored-by: Tolulope Adetula <31691737+Tooluloope@users.noreply.github.com> Co-authored-by: akash-codemonk <67054171+akash-codemonk@users.noreply.github.com> Co-authored-by: “sneha122” <“sneha@appsmith.com”> Co-authored-by: Ankita Kinger Co-authored-by: sidhantgoel Co-authored-by: Rimil Dey --- app/client/src/ce/constants/messages.ts | 1 + .../controllers/ce/PageControllerCE.java | 15 +++-- .../ce/CustomNewPageRepositoryCE.java | 4 +- .../ce/CustomNewPageRepositoryCEImpl.java | 55 ++++++++++++++++--- .../services/ce/NewPageServiceCEImpl.java | 11 +++- 5 files changed, 69 insertions(+), 17 deletions(-) diff --git a/app/client/src/ce/constants/messages.ts b/app/client/src/ce/constants/messages.ts index 10f278dae9..f58c699b9d 100644 --- a/app/client/src/ce/constants/messages.ts +++ b/app/client/src/ce/constants/messages.ts @@ -1049,6 +1049,7 @@ export const MANDATORY_FIELDS_ERROR = () => "Mandatory fields cannot be empty"; // Audit logs begin export const AUDIT_LOGS = () => "Audit Logs"; +export const TRY_AGAIN_WITH_YOUR_FILTER = () => "Try again with your filter"; // Audit logs Upgrade page begin export const INTRODUCING = (featureName: string) => diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/controllers/ce/PageControllerCE.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/controllers/ce/PageControllerCE.java index 86343b3ce1..06345de396 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/controllers/ce/PageControllerCE.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/controllers/ce/PageControllerCE.java @@ -43,8 +43,8 @@ public class PageControllerCE { @Autowired public PageControllerCE(ApplicationPageService applicationPageService, - NewPageService newPageService, - CreateDBTablePageSolution createDBTablePageSolution + NewPageService newPageService, + CreateDBTablePageSolution createDBTablePageSolution ) { this.applicationPageService = applicationPageService; this.newPageService = newPageService; @@ -122,9 +122,10 @@ public class PageControllerCE { * In case the page has never been published, the page gets deleted. * In case the page has been published, this page would eventually get deleted whenever the application is published * next. + * * @param defaultPageId defaultPageId which will be needed to find the actual page that needs to be deleted * @param branchName git branch to find the exact page which needs to be deleted - * @return deleted page DTO + * @return deleted page DTO */ @DeleteMapping("/{defaultPageId}") public Mono> deletePage(@PathVariable String defaultPageId, @@ -155,10 +156,11 @@ public class PageControllerCE { * If Application ID is present, it'll fetch all pages of that application in the provided mode. * if Page ID is present, it'll fetch all pages of the corresponding Application. * If both IDs are present, it'll use the Application ID only and ignore the Page ID + * * @param applicationId Id of the application - * @param pageId id of a page - * @param mode In which mode it's in - * @param branchName name of the current branch + * @param pageId id of a page + * @param mode In which mode it's in + * @param branchName name of the current branch * @return List of ApplicationPagesDTO along with other meta data */ @GetMapping @@ -166,6 +168,7 @@ public class PageControllerCE { @RequestParam(required = false) String pageId, @RequestParam(required = true, defaultValue = "EDIT") ApplicationMode mode, @RequestHeader(name = FieldName.BRANCH_NAME, required = false) String branchName) { + log.debug("Going to fetch applicationPageDTO for applicationId: {}, pageId: {}, branchName: {}, mode: {}", applicationId, pageId, branchName, mode); return newPageService.findApplicationPages(applicationId, pageId, branchName, mode) .map(resources -> new ResponseDTO<>(HttpStatus.OK.value(), resources, null)); } diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/CustomNewPageRepositoryCE.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/CustomNewPageRepositoryCE.java index 5a6e66407a..c6fc344ee5 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/CustomNewPageRepositoryCE.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/CustomNewPageRepositoryCE.java @@ -24,11 +24,13 @@ public interface CustomNewPageRepositoryCE extends AppsmithRepository { Mono findByNameAndApplicationIdAndViewMode(String name, String applicationId, AclPermission aclPermission, Boolean viewMode); - Flux findAllByIds(List ids, AclPermission aclPermission); + Flux findAllPageDTOsByIds(List ids, AclPermission aclPermission); Mono getNameByPageId(String pageId, boolean isPublishedName); Mono findPageByBranchNameAndDefaultPageId(String branchName, String defaultPageId, AclPermission permission); Flux findSlugsByApplicationIds(List applicationIds, AclPermission aclPermission); + + Mono findRootApplicationIdById(String defaultPageId, AclPermission readPermission); } diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/CustomNewPageRepositoryCEImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/CustomNewPageRepositoryCEImpl.java index 4d768b25c8..a941382e4f 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/CustomNewPageRepositoryCEImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/CustomNewPageRepositoryCEImpl.java @@ -5,7 +5,10 @@ import com.appsmith.server.constants.FieldName; import com.appsmith.server.domains.NewPage; import com.appsmith.server.domains.QLayout; import com.appsmith.server.domains.QNewPage; +import com.appsmith.server.domains.User; import com.appsmith.server.dtos.PageDTO; +import com.appsmith.server.exceptions.AppsmithError; +import com.appsmith.server.exceptions.AppsmithException; import com.appsmith.server.repositories.BaseAppsmithRepositoryImpl; import com.appsmith.server.repositories.CacheableRepositoryHelper; import lombok.extern.slf4j.Slf4j; @@ -13,6 +16,7 @@ import org.springframework.data.mongodb.core.ReactiveMongoOperations; import org.springframework.data.mongodb.core.convert.MongoConverter; import org.springframework.data.mongodb.core.query.Criteria; import org.springframework.data.mongodb.core.query.Query; +import org.springframework.security.core.context.ReactiveSecurityContextHolder; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; @@ -50,6 +54,27 @@ public class CustomNewPageRepositoryCEImpl extends BaseAppsmithRepositoryImpl findRootApplicationIdById(String id, AclPermission permission) { + if (id == null) { + return Mono.error(new AppsmithException(AppsmithError.INVALID_PARAMETER, FieldName.ID)); + } + return ReactiveSecurityContextHolder.getContext() + .map(ctx -> ctx.getAuthentication()) + .map(auth -> auth.getPrincipal()) + .flatMap(principal -> getAllPermissionGroupsForUser((User) principal)) + .flatMap(permissionGroups -> { + Query query = new Query(getIdCriteria(id)); + query.fields().include(FieldName.APPLICATION_ID, FieldName.DEFAULT_RESOURCES); + query.addCriteria(new Criteria().andOperator(notDeleted(), userAcl(permissionGroups, permission))); + + return mongoOperations.query(this.genericDomain) + .matching(query) + .one() + .flatMap(obj -> setUserPermissionsInObject(obj, permissionGroups)); + }); + } + @Override public Mono findByIdAndLayoutsIdAndViewMode(String id, String layoutId, AclPermission aclPermission, Boolean viewMode) { String layoutsIdKey; @@ -65,7 +90,7 @@ public class CustomNewPageRepositoryCEImpl extends BaseAppsmithRepositoryImpl findAllByIds(List ids, AclPermission aclPermission) { - Criteria idsCriterion = where("id") - .in(ids); + public Flux findAllPageDTOsByIds(List ids, AclPermission aclPermission) { + ArrayList includedFields = new ArrayList<>(List.of( + FieldName.APPLICATION_ID, + FieldName.DEFAULT_RESOURCES, + "unpublishedPage.name", + "unpublishedPage.isHidden", + "unpublishedPage.slug", + "unpublishedPage.customSlug", + "publishedPage.name", + "publishedPage.isHidden", + "publishedPage.slug", + "publishedPage.customSlug" + )); - return queryAll(List.of(idsCriterion), aclPermission); + Criteria idsCriterion = where("id").in(ids); + + return this.queryAll( + new ArrayList<>(List.of(idsCriterion)), + includedFields, + aclPermission, + null); } private Criteria getNameCriterion(String name, Boolean viewMode) { diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/NewPageServiceCEImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/NewPageServiceCEImpl.java index 30b7f1d0a2..deb589754b 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/NewPageServiceCEImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/NewPageServiceCEImpl.java @@ -244,6 +244,7 @@ public class NewPageServiceCEImpl extends BaseService { + log.debug("Fetched application data for id: {}", applicationId); if (markApplicationAsRecentlyAccessed) { // add this application and workspace id to the recently used list in UserData return userDataService.updateLastUsedAppAndWorkspaceList(application) @@ -282,13 +283,15 @@ public class NewPageServiceCEImpl extends BaseService page.getId()).collect(Collectors.toList()); }) - .flatMapMany(pageIds -> repository.findAllByIds(pageIds, pagePermission.getReadPermission())) + .flatMapMany(pageIds -> repository.findAllPageDTOsByIds(pageIds, pagePermission.getReadPermission())) .collectList() .flatMap(pagesFromDb -> Mono.zip( Mono.just(pagesFromDb), defaultPageIdMono, applicationMono - )).flatMap(tuple -> { + )) + .flatMap(tuple -> { + log.debug("Retrieved Page DTOs from DB ..."); List pagesFromDb = tuple.getT1(); String defaultPageId = tuple.getT2(); @@ -353,6 +356,7 @@ public class NewPageServiceCEImpl extends BaseService { + log.debug("Populating applicationPagesDTO ..."); Application application = tuple.getT1(); application.setPages(null); application.setPublishedPages(null); @@ -591,7 +595,7 @@ public class NewPageServiceCEImpl extends BaseService { + log.debug("Retrieved possible application ids for page, picking the appropriate one now"); if (newPage.getDefaultResources() != null) { return newPage.getDefaultResources().getApplicationId(); } else {