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)
36 lines
985 B
Python
36 lines
985 B
Python
from __future__ import annotations
|
|
|
|
from quart import session as qsession, g
|
|
from sqlalchemy import select
|
|
from sqlalchemy.orm import selectinload
|
|
|
|
from shared.models.user import User
|
|
from shared.models.ghost_membership_entities import UserNewsletter
|
|
|
|
|
|
async def load_user_by_id(session, user_id: int):
|
|
"""Load a user by ID with labels and newsletters eagerly loaded."""
|
|
stmt = (
|
|
select(User)
|
|
.options(
|
|
selectinload(User.labels),
|
|
selectinload(User.user_newsletters).selectinload(
|
|
UserNewsletter.newsletter
|
|
),
|
|
)
|
|
.where(User.id == user_id)
|
|
)
|
|
result = await session.execute(stmt)
|
|
return result.scalar_one_or_none()
|
|
|
|
|
|
async def load_current_user():
|
|
uid = qsession.get("uid")
|
|
if not uid:
|
|
g.user = None
|
|
g.rights = {"admin": False}
|
|
return
|
|
|
|
g.user = await load_user_by_id(g.s, uid)
|
|
g.rights = {l.name: True for l in g.user.labels} if g.user else {}
|