From d0ce4dd3d3c14e6e6109a48c9fbe6196d06e167c Mon Sep 17 00:00:00 2001 From: Untone Date: Sat, 16 Dec 2023 19:59:43 +0300 Subject: [PATCH] webhook-name-fix --- resolvers/author.py | 4 ++-- resolvers/webhook.py | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/resolvers/author.py b/resolvers/author.py index 0de045c2..a35e865a 100644 --- a/resolvers/author.py +++ b/resolvers/author.py @@ -279,9 +279,9 @@ async def rate_author(_, info, rated_slug, value): return {} -async def create_author(user_id: str, slug: str): +async def create_author(user_id: str, slug: str, name: str = ""): with local_session() as session: - new_author = Author(user=user_id, slug=slug) + new_author = Author(user=user_id, slug=slug, name=name) session.add(new_author) session.commit() print(f"[resolvers.author] created by webhook {new_author.dict()}") diff --git a/resolvers/webhook.py b/resolvers/webhook.py index fe380b89..d0d111d2 100644 --- a/resolvers/webhook.py +++ b/resolvers/webhook.py @@ -19,13 +19,14 @@ class WebhookEndpoint(HTTPEndpoint): if auth: if auth == os.environ.get("WEBHOOK_SECRET"): user_id: str = data["user"]["id"] + name: str = data["user"]["given_name"] slug: str = data["user"]["email"].split("@")[0] slug: str = re.sub("[^0-9a-z]+", "-", slug.lower()) with local_session() as session: author = session.query(Author).filter(Author.slug == slug).first() if author: slug = slug + "-" + user_id.split("-").pop() - await create_author(user_id, slug) + await create_author(user_id, slug, name) return JSONResponse({"status": "success"}) except Exception as e: