From 9f8e7c8532133a34e16c9b252ed9c81bc899b394 Mon Sep 17 00:00:00 2001 From: Calum Mackervoy <c.mackervoy@gmail.com> Date: Tue, 7 Sep 2021 16:00:19 +0200 Subject: [PATCH] update: all notifications are sent via ActivityQueue means I no longer have to subscribe with a user's inbox for notifications to work --- djangoldp_notification/models.py | 15 +-------------- .../tests/test_subscriptions.py | 12 +++++++----- 2 files changed, 8 insertions(+), 19 deletions(-) diff --git a/djangoldp_notification/models.py b/djangoldp_notification/models.py index 3126394..b110901 100644 --- a/djangoldp_notification/models.py +++ b/djangoldp_notification/models.py @@ -232,20 +232,7 @@ def send_request(target, object_iri, instance, created, serialize_object=False): "type": request_type } - # local inbox - if target.startswith(settings.SITE_URL): - user = Model.resolve_parent(target.replace(settings.SITE_URL, '')) - - # render the filters now, the resource is local - from djangoldp_notification.views import filter_object_is_permitted - - if not filter_object_is_permitted(user, json): - return - - Notification.objects.create(user=user, object=object_iri, type=request_type, author=author) - # external inbox - else: - ActivityQueueService.send_activity(target, json) + ActivityQueueService.send_activity(target, json) @receiver(post_save, sender=Notification) diff --git a/djangoldp_notification/tests/test_subscriptions.py b/djangoldp_notification/tests/test_subscriptions.py index eb9d658..a614a61 100644 --- a/djangoldp_notification/tests/test_subscriptions.py +++ b/djangoldp_notification/tests/test_subscriptions.py @@ -5,6 +5,7 @@ from django.conf import settings from django.test import override_settings from rest_framework.test import APITestCase, APIClient +from djangoldp.models import Activity from djangoldp_account.models import LDPUser from djangoldp_notification.models import Notification, Subscription @@ -24,15 +25,16 @@ class SubscriptionTestCase(APITestCase): self.user = self._get_random_user() self._auth_as_user(self.user) - @override_settings(SEND_BACKLINKS=True, DISABLE_OUTBOX=True) + # I can listen to changes on a container an receive a notification to a local inbox + @override_settings(SEND_BACKLINKS=True, DISABLE_OUTBOX='DEBUG') def test_can_subscribe_to_container(self): self.setUpLoggedInUser() users_container = "{}/users/".format(settings.SITE_URL) Subscription.objects.create(object=users_container, inbox=self.user.urlid + "inbox/") - self.assertEqual(self.user.inbox.count(), 0) + self.assertEqual(Activity.objects.count(), 0) new_user = self._get_random_user() - self.assertEqual(self.user.inbox.count(), 2) - notification = self.user.inbox.all()[0] - self.assertEqual(notification.object, new_user.urlid) + self.assertEqual(Activity.objects.count(), 2) + notification = Activity.objects.all()[0].to_activitystream() + self.assertEqual(notification['object'], new_user.urlid) -- GitLab