Repository: inventree/InvenTree

Issue:
[FR] Error notifications should provide link to the error
A notification for a server error should provide a link to the error (on the admin page) which allows staff users to quickly look at the error message.
[FR] Error notifications should provide link to the error
A notification for a server error should provide a link to the error (on the admin page) which allows staff users to quickly look at the error message.


Discussion:

Resolving patch:
diff --git a/InvenTree/InvenTree/models.py b/InvenTree/InvenTree/models.py
--- a/InvenTree/InvenTree/models.py
+++ b/InvenTree/InvenTree/models.py
@@ -650,13 +650,15 @@ def after_error_logged(sender, instance: Error, created: bool, **kwargs):
 
             users = get_user_model().objects.filter(is_staff=True)
 
+            link = InvenTree.helpers.construct_absolute_url(
+                reverse('admin:error_report_error_change', kwargs={'object_id': instance.pk})
+            )
+
             context = {
                 'error': instance,
                 'name': _('Server Error'),
                 'message': _('An error has been logged by the server.'),
-                'link': InvenTree.helpers.construct_absolute_url(
-                    reverse('admin:error_report_error_change', kwargs={'object_id': instance.pk})
-                )
+                'link': link
             }
 
             common.notifications.trigger_notification(
diff --git a/InvenTree/common/serializers.py b/InvenTree/common/serializers.py
--- a/InvenTree/common/serializers.py
+++ b/InvenTree/common/serializers.py
@@ -1,10 +1,12 @@
 """JSON serializers for common components."""
 
+from django.urls import reverse
+
 from rest_framework import serializers
 
 from common.models import (InvenTreeSetting, InvenTreeUserSetting,
                            NotificationMessage)
-from InvenTree.helpers import get_objectreference
+from InvenTree.helpers import construct_absolute_url, get_objectreference
 from InvenTree.serializers import InvenTreeModelSerializer
 
 
@@ -157,7 +159,22 @@ class NotificationMessageSerializer(InvenTreeModelSerializer):
 
     def get_target(self, obj):
         """Function to resolve generic object reference to target."""
-        return get_objectreference(obj, 'target_content_type', 'target_object_id')
+        target = get_objectreference(obj, 'target_content_type', 'target_object_id')
+
+        if 'link' not in target:
+            # Check if objekt has an absolute_url function
+            if hasattr(obj.target_object, 'get_absolute_url'):
+                target['link'] = obj.target_object.get_absolute_url()
+            else:
+                # check if user is staff - link to admin
+                request = self.context['request']
+                if request.user and request.user.is_staff:
+                    meta = obj.target_object._meta
+                    target['link'] = construct_absolute_url(reverse(
+                        f'admin:{meta.db_table}_change',
+                        kwargs={'object_id': obj.target_object_id}
+                    ))
+        return target
 
     def get_source(self, obj):
         """Function to resolve generic object reference to source."""


Test patch: