Skip to content

Commit

Permalink
change request to cem when user is created (#119)
Browse files Browse the repository at this point in the history
use email instead of id

CPNHUB-247
  • Loading branch information
petrjasek authored Jul 31, 2023
1 parent 25603cb commit 0a88e85
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
5 changes: 3 additions & 2 deletions server/cp/cem.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
import logging
import requests

from typing import Literal
from flask import current_app as app


logger = logging.getLogger(__name__)
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:
return
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"):
Expand Down
2 changes: 1 addition & 1 deletion server/cp/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
4 changes: 2 additions & 2 deletions server/tests/test_signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
}
),
Expand Down

0 comments on commit 0a88e85

Please sign in to comment.