From 0a88e858a871726b4bfb7dfc49a9feb148caf228 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Ja=C5=A1ek?= Date: Mon, 31 Jul 2023 14:17:50 +0200 Subject: [PATCH] change request to cem when user is created (#119) use email instead of id CPNHUB-247 --- server/cp/cem.py | 5 +++-- server/cp/signals.py | 2 +- server/tests/test_signals.py | 4 ++-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/server/cp/cem.py b/server/cp/cem.py index d7d90e9..b0e63cf 100644 --- a/server/cp/cem.py +++ b/server/cp/cem.py @@ -1,6 +1,7 @@ import logging import requests +from typing import Literal from flask import current_app as app @@ -8,7 +9,7 @@ session = requests.Session() -def send_notification(_type, user): +def send_notification(_type, user, id_key: Literal["_id", "email"] = "_id"): url = app.config.get("CEM_URL", "") apikey = app.config.get("CEM_APIKEY", "") if not url or not apikey: @@ -16,7 +17,7 @@ def send_notification(_type, user): headers = {"x-api-key": apikey} payload = { "type": _type, - "object_id": str(user["_id"]), + "object_id": str(user[id_key]), "platform": app.config.get("CEM_PLATFORM"), } if user.get("company"): diff --git a/server/cp/signals.py b/server/cp/signals.py index e81d18a..eab11a3 100644 --- a/server/cp/signals.py +++ b/server/cp/signals.py @@ -33,7 +33,7 @@ def copy_correction_to_body_html(item): def on_user_created(sender, user, **kwargs): - send_notification("new user", user) + send_notification("new", user, id_key="email") def on_user_updated(sender, user, updates=None, **kwargs): diff --git a/server/tests/test_signals.py b/server/tests/test_signals.py index 51821a4..050aed4 100644 --- a/server/tests/test_signals.py +++ b/server/tests/test_signals.py @@ -58,8 +58,8 @@ def test_cem_notification_on_user_changes(app): ), matchers.json_params_matcher( { - "object_id": str(user["_id"]), - "type": "new user", + "object_id": str(user["email"]), + "type": "new", "platform": "Test", } ),