feat(pages): HTML block type and hide-header option in the services
The counter accepts an HTML block (required, at most 200,000 characters, no script check because it only runs sealed) and stores a hide-header flag on the page. mobile-api passes the flag through on save and in the public page. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EFUzfiCVCgCVJZq4NDEqZs
This commit is contained in:
1 parent
dcad8cb650
commit
9a7b225827
15 files changed
+96
-7
No files matched your search
+8
-1
@@ -5,4 +5,11 @@ import java.util.List;
|
||||
|
||||
/** A landing page as the API sends and receives it; blocks are omitted (null) in list rows. */
|
||||
public record CmsPageDto(Long id, Long companyId, String slug, String title, String metaDescription, String status,
|
||||
List<CmsBlock> blocks, LocalDateTime updatedAt) {}
|
||||
boolean hideHeader, List<CmsBlock> blocks, LocalDateTime updatedAt) {
|
||||
|
||||
/** A page that shows its header (the default). */
|
||||
public CmsPageDto(Long id, Long companyId, String slug, String title, String metaDescription, String status,
|
||||
List<CmsBlock> blocks, LocalDateTime updatedAt) {
|
||||
this(id, companyId, slug, title, metaDescription, status, false, blocks, updatedAt);
|
||||
}
|
||||
}
|
||||
@@ -19,6 +19,7 @@ public class CmsPage {
|
||||
private String title;
|
||||
private String metaDescription;
|
||||
private String status = "DRAFT";
|
||||
private boolean hideHeader;
|
||||
/** JSON array of blocks, replaced as a whole on every save. */
|
||||
@Column(columnDefinition = "json")
|
||||
private String blocks;
|
||||
|
||||
+7
-1
@@ -12,7 +12,8 @@ import java.util.regex.Pattern;
|
||||
/**
|
||||
* Landing-page block rules, ported from babyboo's CmsBlockValidator (specs/cms-pages) without the product blocks.
|
||||
* Co-Lite changes: images are uploaded ids of the page's company, FORM points at an event of that company,
|
||||
* buttons may also use mailto: and tel:, and HTML holding scripts is refused (the public page sanitises as well).
|
||||
* buttons may also use mailto: and tel:, and rich-text HTML holding scripts is refused (the public page sanitises as well).
|
||||
* The HTML block (custom HTML) is exempt from the script check: it is served only inside a sandboxed frame.
|
||||
* Throws 422 on the first violation, with the reason "path|MessageCode".
|
||||
*/
|
||||
public final class CmsBlockValidator {
|
||||
@@ -44,6 +45,11 @@ public final class CmsBlockValidator {
|
||||
button(b, path);
|
||||
}
|
||||
case "RICH_TEXT" -> html(b.getHtml(), path + ".html");
|
||||
case "HTML" -> {
|
||||
// Custom HTML may hold scripts: it is only ever served in a sandboxed frame (add-custom-html-block).
|
||||
required(b.getHtml(), path + ".html");
|
||||
max(b.getHtml(), path + ".html", 200_000);
|
||||
}
|
||||
case "IMAGE_TEXT" -> {
|
||||
image(b, path, ownImage);
|
||||
max(b.getHeading(), path + ".heading", 120);
|
||||
|
||||
+2
-1
@@ -69,6 +69,7 @@ public class CmsPageService {
|
||||
row.setTitle(dto.title().trim());
|
||||
row.setMetaDescription(dto.metaDescription() == null || dto.metaDescription().isBlank() ? null : dto.metaDescription().trim());
|
||||
row.setStatus(dto.status());
|
||||
row.setHideHeader(dto.hideHeader());
|
||||
row.setBlocks(write(dto.blocks() == null ? List.of() : dto.blocks()));
|
||||
row.setUpdatedBy(user);
|
||||
row.setUpdatedAt(LocalDateTime.now());
|
||||
@@ -109,7 +110,7 @@ public class CmsPageService {
|
||||
|
||||
private CmsPageDto toDto(CmsPage p, boolean withBlocks) {
|
||||
return new CmsPageDto(p.getId(), p.getCompanyId(), p.getSlug(), p.getTitle(), p.getMetaDescription(), p.getStatus(),
|
||||
withBlocks ? read(p.getBlocks()) : null, p.getUpdatedAt());
|
||||
p.isHideHeader(), withBlocks ? read(p.getBlocks()) : null, p.getUpdatedAt());
|
||||
}
|
||||
|
||||
private String write(List<CmsBlock> blocks) {
|
||||
|
||||
Reference in new issue
Block a user