Allow client to set layouts without id when creating a page (#3477)
* Allow client to set layouts without id when creating a page * Mild refactoring * Fix Layout action tests
This commit is contained in:
parent
757dead361
commit
e6edbc3b2f
|
|
@ -93,11 +93,18 @@ public class ApplicationPageServiceImpl implements ApplicationPageService {
|
|||
if (layoutList == null) {
|
||||
layoutList = new ArrayList<>();
|
||||
}
|
||||
|
||||
if (layoutList.isEmpty()) {
|
||||
layoutList.add(newPageService.createDefaultLayout());
|
||||
page.setLayouts(layoutList);
|
||||
}
|
||||
|
||||
for (final Layout layout : layoutList) {
|
||||
if (StringUtils.isEmpty(layout.getId())) {
|
||||
layout.setId(new ObjectId().toString());
|
||||
}
|
||||
}
|
||||
|
||||
Mono<Application> applicationMono = applicationService.findById(page.getApplicationId(), AclPermission.MANAGE_APPLICATIONS)
|
||||
.switchIfEmpty(Mono.error(new AppsmithException(AppsmithError.NO_RESOURCE_FOUND, FieldName.APPLICATION, page.getApplicationId())))
|
||||
.cache();
|
||||
|
|
|
|||
|
|
@ -31,8 +31,8 @@ import java.util.List;
|
|||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static com.appsmith.server.acl.AclPermission.READ_PAGES;
|
||||
import static com.appsmith.external.helpers.BeanCopyUtils.copyNewFieldValuesIntoOldObject;
|
||||
import static com.appsmith.server.acl.AclPermission.READ_PAGES;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import com.appsmith.external.plugins.PluginExecutor;
|
|||
import com.appsmith.server.constants.FieldName;
|
||||
import com.appsmith.server.domains.Application;
|
||||
import com.appsmith.server.domains.Datasource;
|
||||
import com.appsmith.server.domains.Layout;
|
||||
import com.appsmith.server.domains.NewAction;
|
||||
import com.appsmith.server.domains.Plugin;
|
||||
import com.appsmith.server.domains.User;
|
||||
|
|
@ -17,6 +18,7 @@ import com.appsmith.server.helpers.MockPluginExecutor;
|
|||
import com.appsmith.server.helpers.PluginExecutorHelper;
|
||||
import com.appsmith.server.repositories.PluginRepository;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.minidev.json.JSONObject;
|
||||
import net.minidev.json.parser.JSONParser;
|
||||
import net.minidev.json.parser.ParseException;
|
||||
import org.junit.After;
|
||||
|
|
@ -34,6 +36,7 @@ import reactor.core.publisher.Mono;
|
|||
import reactor.test.StepVerifier;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
|
|
@ -161,6 +164,44 @@ public class PageServiceTest {
|
|||
.verifyComplete();
|
||||
}
|
||||
|
||||
@Test
|
||||
@WithUserDetails(value = "api_user")
|
||||
public void createValidPageWithLayout() throws ParseException {
|
||||
Policy managePagePolicy = Policy.builder().permission(MANAGE_PAGES.getValue())
|
||||
.users(Set.of("api_user"))
|
||||
.build();
|
||||
Policy readPagePolicy = Policy.builder().permission(READ_PAGES.getValue())
|
||||
.users(Set.of("api_user"))
|
||||
.build();
|
||||
|
||||
PageDTO testPage = new PageDTO();
|
||||
testPage.setName("PageServiceTest TestApp");
|
||||
setupTestApplication();
|
||||
testPage.setApplicationId(application.getId());
|
||||
|
||||
final Layout layout = new Layout();
|
||||
final JSONObject dsl = new JSONObject(Map.of("text", "{{ query1.data }}"));
|
||||
layout.setDsl(dsl);
|
||||
testPage.setLayouts(List.of(layout));
|
||||
|
||||
Mono<PageDTO> pageMono = applicationPageService.createPage(testPage);
|
||||
|
||||
StepVerifier
|
||||
.create(pageMono)
|
||||
.assertNext(page -> {
|
||||
assertThat(page).isNotNull();
|
||||
assertThat(page.getId()).isNotNull();
|
||||
assertThat("PageServiceTest TestApp".equals(page.getName()));
|
||||
|
||||
assertThat(page.getPolicies()).isNotEmpty();
|
||||
assertThat(page.getPolicies()).containsOnly(managePagePolicy, readPagePolicy);
|
||||
|
||||
assertThat(page.getLayouts()).isNotEmpty();
|
||||
assertThat(page.getLayouts().get(0).getDsl()).isEqualTo(dsl);
|
||||
})
|
||||
.verifyComplete();
|
||||
}
|
||||
|
||||
@Test
|
||||
@WithUserDetails(value = "api_user")
|
||||
public void validChangePageName() {
|
||||
|
|
@ -317,4 +358,3 @@ public class PageServiceTest {
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user