feat: enforce calendar creation only on pages with calendar feature
All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 48s
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:
@@ -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)
|
||||
|
||||
Submodule shared_lib updated: fa9ffa98e5...56e32585b7
Reference in New Issue
Block a user