2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-06-18 13:05:42 +00:00

user notification settings

This commit is contained in:
Matthias
2022-04-04 23:46:19 +02:00
parent 2fee6b02db
commit 1eb511e8a0
9 changed files with 153 additions and 3 deletions

View File

@ -265,6 +265,12 @@ class BaseInvenTreeSetting(models.Model):
filters['plugin'] = plugin
kwargs['plugin'] = plugin
# Filter by method
method = kwargs.get('method', None)
if method is not None:
filters['method'] = method
try:
setting = settings.filter(**filters).first()
except (ValueError, cls.DoesNotExist):

View File

@ -5,6 +5,7 @@ from InvenTree.helpers import inheritors
from InvenTree.ready import isImportingData
from common.models import NotificationEntry, NotificationMessage
from plugin import registry
from plugin.models import NotificationUserSetting
logger = logging.getLogger('inventree')
@ -20,6 +21,7 @@ class NotificationMethod:
CONTEXT_BUILTIN = ['name', 'message', ]
CONTEXT_EXTRA = []
GLOBAL_SETTING = None
USER_SETTING = None
def __init__(self, obj, category, targets, context) -> None:
# Check if a sending fnc is defined
@ -127,10 +129,33 @@ class BulkNotificationMethod(NotificationMethod):
class MethodStorageClass:
liste = None
user_settings = {}
def collect(self):
storage.liste = inheritors(NotificationMethod) - IGNORED_NOTIFICATION_CLS
def get_usersettings(self, user):
methods = []
for item in storage.liste:
if item.USER_SETTING:
new_key = f'NOTIFICATION_METHOD_{item.METHOD_NAME.upper()}'
# make sure the setting exists
self.user_settings[new_key] = item.USER_SETTING
NotificationUserSetting.get_setting(
key=new_key,
user=user,
method=item.METHOD_NAME,
)
# save definition
methods.append({
'key': new_key,
'icon': 'envelope',
'method': item.METHOD_NAME,
})
return methods
IGNORED_NOTIFICATION_CLS = set([
SingleNotificationMethod,