From 5124e23de7b697f8ee6a3175204f667928888b05 Mon Sep 17 00:00:00 2001 From: Andreas Ellewsen <ae@uio.no> Date: Thu, 7 Oct 2021 13:52:21 +0200 Subject: [PATCH] Expand published notifications with data field If the notification to be published is regarding a Role, Identity or Consent object, we now add the 'data' field with a 'person_id' key where the value is the id of the Person connected to the Role, Identity or Consent. Resolve: GREG-64 --- .../commands/start_notification_publisher.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/greg/management/commands/start_notification_publisher.py b/greg/management/commands/start_notification_publisher.py index c7257c94..2f8f1066 100644 --- a/greg/management/commands/start_notification_publisher.py +++ b/greg/management/commands/start_notification_publisher.py @@ -2,6 +2,7 @@ import json import logging import signal import sys +from typing import Union import daemon import lockfile @@ -60,14 +61,17 @@ def create_cloud_event_payload(n: Notification) -> str: """ object_type = camel_to_snake(n.object_type) - return json.dumps( - { - "id": str(n.id), - "source": f"urn:greg:{settings.INSTANCE_NAME}:{object_type}:{n.identifier}", - "specversion": "1.0", - "type": generate_event_type(n), + content: dict[str, Union[str, dict[str, str]]] = { + "id": str(n.id), + "source": f"urn:greg:{settings.INSTANCE_NAME}:{object_type}:{n.identifier}", + "specversion": "1.0", + "type": generate_event_type(n), + } + if n.object_type in ("Role", "Consent", "Identity"): + content["data"] = { + "person_id": n.meta.get("person_id"), } - ) + return json.dumps(content) def handle_one_notification(notification: Notification, pcm: PCM, exchange: str): -- GitLab