feat(tickets): TICKETS page block validation

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-04 15:42:08 +08:00
1 parent 687f054acf
commit 763a295234
4 files changed
+108 -3

No files matched your search

@@ -17,6 +17,7 @@ import java.util.regex.Pattern;
* 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 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.
* add-event-ticket-orders adds TICKETS: an event of the page's company that sells tickets (ticketEvent) when saved.
* add-landing-page-polish adds TOPBAR and section labels. add-landing-thanks-and-footer adds FOOTER and the thank-you text. add-page-sections adds FEATURES, STEPS, TRUST and CTA, a look on any block, and makes the HERO image optional.
* Throws 422 on the first violation, with the reason "path|MessageCode".
*/
@@ -29,13 +30,18 @@ public final class CmsBlockValidator {
static final Set<String> ICONS = Set.of("wifi", "phone", "tv", "monitor", "lock", "shield-check", "cloud", "wrench", "headset", "users", "calendar", "star");
private static final Set<String> CARD_TYPES = Set.of("FEATURES", "STEPS", "TRUST", "HERO", "FOOTER");
/** add-landing-page-polish: blocks that may carry a short label above their heading. */
private static final Set<String> EYEBROW_TYPES = Set.of("FEATURES", "STEPS", "IMAGE_TEXT", "FAQ", "CTA");
private static final Set<String> EYEBROW_TYPES = Set.of("FEATURES", "STEPS", "IMAGE_TEXT", "FAQ", "CTA", "TICKETS");
private static final Pattern SCRIPT = Pattern.compile("(?i)<\\s*script|\\son[a-z]+\\s*=|javascript\\s*:");
private CmsBlockValidator() {
}
/** Without ticket-selling events: no TICKETS block passes. */
public static void validate(List<CmsBlock> blocks, LongPredicate ownImage, LongPredicate ownEvent) {
validate(blocks, ownImage, ownEvent, uuid -> false);
}
public static void validate(List<CmsBlock> blocks, LongPredicate ownImage, LongPredicate ownEvent, LongPredicate ticketEvent) {
if (blocks == null || blocks.isEmpty()) {
return;
}
@@ -176,6 +182,25 @@ public final class CmsBlockValidator {
unused(path, "look", b.getLook());
button(b, path);
}
case "TICKETS" -> {
if (b.getEventUuid() == null || !ownEvent.test(b.getEventUuid())) {
throw refuse(path + ".eventUuid", "PagesBadEvent");
}
if (!ticketEvent.test(b.getEventUuid())) {
throw refuse(path + ".eventUuid", "PagesTicketsClosed");
}
max(b.getHeading(), path + ".heading", 120);
max(b.getText(), path + ".text", 1000);
unused(path, "html", b.getHtml());
unused(path, "imageId", b.getImageId());
unused(path, "imagePosition", b.getImagePosition());
unused(path, "buttonLabel", b.getButtonLabel());
unused(path, "buttonUrl", b.getButtonUrl());
unused(path, "items", b.getItems());
unused(path, "fullWidth", b.getFullWidth());
unused(path, "formHeading", b.getFormHeading());
unused(path, "formText", b.getFormText());
}
default -> throw refuse(path + ".type", "PagesUnknownType");
}
}
@@ -19,6 +19,7 @@ import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Service;
import org.springframework.web.server.ResponseStatusException;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Locale;
@@ -91,7 +92,8 @@ public class CmsPageService {
CmsBlockValidator.max(c.metaDescription(), "metaDescription", 160);
CmsBlockValidator.validate(c.blocks(),
id -> images.findCompanyIdById(id).map(co -> co == companyId).orElse(false),
uuid -> events.findByUuid(uuid).map(e -> e.getCompanyId() != null && e.getCompanyId() == companyId).orElse(false));
uuid -> events.findByUuid(uuid).map(e -> e.getCompanyId() != null && e.getCompanyId() == companyId).orElse(false),
uuid -> events.findByUuid(uuid).map(e -> TicketTypeService.ticketsOpen(e, LocalDate.now(TicketTypeService.MALAYSIA))).orElse(false));
if (pages.existsByCompanyIdAndSlugAndIdNot(companyId, slug, row.getId() == null ? -1L : row.getId())) {
throw slugTaken();
}