feat: platform-aware storefront routing and billing improvements
Overhaul storefront URL routing to be platform-aware:
- Dev: /platforms/{code}/storefront/{store_code}/
- Prod: subdomain.platform.lu/ (internally rewritten to /storefront/)
- Add subdomain detection in PlatformContextMiddleware
- Add /storefront/ path rewrite for prod mode (subdomain/custom domain)
- Remove all silent platform fallbacks (platform_id=1)
- Add require_platform dependency for clean endpoint validation
- Update route registration, templates, module definitions, base_url calc
- Update StoreContextMiddleware for /storefront/ path detection
- Remove /stores/ from FrontendDetector STOREFRONT_PATH_PREFIXES
Billing service improvements:
- Add store_platform_sync_service to keep store_platforms in sync
- Make tier lookups platform-aware across billing services
- Add tiers for all platforms in seed data
- Add demo subscriptions to seed
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -39,7 +39,9 @@ def _get_platform_context(request: Any, db: Any, platform: Any) -> dict[str, Any
|
||||
"""
|
||||
from app.modules.cms.services import content_page_service
|
||||
|
||||
platform_id = platform.id if platform else 1
|
||||
if not platform:
|
||||
return {"header_pages": [], "footer_pages": [], "legal_pages": []}
|
||||
platform_id = platform.id
|
||||
|
||||
header_pages = []
|
||||
footer_pages = []
|
||||
@@ -73,7 +75,9 @@ def _get_storefront_context(request: Any, db: Any, platform: Any) -> dict[str, A
|
||||
from app.modules.cms.services import content_page_service
|
||||
|
||||
store = getattr(request.state, "store", None)
|
||||
platform_id = platform.id if platform else 1
|
||||
if not platform:
|
||||
return {"header_pages": [], "footer_pages": [], "legal_pages": []}
|
||||
platform_id = platform.id
|
||||
|
||||
header_pages = []
|
||||
footer_pages = []
|
||||
|
||||
@@ -11,6 +11,7 @@ import logging
|
||||
from fastapi import APIRouter, Depends, Request
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from app.api.deps import require_platform
|
||||
from app.core.database import get_db
|
||||
from app.modules.cms.schemas import (
|
||||
ContentPageListItem,
|
||||
@@ -29,7 +30,11 @@ logger = logging.getLogger(__name__)
|
||||
|
||||
# public - storefront content pages are publicly accessible
|
||||
@router.get("/navigation", response_model=list[ContentPageListItem])
|
||||
def get_navigation_pages(request: Request, db: Session = Depends(get_db)):
|
||||
def get_navigation_pages(
|
||||
request: Request,
|
||||
platform=Depends(require_platform),
|
||||
db: Session = Depends(get_db),
|
||||
):
|
||||
"""
|
||||
Get list of content pages for navigation (footer/header).
|
||||
|
||||
@@ -37,9 +42,8 @@ def get_navigation_pages(request: Request, db: Session = Depends(get_db)):
|
||||
Returns store overrides + platform defaults.
|
||||
"""
|
||||
store = getattr(request.state, "store", None)
|
||||
platform = getattr(request.state, "platform", None)
|
||||
store_id = store.id if store else None
|
||||
platform_id = platform.id if platform else 1
|
||||
platform_id = platform.id
|
||||
|
||||
# Get all published pages for this store
|
||||
pages = content_page_service.list_pages_for_store(
|
||||
@@ -59,7 +63,12 @@ def get_navigation_pages(request: Request, db: Session = Depends(get_db)):
|
||||
|
||||
|
||||
@router.get("/{slug}", response_model=PublicContentPageResponse)
|
||||
def get_content_page(slug: str, request: Request, db: Session = Depends(get_db)):
|
||||
def get_content_page(
|
||||
slug: str,
|
||||
request: Request,
|
||||
platform=Depends(require_platform),
|
||||
db: Session = Depends(get_db),
|
||||
):
|
||||
"""
|
||||
Get a specific content page by slug.
|
||||
|
||||
@@ -67,9 +76,8 @@ def get_content_page(slug: str, request: Request, db: Session = Depends(get_db))
|
||||
Returns store override if exists, otherwise platform default.
|
||||
"""
|
||||
store = getattr(request.state, "store", None)
|
||||
platform = getattr(request.state, "platform", None)
|
||||
store_id = store.id if store else None
|
||||
platform_id = platform.id if platform else 1
|
||||
platform_id = platform.id
|
||||
|
||||
page = content_page_service.get_page_for_store_or_raise(
|
||||
db,
|
||||
|
||||
@@ -91,8 +91,9 @@ async def homepage(
|
||||
if store:
|
||||
logger.debug(f"[HOMEPAGE] Store detected: {store.subdomain}")
|
||||
|
||||
# Get platform_id (use platform from context or default to 1 for OMS)
|
||||
platform_id = platform.id if platform else 1
|
||||
if not platform:
|
||||
raise HTTPException(status_code=400, detail="Platform context required")
|
||||
platform_id = platform.id
|
||||
|
||||
# Try to find store landing page (slug='landing' or 'home')
|
||||
landing_page = content_page_service.get_page_for_store(
|
||||
@@ -133,21 +134,19 @@ async def homepage(
|
||||
else "unknown"
|
||||
)
|
||||
|
||||
if access_method == "path":
|
||||
full_prefix = (
|
||||
store_context.get("full_prefix", "/store/")
|
||||
if store_context
|
||||
else "/store/"
|
||||
)
|
||||
if access_method == "path" and platform:
|
||||
return RedirectResponse(
|
||||
url=f"{full_prefix}{store.subdomain}/storefront/", status_code=302
|
||||
url=f"/platforms/{platform.code}/storefront/{store.store_code}/",
|
||||
status_code=302,
|
||||
)
|
||||
# Domain/subdomain - redirect to /storefront/
|
||||
return RedirectResponse(url="/storefront/", status_code=302)
|
||||
# Domain/subdomain - root is storefront
|
||||
return RedirectResponse(url="/", status_code=302)
|
||||
|
||||
# Scenario 2: Platform marketing site (no store)
|
||||
# Load platform homepage from CMS (slug='home')
|
||||
platform_id = platform.id if platform else 1
|
||||
if not platform:
|
||||
raise HTTPException(status_code=400, detail="Platform context required")
|
||||
platform_id = platform.id
|
||||
|
||||
cms_homepage = content_page_service.get_platform_page(
|
||||
db, platform_id=platform_id, slug="home", include_unpublished=False
|
||||
@@ -227,9 +226,10 @@ async def content_page(
|
||||
This is a catch-all route for dynamic content pages managed via the admin CMS.
|
||||
Platform pages have store_id=None and is_platform_page=True.
|
||||
"""
|
||||
# Get platform from middleware (default to OMS platform_id=1)
|
||||
platform = getattr(request.state, "platform", None)
|
||||
platform_id = platform.id if platform else 1
|
||||
if not platform:
|
||||
raise HTTPException(status_code=400, detail="Platform context required")
|
||||
platform_id = platform.id
|
||||
|
||||
# Load platform marketing page from database
|
||||
page = content_page_service.get_platform_page(
|
||||
|
||||
@@ -184,7 +184,9 @@ async def store_content_page(
|
||||
store = getattr(request.state, "store", None)
|
||||
platform = getattr(request.state, "platform", None)
|
||||
store_id = store.id if store else None
|
||||
platform_id = platform.id if platform else 1
|
||||
if not platform:
|
||||
raise HTTPException(status_code=400, detail="Platform context required")
|
||||
platform_id = platform.id
|
||||
|
||||
# Load content page from database (store override → platform default)
|
||||
page = content_page_service.get_page_for_store(
|
||||
|
||||
@@ -66,7 +66,9 @@ async def generic_content_page(
|
||||
store = getattr(request.state, "store", None)
|
||||
platform = getattr(request.state, "platform", None)
|
||||
store_id = store.id if store else None
|
||||
platform_id = platform.id if platform else 1 # Default to OMS
|
||||
if not platform:
|
||||
raise HTTPException(status_code=400, detail="Platform context required")
|
||||
platform_id = platform.id
|
||||
|
||||
# Load content page from database (store override -> store default)
|
||||
page = content_page_service.get_page_for_store(
|
||||
|
||||
Reference in New Issue
Block a user