Skip to content

Commit

Permalink
Merge pull request #118 from open-zaak/revert-101-Issue/Add-Notificat…
Browse files Browse the repository at this point in the history
…ion-uuid-header-to-outgoing-requests

Revert "Issue/add notification UUID header to outgoing requests"
  • Loading branch information
alextreme authored Dec 1, 2023
2 parents 00ebd10 + a6111d4 commit 06b90f8
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 59 deletions.
20 changes: 3 additions & 17 deletions src/nrc/api/serializers.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import logging
from typing import Optional
from uuid import UUID, uuid4

from django.conf import settings
from django.core.exceptions import ObjectDoesNotExist
Expand Down Expand Up @@ -176,12 +175,7 @@ def validate(self, attrs):
# ensure we're still camelCasing
return camelize(validated_attrs)

def _send_to_subs(
self,
msg: dict,
notificatie_uuid: UUID,
notificatie: Optional[Notificatie] = None,
):
def _send_to_subs(self, msg: dict, notificatie: Optional[Notificatie] = None):
# define subs
msg_filters = msg["kenmerken"]
subs = set()
Expand All @@ -196,11 +190,7 @@ def _send_to_subs(
if not notificatie and settings.LOG_NOTIFICATIONS_IN_DB:
# creation of the notification
kanaal = Kanaal.objects.get(naam=msg["kanaal"])
notificatie = Notificatie.objects.create(
uuid=notificatie_uuid, forwarded_msg=msg, kanaal=kanaal
)

msg["uuid"] = str(notificatie_uuid)
notificatie = Notificatie.objects.create(forwarded_msg=msg, kanaal=kanaal)

if notificatie:
task_kwargs.update(
Expand All @@ -218,13 +208,9 @@ def create(self, validated_data: dict) -> dict:
logger.info("Handling notification %r", validated_data)

notificatie = validated_data.pop("notificatie", None)
if notificatie:
notificatie_uuid = notificatie.uuid
else:
notificatie_uuid = uuid4()

# send to subs
self._send_to_subs(validated_data, notificatie_uuid, notificatie=notificatie)
self._send_to_subs(validated_data, notificatie=notificatie)
return validated_data

@classmethod
Expand Down
13 changes: 2 additions & 11 deletions src/nrc/api/tests/test_notificatie.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,10 @@ def test_notificatie_send_success(self, mock_task):

response = self.client.post(notificatie_url, msg)

saved_notificatie = Notificatie.objects.get()

self.assertEqual(response.status_code, status.HTTP_201_CREATED, response.data)
self.assertEqual(Notificatie.objects.count(), 1)
mock_task.assert_called_once_with(
abon.id,
{**msg, **{"uuid": str(saved_notificatie.uuid)}},
notificatie_id=saved_notificatie.id,
attempt=1,
abon.id, msg, notificatie_id=Notificatie.objects.get().id, attempt=1
)

def test_notificatie_send_inconsistent_kenmerken(self, mock_task):
Expand Down Expand Up @@ -142,13 +137,9 @@ def test_notificatie_send_empty_kenmerk_value(self, mock_task):
}

response = self.client.post(notificatie_url, msg)
saved_notificatie = Notificatie.objects.get()

self.assertEqual(response.status_code, status.HTTP_201_CREATED, response.data)
self.assertEqual(Notificatie.objects.count(), 1)
mock_task.assert_called_once_with(
abon.id,
{**msg, **{"uuid": str(saved_notificatie.uuid)}},
notificatie_id=saved_notificatie.id,
attempt=1,
abon.id, msg, notificatie_id=Notificatie.objects.get().id, attempt=1
)
1 change: 0 additions & 1 deletion src/nrc/datamodel/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ def resend_notifications(modeladmin, request, queryset):
@admin.register(Notificatie)
class NotificatieAdmin(admin.ModelAdmin):
list_display = (
"uuid",
"kanaal",
"action",
"resource",
Expand Down
23 changes: 0 additions & 23 deletions src/nrc/datamodel/migrations/0017_notificatie_uuid.py

This file was deleted.

5 changes: 0 additions & 5 deletions src/nrc/datamodel/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,6 @@ class Meta:


class Notificatie(models.Model):
uuid = models.UUIDField(
unique=True,
default=_uuid.uuid4,
help_text=_("Unique resource identifier (UUID4)"),
)
forwarded_msg = models.JSONField(encoder=DjangoJSONEncoder)
kanaal = models.ForeignKey(Kanaal, on_delete=models.CASCADE)

Expand Down
4 changes: 2 additions & 2 deletions src/nrc/tests/admin/test_notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def test_create_notification(self, mock_deliver_message):
# Notification should be sent
mock_deliver_message.assert_called_once_with(
self.abonnement.id,
{**self.forwarded_msg, **{"uuid": str(Notificatie.objects.get().uuid)}},
self.forwarded_msg,
notificatie_id=Notificatie.objects.get().id,
attempt=1,
)
Expand Down Expand Up @@ -92,7 +92,7 @@ def test_resend_notification(self, mock_deliver_message):
# Notification should be scheduled
mock_deliver_message.assert_called_once_with(
self.abonnement.id,
{**self.forwarded_msg, **{"uuid": str(Notificatie.objects.get().uuid)}},
self.forwarded_msg,
notificatie_id=notificatie.id,
attempt=2,
)
Expand Down

0 comments on commit 06b90f8

Please sign in to comment.