Merge branch 'feature/view-published-page' into 'master'
Endpoint to view published page using just PageId Fixes #83 We now return all the published layouts for a given pageId in the view mode. In the future, we will whittle the layouts down based on query parameters and other factors to return a single layout in the published page. Today, since most pages only have a single layout, there is no performance impact. See merge request theappsmith/internal-tools-server!76
This commit is contained in:
commit
98662714dc
|
|
@ -3,7 +3,6 @@ package com.appsmith.server.configurations;
|
|||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.SerializationFeature;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
|
|
|
|||
|
|
@ -32,4 +32,10 @@ public class PageController extends BaseController<PageService, Page, String> {
|
|||
.collectList()
|
||||
.map(resources -> new ResponseDTO<>(HttpStatus.OK.value(), resources, null));
|
||||
}
|
||||
|
||||
@GetMapping("/{pageId}/view")
|
||||
public Mono<ResponseDTO<Page>> getPageView(@PathVariable String pageId) {
|
||||
return service.getPage(pageId, true)
|
||||
.map(page -> new ResponseDTO<>(HttpStatus.OK.value(), page, null));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@ public class LayoutServiceImpl implements LayoutService {
|
|||
public Mono<Layout> getLayout(String pageId, String layoutId, Boolean viewMode) {
|
||||
return pageService.findByIdAndLayoutsId(pageId, layoutId)
|
||||
.switchIfEmpty(Mono.error(new AppsmithException(AppsmithError.INVALID_PARAMETER, FieldName.PAGEID + " or " + FieldName.LAYOUTID)))
|
||||
.flatMap(pageService::doesPageIdBelongToCurrentUserOrganization)
|
||||
.flatMap(pageService::doesPageBelongToCurrentUserOrganization)
|
||||
//The pageId given is correct and belongs to the current user's organization.
|
||||
.map(page -> {
|
||||
List<Layout> layoutList = page.getLayouts();
|
||||
|
|
@ -73,7 +73,7 @@ public class LayoutServiceImpl implements LayoutService {
|
|||
public Mono<Layout> updateLayout(String pageId, String layoutId, Layout layout) {
|
||||
return pageService.findByIdAndLayoutsId(pageId, layoutId)
|
||||
.switchIfEmpty(Mono.error(new AppsmithException(AppsmithError.INVALID_PARAMETER, FieldName.PAGEID + " or " + FieldName.LAYOUTID)))
|
||||
.flatMap(pageService::doesPageIdBelongToCurrentUserOrganization)
|
||||
.flatMap(pageService::doesPageBelongToCurrentUserOrganization)
|
||||
//The pageId given is correct and belongs to the current user's organization.
|
||||
.map(page -> {
|
||||
List<Layout> layoutList = page.getLayouts();
|
||||
|
|
|
|||
|
|
@ -13,11 +13,13 @@ public interface PageService extends CrudService<Page, String> {
|
|||
|
||||
Mono<Page> findByIdAndLayoutsId(String pageId, String layoutId);
|
||||
|
||||
Mono<Page> doesPageIdBelongToCurrentUserOrganization(Page page);
|
||||
Mono<Page> doesPageBelongToCurrentUserOrganization(Page page);
|
||||
|
||||
Mono<Page> findByName(String name);
|
||||
|
||||
Mono<Void> deleteAll();
|
||||
|
||||
Flux<PageNameIdDTO> findNamesByApplicationId(String applicationId);
|
||||
|
||||
Mono<Page> getPage(String pageId, Boolean viewMode);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -86,7 +86,7 @@ public class PageServiceImpl extends BaseService<PageRepository, Page, String> i
|
|||
}
|
||||
|
||||
@Override
|
||||
public Mono<Page> doesPageIdBelongToCurrentUserOrganization(Page page) {
|
||||
public Mono<Page> doesPageBelongToCurrentUserOrganization(Page page) {
|
||||
Mono<User> userMono = sessionUserService.getCurrentUser();
|
||||
final String[] username = {null};
|
||||
|
||||
|
|
@ -121,4 +121,21 @@ public class PageServiceImpl extends BaseService<PageRepository, Page, String> i
|
|||
public Flux<PageNameIdDTO> findNamesByApplicationId(String applicationId) {
|
||||
return repository.findByApplicationId(applicationId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mono<Page> getPage(String pageId, Boolean viewMode) {
|
||||
return repository.findById(pageId)
|
||||
.switchIfEmpty(Mono.error(new AppsmithException(AppsmithError.INVALID_PARAMETER, FieldName.PAGEID)))
|
||||
.flatMap(this::doesPageBelongToCurrentUserOrganization)
|
||||
//The pageId given is correct and belongs to the current user's organization.
|
||||
.map(page -> {
|
||||
List<Layout> layoutList = page.getLayouts();
|
||||
// Set the view mode for all the layouts in the page. This ensures that we send the correct DSL
|
||||
// back to the client
|
||||
layoutList.stream()
|
||||
.forEach(layout -> layout.setViewMode(viewMode));
|
||||
page.setLayouts(layoutList);
|
||||
return page;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,7 +9,6 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||
import org.springframework.stereotype.Component;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user