Skip to content
Snippets Groups Projects
Commit 26b23fd3 authored by Calum Mackervoy's avatar Calum Mackervoy
Browse files

feature: filters are applied to local inboxes

parent fd5b9f5f
No related branches found
No related tags found
1 merge request!47feature: serialization of notifications into objects and their filtering
Pipeline #11956 passed
...@@ -225,18 +225,26 @@ def send_request(target, object_iri, instance, created, serialize_object=False): ...@@ -225,18 +225,26 @@ def send_request(target, object_iri, instance, created, serialize_object=False):
else: else:
request_type = "deletion" 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 # local inbox
if target.startswith(settings.SITE_URL): if target.startswith(settings.SITE_URL):
user = Model.resolve_parent(target.replace(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) Notification.objects.create(user=user, object=object_iri, type=request_type, author=author)
# external inbox # external inbox
else: 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) ActivityQueueService.send_activity(target, json)
......
...@@ -18,12 +18,7 @@ class LDPNotificationsPagination(LDPPagination): ...@@ -18,12 +18,7 @@ class LDPNotificationsPagination(LDPPagination):
default_limit = 80 default_limit = 80
class LDPNotificationsViewSet(LDPViewSet): def filter_object_is_permitted(recipient, data):
'''overridden LDPViewSet to force pagination'''
pagination_class = LDPNotificationsPagination
depth = 0
def _filter_object_is_permitted(self, recipient, data):
''' '''
applies filter on passed object data applies filter on passed object data
returns True if the object is permitted, False if not returns True if the object is permitted, False if not
...@@ -51,6 +46,12 @@ class LDPNotificationsViewSet(LDPViewSet): ...@@ -51,6 +46,12 @@ class LDPNotificationsViewSet(LDPViewSet):
return object_model.permit_notification(recipient, data) 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): def _resolve_user_recipient(self, request):
# TODO: extend to work on views other than the nested inbox # TODO: extend to work on views other than the nested inbox
# https://git.startinblox.com/djangoldp-packages/djangoldp-notification/issues/41 # https://git.startinblox.com/djangoldp-packages/djangoldp-notification/issues/41
...@@ -71,7 +72,7 @@ class LDPNotificationsViewSet(LDPViewSet): ...@@ -71,7 +72,7 @@ class LDPNotificationsViewSet(LDPViewSet):
data = request.data data = request.data
if 'object' in 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 # if the notification should not be sent, accept the request but do nothing
return Response(status=status.HTTP_204_NO_CONTENT) return Response(status=status.HTTP_204_NO_CONTENT)
......
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