diff --git a/djangoldp_notification/models.py b/djangoldp_notification/models.py index b577be711d3725fa6211a0909c284111fdbcb711..3126394066fc1e62f347f321b4d276922e5e5a9a 100644 --- a/djangoldp_notification/models.py +++ b/djangoldp_notification/models.py @@ -225,18 +225,26 @@ def send_request(target, object_iri, instance, created, serialize_object=False): else: request_type = "deletion" + json = { + "@context": settings.LDP_RDF_CONTEXT, + "object": object_iri if not serialize_object else serialize_instance(), + "author": author, + "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: - json = { - "@context": settings.LDP_RDF_CONTEXT, - "object": object_iri if not serialize_object else serialize_instance(), - "author": author, - "type": request_type - } ActivityQueueService.send_activity(target, json) diff --git a/djangoldp_notification/views.py b/djangoldp_notification/views.py index b13d89b79fa4c5c701b0cfb5e3ef914c9693aaf5..306db3ee42ddb1261a70ee6901bbb4238caa8eb2 100644 --- a/djangoldp_notification/views.py +++ b/djangoldp_notification/views.py @@ -18,12 +18,7 @@ class LDPNotificationsPagination(LDPPagination): default_limit = 80 -class LDPNotificationsViewSet(LDPViewSet): - '''overridden LDPViewSet to force pagination''' - pagination_class = LDPNotificationsPagination - depth = 0 - - def _filter_object_is_permitted(self, recipient, data): +def filter_object_is_permitted(recipient, data): ''' applies filter on passed object data returns True if the object is permitted, False if not @@ -51,6 +46,12 @@ class LDPNotificationsViewSet(LDPViewSet): return object_model.permit_notification(recipient, data) + +class LDPNotificationsViewSet(LDPViewSet): + '''overridden LDPViewSet to force pagination''' + pagination_class = LDPNotificationsPagination + depth = 0 + def _resolve_user_recipient(self, request): # TODO: extend to work on views other than the nested inbox # https://git.startinblox.com/djangoldp-packages/djangoldp-notification/issues/41 @@ -71,7 +72,7 @@ class LDPNotificationsViewSet(LDPViewSet): data = request.data if 'object' in data: - if not self._filter_object_is_permitted(recipient, data): + if not filter_object_is_permitted(recipient, data): # if the notification should not be sent, accept the request but do nothing return Response(status=status.HTTP_204_NO_CONTENT)