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 61885bc6e8..c08b079267 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 @@ -27,4 +27,6 @@ public interface CustomNewPageRepositoryCE extends AppsmithRepository { 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 07ee57c4d6..69041e3d54 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; @@ -43,6 +47,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; @@ -58,7 +83,7 @@ public class CustomNewPageRepositoryCEImpl extends BaseAppsmithRepositoryImpl { + log.debug("Retrieved possible application ids for page, picking the appropriate one now"); if (newPage.getDefaultResources() != null) { return newPage.getDefaultResources().getApplicationId(); } else {