From 8c1a0240a3cae70c8e9953e2dd98787be19a56cc Mon Sep 17 00:00:00 2001 From: giles Date: Tue, 10 Feb 2026 14:26:10 +0000 Subject: [PATCH] feat: enforce calendar creation only on pages with calendar feature 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 --- bp/calendars/services/calendars.py | 13 ++++++++++++- shared_lib | 2 +- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/bp/calendars/services/calendars.py b/bp/calendars/services/calendars.py index 752dea9..1bcabcd 100644 --- a/bp/calendars/services/calendars.py +++ b/bp/calendars/services/calendars.py @@ -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) diff --git a/shared_lib b/shared_lib index fa9ffa9..56e3258 160000 --- a/shared_lib +++ b/shared_lib @@ -1 +1 @@ -Subproject commit fa9ffa98e500d8434fef5a8cea95b6818a875b59 +Subproject commit 56e32585b7c111ca0c417d44746840beae7af0e6