fix: author for deletion and ignore activities related models
This commit is contained in:
parent
eb06f2c38c
commit
87e5d8688f
@ -12,6 +12,7 @@ class CurrentUserMiddleware:
|
|||||||
self.process_request(request)
|
self.process_request(request)
|
||||||
response = self.get_response(request)
|
response = self.get_response(request)
|
||||||
signals.pre_save.disconnect(dispatch_uid=request)
|
signals.pre_save.disconnect(dispatch_uid=request)
|
||||||
|
signals.pre_delete.disconnect(dispatch_uid=request)
|
||||||
return response
|
return response
|
||||||
|
|
||||||
def process_request(self, request):
|
def process_request(self, request):
|
||||||
@ -26,6 +27,8 @@ class CurrentUserMiddleware:
|
|||||||
user = None
|
user = None
|
||||||
|
|
||||||
def _update_users(sender, instance, **kwargs):
|
def _update_users(sender, instance, **kwargs):
|
||||||
setattr(instance, MODEL_MODIFICATION_USER_FIELD, user)
|
if(type(instance).__name__ != "ScheduledActivity" and type(instance).__name__ != "LogEntry" and type(instance).__name__ != "Activity"):
|
||||||
|
setattr(instance, MODEL_MODIFICATION_USER_FIELD, user)
|
||||||
|
|
||||||
signals.pre_save.connect(_update_users, dispatch_uid=request, weak=False)
|
signals.pre_save.connect(_update_users, dispatch_uid=request, weak=False)
|
||||||
|
signals.pre_delete.connect(_update_users, dispatch_uid=request, weak=False)
|
||||||
|
@ -132,41 +132,42 @@ def create_nested_subscribers(sender, instance, created, **kwargs):
|
|||||||
@receiver(post_save, dispatch_uid="callback_notif")
|
@receiver(post_save, dispatch_uid="callback_notif")
|
||||||
@receiver(post_delete, dispatch_uid="delete_callback_notif")
|
@receiver(post_delete, dispatch_uid="delete_callback_notif")
|
||||||
def send_notification(sender, instance, **kwargs):
|
def send_notification(sender, instance, **kwargs):
|
||||||
if sender != Notification:
|
if(type(instance).__name__ != "ScheduledActivity" and type(instance).__name__ != "LogEntry" and type(instance).__name__ != "Activity"):
|
||||||
# don't send notifications for foreign resources
|
if sender != Notification:
|
||||||
if hasattr(instance, 'urlid') and Model.is_external(instance.urlid):
|
# don't send notifications for foreign resources
|
||||||
return
|
if hasattr(instance, 'urlid') and Model.is_external(instance.urlid):
|
||||||
|
return
|
||||||
|
|
||||||
recipients = []
|
recipients = []
|
||||||
try:
|
try:
|
||||||
url_container = settings.BASE_URL + Model.container_id(instance)
|
url_container = settings.BASE_URL + Model.container_id(instance)
|
||||||
url_resource = settings.BASE_URL + Model.resource_id(instance)
|
url_resource = settings.BASE_URL + Model.resource_id(instance)
|
||||||
except NoReverseMatch:
|
except NoReverseMatch:
|
||||||
return
|
return
|
||||||
|
|
||||||
# dispatch a notification for every Subscription on this resource
|
# dispatch a notification for every Subscription on this resource
|
||||||
for subscription in Subscription.objects.filter(models.Q(object=url_resource) | models.Q(object=url_container)):
|
for subscription in Subscription.objects.filter(models.Q(object=url_resource) | models.Q(object=url_container)):
|
||||||
if subscription.inbox not in recipients and (not subscription.is_backlink or not kwargs.get("created")):
|
if subscription.inbox not in recipients and (not subscription.is_backlink or not kwargs.get("created")):
|
||||||
# I may have configured to send the subscription to a foreign key
|
# I may have configured to send the subscription to a foreign key
|
||||||
if subscription.field is not None and len(subscription.field) > 1:
|
if subscription.field is not None and len(subscription.field) > 1:
|
||||||
try:
|
try:
|
||||||
if kwargs.get("created"):
|
if kwargs.get("created"):
|
||||||
|
continue
|
||||||
|
|
||||||
|
instance = getattr(instance, subscription.field, instance)
|
||||||
|
|
||||||
|
# don't send notifications for foreign resources
|
||||||
|
if hasattr(instance, 'urlid') and Model.is_external(instance.urlid):
|
||||||
|
continue
|
||||||
|
|
||||||
|
url_resource = settings.BASE_URL + Model.resource_id(instance)
|
||||||
|
except NoReverseMatch:
|
||||||
|
continue
|
||||||
|
except ObjectDoesNotExist:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
instance = getattr(instance, subscription.field, instance)
|
send_request(subscription.inbox, url_resource, instance, kwargs.get("created"))
|
||||||
|
recipients.append(subscription.inbox)
|
||||||
# don't send notifications for foreign resources
|
|
||||||
if hasattr(instance, 'urlid') and Model.is_external(instance.urlid):
|
|
||||||
continue
|
|
||||||
|
|
||||||
url_resource = settings.BASE_URL + Model.resource_id(instance)
|
|
||||||
except NoReverseMatch:
|
|
||||||
continue
|
|
||||||
except ObjectDoesNotExist:
|
|
||||||
continue
|
|
||||||
|
|
||||||
send_request(subscription.inbox, url_resource, instance, kwargs.get("created", False))
|
|
||||||
recipients.append(subscription.inbox)
|
|
||||||
|
|
||||||
|
|
||||||
@receiver(activity_sending_finished, sender=ActivityQueueService)
|
@receiver(activity_sending_finished, sender=ActivityQueueService)
|
||||||
@ -181,9 +182,11 @@ def _handle_prosody_response(sender, response, saved_activity, **kwargs):
|
|||||||
|
|
||||||
|
|
||||||
def send_request(target, object_iri, instance, created):
|
def send_request(target, object_iri, instance, created):
|
||||||
unknown = str(_("Auteur inconnu"))
|
author = getattr(getattr(instance, MODEL_MODIFICATION_USER_FIELD, None), "urlid", str(_("Auteur inconnu")))
|
||||||
author = getattr(getattr(instance, MODEL_MODIFICATION_USER_FIELD, unknown), "urlid", unknown)
|
if(created is not None):
|
||||||
request_type = "creation" if created else "update"
|
request_type = "creation" if created else "update"
|
||||||
|
else:
|
||||||
|
request_type = "deletion"
|
||||||
|
|
||||||
# local inbox
|
# local inbox
|
||||||
if target.startswith(settings.SITE_URL):
|
if target.startswith(settings.SITE_URL):
|
||||||
|
Loading…
Reference in New Issue
Block a user