feat: enforce calendar creation only on pages with calendar feature
All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 48s

Calendar creation now requires the parent post to be a page (is_page=True)
with the calendar feature enabled in its PageConfig. Update shared_lib
submodule with PageConfig model.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
giles
2026-02-10 14:26:10 +00:00
parent 4a707577d3
commit 8c1a0240a3
2 changed files with 13 additions and 2 deletions

View File

@@ -5,6 +5,7 @@ from sqlalchemy.ext.asyncio import AsyncSession
from models.calendars import Calendar
from models.ghost_content import Post # for FK existence checks
from models.page_config import PageConfig
import unicodedata
import re
@@ -79,10 +80,20 @@ async def create_calendar(sess: AsyncSession, post_id: int, name: str) -> Calend
slug=slugify(name)
# Ensure post exists (avoid silent FK errors in some DBs)
post = (await sess.execute(select(Post.id).where(Post.id == post_id))).scalar_one_or_none()
post = (await sess.execute(select(Post).where(Post.id == post_id))).scalar_one_or_none()
if not post:
raise CalendarError(f"Post {post_id} does not exist.")
# Enforce: calendars can only be created on pages with the calendar feature
if not post.is_page:
raise CalendarError("Calendars can only be created on pages, not posts.")
pc = (await sess.execute(
select(PageConfig).where(PageConfig.post_id == post_id)
)).scalar_one_or_none()
if pc is None or not (pc.features or {}).get("calendar"):
raise CalendarError("Calendar feature is not enabled for this page. Enable it in page settings first.")
# Look for existing (including soft-deleted)
q = await sess.execute(
select(Calendar).where(Calendar.post_id == post_id, Calendar.name == name)