mirror of
https://github.com/inventree/InvenTree.git
synced 2025-04-28 11:36:44 +00:00
Optional error notification (#5506)
* Add user setting for receiving error notifications * Ignore uses who don't want error notifications * Add config to settings page
This commit is contained in:
parent
2243f288ee
commit
f917c91522
@ -887,6 +887,7 @@ def after_error_logged(sender, instance: Error, created: bool, **kwargs):
|
|||||||
|
|
||||||
if created:
|
if created:
|
||||||
try:
|
try:
|
||||||
|
import common.models
|
||||||
import common.notifications
|
import common.notifications
|
||||||
|
|
||||||
users = get_user_model().objects.filter(is_staff=True)
|
users = get_user_model().objects.filter(is_staff=True)
|
||||||
@ -902,13 +903,20 @@ def after_error_logged(sender, instance: Error, created: bool, **kwargs):
|
|||||||
'link': link
|
'link': link
|
||||||
}
|
}
|
||||||
|
|
||||||
common.notifications.trigger_notification(
|
target_users = []
|
||||||
instance,
|
|
||||||
'inventree.error_log',
|
for user in users:
|
||||||
context=context,
|
if common.models.InvenTreeUserSetting.get_setting('NOTIFICATION_ERROR_REPORT', True, user=user):
|
||||||
targets=users,
|
target_users.append(user)
|
||||||
delivery_methods={common.notifications.UIMessageNotification, },
|
|
||||||
)
|
if len(target_users) > 0:
|
||||||
|
common.notifications.trigger_notification(
|
||||||
|
instance,
|
||||||
|
'inventree.error_log',
|
||||||
|
context=context,
|
||||||
|
targets=users,
|
||||||
|
delivery_methods={common.notifications.UIMessageNotification, },
|
||||||
|
)
|
||||||
|
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
"""We do not want to throw an exception while reporting an exception"""
|
"""We do not want to throw an exception while reporting an exception"""
|
||||||
|
@ -2191,6 +2191,13 @@ class InvenTreeUserSetting(BaseInvenTreeSetting):
|
|||||||
'default': '',
|
'default': '',
|
||||||
},
|
},
|
||||||
|
|
||||||
|
'NOTIFICATION_ERROR_REPORT': {
|
||||||
|
'name': _('Receive error reports'),
|
||||||
|
'description': _('Receive notifications for system errors'),
|
||||||
|
'default': True,
|
||||||
|
'validator': bool,
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
typ = 'user'
|
typ = 'user'
|
||||||
|
@ -13,6 +13,9 @@
|
|||||||
<div class='row'>
|
<div class='row'>
|
||||||
<table class='table table-striped table-condensed'>
|
<table class='table table-striped table-condensed'>
|
||||||
<tbody>
|
<tbody>
|
||||||
|
{% if user.is_staff %}
|
||||||
|
{% include "InvenTree/settings/setting.html" with key="NOTIFICATION_ERROR_REPORT" icon='fa-flag' user_setting=True %}
|
||||||
|
{% endif %}
|
||||||
{% notification_settings_list as settings %}
|
{% notification_settings_list as settings %}
|
||||||
{% for setting in settings %}
|
{% for setting in settings %}
|
||||||
{% include "InvenTree/settings/setting.html" with key=setting.key icon=setting.icon method=setting.method notification_setting=True %}
|
{% include "InvenTree/settings/setting.html" with key=setting.key icon=setting.icon method=setting.method notification_setting=True %}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user