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)
|
||||
response = self.get_response(request)
|
||||
signals.pre_save.disconnect(dispatch_uid=request)
|
||||
signals.pre_delete.disconnect(dispatch_uid=request)
|
||||
return response
|
||||
|
||||
def process_request(self, request):
|
||||
@ -26,6 +27,8 @@ class CurrentUserMiddleware:
|
||||
user = None
|
||||
|
||||
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_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_delete, dispatch_uid="delete_callback_notif")
|
||||
def send_notification(sender, instance, **kwargs):
|
||||
if sender != Notification:
|
||||
# don't send notifications for foreign resources
|
||||
if hasattr(instance, 'urlid') and Model.is_external(instance.urlid):
|
||||
return
|
||||
if(type(instance).__name__ != "ScheduledActivity" and type(instance).__name__ != "LogEntry" and type(instance).__name__ != "Activity"):
|
||||
if sender != Notification:
|
||||
# don't send notifications for foreign resources
|
||||
if hasattr(instance, 'urlid') and Model.is_external(instance.urlid):
|
||||
return
|
||||
|
||||
recipients = []
|
||||
try:
|
||||
url_container = settings.BASE_URL + Model.container_id(instance)
|
||||
url_resource = settings.BASE_URL + Model.resource_id(instance)
|
||||
except NoReverseMatch:
|
||||
return
|
||||
recipients = []
|
||||
try:
|
||||
url_container = settings.BASE_URL + Model.container_id(instance)
|
||||
url_resource = settings.BASE_URL + Model.resource_id(instance)
|
||||
except NoReverseMatch:
|
||||
return
|
||||
|
||||
# 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)):
|
||||
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
|
||||
if subscription.field is not None and len(subscription.field) > 1:
|
||||
try:
|
||||
if kwargs.get("created"):
|
||||
# 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)):
|
||||
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
|
||||
if subscription.field is not None and len(subscription.field) > 1:
|
||||
try:
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
send_request(subscription.inbox, url_resource, instance, kwargs.get("created", False))
|
||||
recipients.append(subscription.inbox)
|
||||
send_request(subscription.inbox, url_resource, instance, kwargs.get("created"))
|
||||
recipients.append(subscription.inbox)
|
||||
|
||||
|
||||
@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):
|
||||
unknown = str(_("Auteur inconnu"))
|
||||
author = getattr(getattr(instance, MODEL_MODIFICATION_USER_FIELD, unknown), "urlid", unknown)
|
||||
request_type = "creation" if created else "update"
|
||||
author = getattr(getattr(instance, MODEL_MODIFICATION_USER_FIELD, None), "urlid", str(_("Auteur inconnu")))
|
||||
if(created is not None):
|
||||
request_type = "creation" if created else "update"
|
||||
else:
|
||||
request_type = "deletion"
|
||||
|
||||
# local inbox
|
||||
if target.startswith(settings.SITE_URL):
|
||||
|
Loading…
Reference in New Issue
Block a user