All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 6m2s
Move Ghost membership sync from blog to account service so blog no longer queries account tables (users, ghost_labels, etc.). Account runs membership sync at startup and exposes HTTP action/data endpoints for webhook-triggered syncs and user lookups. Key changes: - account/services/ghost_membership.py: all membership sync functions - account/bp/actions + data: ghost-sync-member, user-by-email, newsletters - blog ghost_sync.py: stripped to content-only (posts, authors, tags) - blog webhook member: delegates to account via call_action() - try_publish: opens federation session when DBs differ - oauth.py callback: uses get_account_session() for OAuthCode - page_configs moved from db_events to db_blog in split script Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
65 lines
2.0 KiB
Python
65 lines
2.0 KiB
Python
"""Account app data endpoints.
|
|
|
|
Exposes read-only JSON queries at ``/internal/data/<query_name>`` for
|
|
cross-app callers via the internal data client.
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
from quart import Blueprint, g, jsonify, request
|
|
|
|
from shared.infrastructure.data_client import DATA_HEADER
|
|
from sqlalchemy import select
|
|
from shared.models import User
|
|
|
|
|
|
def register() -> Blueprint:
|
|
bp = Blueprint("data", __name__, url_prefix="/internal/data")
|
|
|
|
@bp.before_request
|
|
async def _require_data_header():
|
|
if not request.headers.get(DATA_HEADER):
|
|
return jsonify({"error": "forbidden"}), 403
|
|
|
|
_handlers: dict[str, object] = {}
|
|
|
|
@bp.get("/<query_name>")
|
|
async def handle_query(query_name: str):
|
|
handler = _handlers.get(query_name)
|
|
if handler is None:
|
|
return jsonify({"error": "unknown query"}), 404
|
|
result = await handler()
|
|
return jsonify(result)
|
|
|
|
# --- user-by-email ---
|
|
async def _user_by_email():
|
|
"""Return user_id for a given email address."""
|
|
email = request.args.get("email", "").strip().lower()
|
|
if not email:
|
|
return None
|
|
result = await g.s.execute(
|
|
select(User.id).where(User.email.ilike(email))
|
|
)
|
|
row = result.first()
|
|
if not row:
|
|
return None
|
|
return {"user_id": row[0]}
|
|
|
|
_handlers["user-by-email"] = _user_by_email
|
|
|
|
# --- newsletters ---
|
|
async def _newsletters():
|
|
"""Return all Ghost newsletters (for blog post editor)."""
|
|
from shared.models.ghost_membership_entities import GhostNewsletter
|
|
result = await g.s.execute(
|
|
select(GhostNewsletter.id, GhostNewsletter.ghost_id, GhostNewsletter.name, GhostNewsletter.slug)
|
|
.order_by(GhostNewsletter.name)
|
|
)
|
|
return [
|
|
{"id": row[0], "ghost_id": row[1], "name": row[2], "slug": row[3]}
|
|
for row in result.all()
|
|
]
|
|
|
|
_handlers["newsletters"] = _newsletters
|
|
|
|
return bp
|