mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Add links to all notifications that do not have a link (#3431)
* refactor link * [FR] Error notifications should provide link to the error Fixes #3367
This commit is contained in:
parent
742e579fa7
commit
ae07247a82
@ -650,13 +650,15 @@ def after_error_logged(sender, instance: Error, created: bool, **kwargs):
|
|||||||
|
|
||||||
users = get_user_model().objects.filter(is_staff=True)
|
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 = {
|
context = {
|
||||||
'error': instance,
|
'error': instance,
|
||||||
'name': _('Server Error'),
|
'name': _('Server Error'),
|
||||||
'message': _('An error has been logged by the server.'),
|
'message': _('An error has been logged by the server.'),
|
||||||
'link': InvenTree.helpers.construct_absolute_url(
|
'link': link
|
||||||
reverse('admin:error_report_error_change', kwargs={'object_id': instance.pk})
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
common.notifications.trigger_notification(
|
common.notifications.trigger_notification(
|
||||||
|
@ -1,10 +1,12 @@
|
|||||||
"""JSON serializers for common components."""
|
"""JSON serializers for common components."""
|
||||||
|
|
||||||
|
from django.urls import reverse
|
||||||
|
|
||||||
from rest_framework import serializers
|
from rest_framework import serializers
|
||||||
|
|
||||||
from common.models import (InvenTreeSetting, InvenTreeUserSetting,
|
from common.models import (InvenTreeSetting, InvenTreeUserSetting,
|
||||||
NotificationMessage)
|
NotificationMessage)
|
||||||
from InvenTree.helpers import get_objectreference
|
from InvenTree.helpers import construct_absolute_url, get_objectreference
|
||||||
from InvenTree.serializers import InvenTreeModelSerializer
|
from InvenTree.serializers import InvenTreeModelSerializer
|
||||||
|
|
||||||
|
|
||||||
@ -157,7 +159,22 @@ class NotificationMessageSerializer(InvenTreeModelSerializer):
|
|||||||
|
|
||||||
def get_target(self, obj):
|
def get_target(self, obj):
|
||||||
"""Function to resolve generic object reference to target."""
|
"""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):
|
def get_source(self, obj):
|
||||||
"""Function to resolve generic object reference to source."""
|
"""Function to resolve generic object reference to source."""
|
||||||
|
Loading…
Reference in New Issue
Block a user