Monorepo: consolidate 7 repos into one
All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 1m5s
All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 1m5s
Combines shared, blog, market, cart, events, federation, and account into a single repository. Eliminates submodule sync, sibling model copying at build time, and per-app CI orchestration. Changes: - Remove per-app .git, .gitmodules, .gitea, submodule shared/ dirs - Remove stale sibling model copies from each app - Update all 6 Dockerfiles for monorepo build context (root = .) - Add build directives to docker-compose.yml - Add single .gitea/workflows/ci.yml with change detection - Add .dockerignore for monorepo build context - Create __init__.py for federation and account (cross-app imports)
This commit is contained in:
34
shared/infrastructure/cart_identity.py
Normal file
34
shared/infrastructure/cart_identity.py
Normal file
@@ -0,0 +1,34 @@
|
||||
"""
|
||||
Cart identity resolution — shared across all apps that need to know
|
||||
who the current cart owner is (user_id or anonymous session_id).
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
import secrets
|
||||
from typing import TypedDict, Optional
|
||||
|
||||
from quart import g, session as qsession
|
||||
|
||||
|
||||
class CartIdentity(TypedDict):
|
||||
user_id: Optional[int]
|
||||
session_id: Optional[str]
|
||||
|
||||
|
||||
def current_cart_identity() -> CartIdentity:
|
||||
"""
|
||||
Decide how to identify the cart:
|
||||
|
||||
- If user is logged in -> use user_id (and ignore session_id)
|
||||
- Else -> generate / reuse an anonymous session_id stored in Quart's session
|
||||
"""
|
||||
user = getattr(g, "user", None)
|
||||
if user is not None and getattr(user, "id", None) is not None:
|
||||
return {"user_id": user.id, "session_id": None}
|
||||
|
||||
sid = qsession.get("cart_sid")
|
||||
if not sid:
|
||||
sid = secrets.token_hex(16)
|
||||
qsession["cart_sid"] = sid
|
||||
|
||||
return {"user_id": None, "session_id": sid}
|
||||
Reference in New Issue
Block a user