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:
ngqileandClaude Opus 5.5 committed 2026-12-02 17:46:32 +08:00
1 parent dcad8cb650
commit 9a7b225827
15 files changed
+96 -7

No files matched your search

+3
View File
@@ -503,3 +503,6 @@ ALTER TABLE `company`
USE `service-system`;
INSERT INTO `module` (`id`, `name`, `desc`, `area`, `type`, `parent`, `url`, `icon_name`) VALUES
(40250000, 'BO_PAGES', 'Pages', 'BO', 'M', 40000000, '/pages', 'PanelsTopLeft');
-- add-custom-html-block: the hide-header page option
USE `service-counter`;
ALTER TABLE `cms_page` ADD COLUMN `hide_header` tinyint(1) NOT NULL DEFAULT 0 COMMENT 'Hide the company header and the page title on the public page' AFTER `status`;
@@ -0,0 +1,5 @@
-- Co-Lite change add-custom-html-block: a page option that hides the company header and the page title.
-- Target: `service-counter`. Additive only. Run once, after add-landing-pages 01.
SET NAMES utf8mb4;
USE `service-counter`;
ALTER TABLE `cms_page` ADD COLUMN `hide_header` tinyint(1) NOT NULL DEFAULT 0 COMMENT 'Hide the company header and the page title on the public page' AFTER `status`;
@@ -0,0 +1,4 @@
-- Co-Lite change add-custom-html-block: rollback. Pages with HTML blocks must be edited or deleted first,
-- because the previous release refuses the HTML block type when such a page is saved.
USE `service-counter`;
ALTER TABLE `cms_page` DROP COLUMN `hide_header`;
@@ -4,12 +4,12 @@ Design: `design.md` and `docs/superpowers/specs/2026-12-02-custom-html-block-des
## 1. Data and services
- [ ] 1.1 SQL: `sql/01-hide-header.sql` (`cms_page.hide_header`), `sql/99-rollback.sql`; mirror 01 into `local/seed/`.
- [ ] 1.2 services-counter:
- [x] 1.1 SQL: `sql/01-hide-header.sql` (`cms_page.hide_header`), `sql/99-rollback.sql`; mirror 01 into `local/seed/`.
- [x] 1.2 services-counter:
- the `HTML` block type: required, at most 200,000 characters, no script check;
- `hideHeader` on the page model and DTO.
- Verify: `mvn -T 1C -B -pl solvway-services-counter -am verify`
- [ ] 1.3 mobile-api: `hideHeader` on `AdminPageRequest` and in the public page response.
- [x] 1.3 mobile-api: `hideHeader` on `AdminPageRequest` and in the public page response.
- Verify: `mvn -T 1C -B -pl solvway-mobile-api -am verify`
## 2. Portal
@@ -5,4 +5,11 @@ import java.util.Map;
/** A landing page as the editor saves it. Blocks pass through to the counter, which validates them. companyId counts only on create. */
public record AdminPageRequest(Long companyId, String slug, String title, String metaDescription, String status,
List<Map<String, Object>> blocks) {}
boolean hideHeader, List<Map<String, Object>> blocks) {
/** A page that shows its header (the default). */
public AdminPageRequest(Long companyId, String slug, String title, String metaDescription, String status,
List<Map<String, Object>> blocks) {
this(companyId, slug, title, metaDescription, status, false, blocks);
}
}
@@ -93,6 +93,7 @@ public class AdminPageService {
page.put("title", r.title());
page.put("metaDescription", r.metaDescription());
page.put("status", r.status());
page.put("hideHeader", r.hideHeader());
page.put("blocks", r.blocks() == null ? List.of() : r.blocks());
Map<String, Object> body = new LinkedHashMap<>();
body.put("page", page);
@@ -59,6 +59,7 @@ public class PublicPageService {
page.put("slug", f.page().get("slug"));
page.put("title", f.page().get("title"));
page.put("metaDescription", f.page().get("metaDescription"));
page.put("hideHeader", Boolean.TRUE.equals(f.page().get("hideHeader")));
page.put("blocks", blocks);
return Map.of("company", f.company(), "page", page);
}
@@ -115,6 +115,17 @@ class AdminPageServiceTest {
assertThat((Map<String, Object>) sent.get("page")).containsEntry("companyId", 2L).containsEntry("slug", "hotel").containsEntry("id", null);
}
@Test
void theHideHeaderOptionIsSentToTheCounter() {
caller(2L, false);
service.create(new AdminPageRequest(null, "designed", "Designed", null, "DRAFT", true, List.of(Map.<String, Object>of("type", "HTML", "html", "<script>x()</script>"))));
ArgumentCaptor<Object> body = ArgumentCaptor.forClass(Object.class);
verify(rest).postForEntity(eq(SAVE), any(ParameterizedTypeReference.class), body.capture());
Map<String, Object> page = (Map<String, Object>) ((Map<String, Object>) body.getValue()).get("page");
assertThat(page).containsEntry("hideHeader", true);
assertThat((List<Map<String, Object>>) page.get("blocks")).first().isEqualTo(Map.of("type", "HTML", "html", "<script>x()</script>"));
}
@Test
void updateKeepsTheIdAndStoredCompany() {
caller(2L, false);
@@ -123,6 +123,16 @@ class PublicPageServiceTest {
assertThat(blocks.get(1)).doesNotContainKey("closed");
}
@Test
void thePageCarriesItsHideHeaderOptionDefaultingToOff() {
assertThat((Map<String, Object>) service.page("INS", "hotel-technology").get("page")).containsEntry("hideHeader", false);
Map<String, Object> designed = page();
designed.put("hideHeader", true);
when(rest.getForEntity(eq(PUBLISHED), any(ParameterizedTypeReference.class), eq(COMPANY), eq("hotel-technology")))
.thenReturn(ResponseEntity.ok(designed));
assertThat((Map<String, Object>) service.page("INS", "hotel-technology").get("page")).containsEntry("hideHeader", true);
}
@Test
void aFormWhoseEventEndedIsClosedButThePageStillShows() {
stubEvent(LocalDateTime.of(2027, 1, 15, 23, 59));
@@ -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;
@@ -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);
@@ -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) {
@@ -150,4 +150,20 @@ class CmsBlockValidatorTest {
refused(List.of(noImage), "blocks[0].imageId", "PagesBadImage");
refused(List.of(form(901)), "blocks[0].eventUuid", "PagesBadEvent");
}
private static CmsBlock custom(String html) {
CmsBlock b = new CmsBlock();
b.setType("HTML");
b.setHtml(html);
return b;
}
@Test
void anHtmlBlockMayHoldScriptsButHasALimit() {
assertThatCode(() -> validate(List.of(custom("<style>h1{color:gold}</style><script>document.title = 'x'</script><h1 onclick=\"go()\">Hi</h1>"))))
.doesNotThrowAnyException();
assertThatCode(() -> validate(List.of(custom("x".repeat(200_000))))).doesNotThrowAnyException();
refused(List.of(custom("x".repeat(200_001))), "blocks[0].html", "PagesTooLong");
refused(List.of(custom(" ")), "blocks[0].html", "PagesRequired");
}
}
@@ -130,6 +130,22 @@ class CmsPageServiceTest {
refused(page(null, INS, "launch", List.of(hero)), HttpStatus.UNPROCESSABLE_ENTITY, "blocks[0].imageId|PagesBadImage");
}
@Test
void theHideHeaderOptionAndAnHtmlBlockReadBack() {
CmsBlock custom = new CmsBlock();
custom.setType("HTML");
custom.setHtml("<section><script>x()</script></section>");
CmsPageDto dto = new CmsPageDto(null, INS, "designed", "Designed", null, "DRAFT", true, List.of(custom), null);
service.save(dto, "staff1");
ArgumentCaptor<CmsPage> row = ArgumentCaptor.forClass(CmsPage.class);
verify(pages).saveAndFlush(row.capture());
when(pages.findById(77L)).thenReturn(Optional.of(row.getValue()));
CmsPageDto read = service.findById(77L);
assertThat(read.hideHeader()).isTrue();
assertThat(read.blocks().get(0).getHtml()).isEqualTo("<section><script>x()</script></section>");
}
@Test
void blocksReadBackInTheirSavedOrder() {
CmsBlock faq = new CmsBlock();