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:
Oliver 2023-09-05 15:23:14 +10:00 committed by GitHub
parent 2243f288ee
commit f917c91522
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 25 additions and 7 deletions

View File

@ -887,6 +887,7 @@ def after_error_logged(sender, instance: Error, created: bool, **kwargs):
if created:
try:
import common.models
import common.notifications
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
}
common.notifications.trigger_notification(
instance,
'inventree.error_log',
context=context,
targets=users,
delivery_methods={common.notifications.UIMessageNotification, },
)
target_users = []
for user in users:
if common.models.InvenTreeUserSetting.get_setting('NOTIFICATION_ERROR_REPORT', True, user=user):
target_users.append(user)
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:
"""We do not want to throw an exception while reporting an exception"""

View File

@ -2191,6 +2191,13 @@ class InvenTreeUserSetting(BaseInvenTreeSetting):
'default': '',
},
'NOTIFICATION_ERROR_REPORT': {
'name': _('Receive error reports'),
'description': _('Receive notifications for system errors'),
'default': True,
'validator': bool,
}
}
typ = 'user'

View File

@ -13,6 +13,9 @@
<div class='row'>
<table class='table table-striped table-condensed'>
<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 %}
{% for setting in settings %}
{% include "InvenTree/settings/setting.html" with key=setting.key icon=setting.icon method=setting.method notification_setting=True %}