From aaf4c0b876e2b49f14e756c72f78a03100c6e56f Mon Sep 17 00:00:00 2001 From: Untone Date: Tue, 28 Nov 2023 23:13:42 +0300 Subject: [PATCH] trig-ci --- main.py | 12 ++++++++---- resolvers/author.py | 1 - 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/main.py b/main.py index 3b481169..063c6feb 100644 --- a/main.py +++ b/main.py @@ -44,10 +44,14 @@ class WebhookEndpoint(HTTPEndpoint): try: data = await request.json() if data: - # Extract user_id and slug - user_id = data["user"]["id"] - slug = data["user"]["preferred_username"] or data["user"]["email"].replace(".", "-").split("@").pop() - await create_author(user_id, slug) + auth = request.headers.get("Authorization") + if auth: + # TODO: check Authorization header + # Extract user_id and slug + user_id = data["user"]["id"] + email_slug = data["user"]["email"].replace(".", "-").split("@").pop() + slug = data["user"]["preferred_username"] or email_slug + await create_author(user_id, slug) return JSONResponse({"status": "success"}) except Exception as e: return JSONResponse({"status": "error", "message": str(e)}, status_code=500) diff --git a/resolvers/author.py b/resolvers/author.py index 6426fa8f..efe71048 100644 --- a/resolvers/author.py +++ b/resolvers/author.py @@ -243,7 +243,6 @@ async def rate_author(_, info, rated_slug, value): async def create_author(user_id: str, slug: str): with local_session() as session: - # TODO: check Authorization header new_author = Author(user=user_id, slug=slug) session.add(new_author) session.commit()