2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-07-02 19:50:59 +00:00

Raise error if version fails (#3792)

* add comment where feature should be

* add triggermethod for superusers

* Add plugin version warning

* switch to simple error logging

* switch import mechanism

* move import down

* reintroduce db notifications

* adding mising import

* add db entry

* Only log to DB if plugin was regsitered

* fix merge

* remove db logging
This commit is contained in:
Matthias Mair
2022-10-18 00:55:56 +02:00
committed by GitHub
parent 9cfbe1061d
commit 3bd64e9098
2 changed files with 38 additions and 4 deletions

View File

@ -12,7 +12,7 @@ import InvenTree.helpers
from common.models import NotificationEntry, NotificationMessage
from InvenTree.ready import isImportingData
from plugin import registry
from plugin.models import NotificationUserSetting
from plugin.models import NotificationUserSetting, PluginConfig
from users.models import Owner
logger = logging.getLogger('inventree')
@ -397,6 +397,28 @@ def trigger_notification(obj, category=None, obj_ref='pk', **kwargs):
logger.info(f"No possible users for notification '{category}'")
def trigger_superuser_notification(plugin: PluginConfig, msg: str):
"""Trigger a notification to all superusers.
Args:
plugin (PluginConfig): Plugin that is raising the notification
msg (str): Detailed message that should be attached
"""
users = get_user_model().objects.filter(is_superuser=True)
trigger_notification(
plugin,
'inventree.plugin',
context={
'error': plugin,
'name': _('Error raised by plugin'),
'message': msg,
},
targets=users,
delivery_methods=set([UIMessageNotification]),
)
def deliver_notification(cls: NotificationMethod, obj, category: str, targets, context: dict):
"""Send notification with the provided class.