diff --git a/netbox/extras/events.py b/netbox/extras/events.py index ad603d11a..f13a3b48f 100644 --- a/netbox/extras/events.py +++ b/netbox/extras/events.py @@ -139,6 +139,7 @@ def process_event_rules(event_rules, object_type, event_type, data, username=Non event_rule.action_object.notify( object_type=object_type, object_id=data['id'], + object_repr=data.get('display'), event_type=event_type ) diff --git a/netbox/extras/views.py b/netbox/extras/views.py index 8eb9f412d..aaf8ff393 100644 --- a/netbox/extras/views.py +++ b/netbox/extras/views.py @@ -424,11 +424,16 @@ class NotificationReadView(LoginRequiredMixin, View): Mark the Notification read and redirect the user to its attached object. """ def get(self, request, pk): + # Mark the Notification as read notification = get_object_or_404(request.user.notifications, pk=pk) notification.read = timezone.now() notification.save() - return redirect(notification.object.get_absolute_url()) + # Redirect to the object if it has a URL (deleted objects will not) + if hasattr(notification.object, 'get_absolute_url'): + return redirect(notification.object.get_absolute_url()) + + return redirect('account:notifications') @register_model_view(Notification, 'dismiss') diff --git a/netbox/templates/htmx/notifications.html b/netbox/templates/htmx/notifications.html index 23660e4c5..e03e5afc9 100644 --- a/netbox/templates/htmx/notifications.html +++ b/netbox/templates/htmx/notifications.html @@ -7,7 +7,11 @@