Skip to content
Snippets Groups Projects
Verified Commit 5124e23d authored by Andreas Ellewsen's avatar Andreas Ellewsen
Browse files

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
parent ad4bf7cd
No related branches found
No related tags found
1 merge request!93Expand published notifications with data field
Pipeline #96040 passed
...@@ -2,6 +2,7 @@ import json ...@@ -2,6 +2,7 @@ import json
import logging import logging
import signal import signal
import sys import sys
from typing import Union
import daemon import daemon
import lockfile import lockfile
...@@ -60,14 +61,17 @@ def create_cloud_event_payload(n: Notification) -> str: ...@@ -60,14 +61,17 @@ def create_cloud_event_payload(n: Notification) -> str:
""" """
object_type = camel_to_snake(n.object_type) object_type = camel_to_snake(n.object_type)
return json.dumps( content: dict[str, Union[str, dict[str, str]]] = {
{ "id": str(n.id),
"id": str(n.id), "source": f"urn:greg:{settings.INSTANCE_NAME}:{object_type}:{n.identifier}",
"source": f"urn:greg:{settings.INSTANCE_NAME}:{object_type}:{n.identifier}", "specversion": "1.0",
"specversion": "1.0", "type": generate_event_type(n),
"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): def handle_one_notification(notification: Notification, pcm: PCM, exchange: str):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment