mkae user setting access simpler

This commit is contained in:
Matthias 2022-04-06 23:58:11 +02:00
parent 547c51b81b
commit 4c1a0ea9ce
No known key found for this signature in database
GPG Key ID: F50EF5741D33E076
2 changed files with 8 additions and 3 deletions

View File

@ -114,6 +114,12 @@ class NotificationMethod:
# Lets go!
return False
def usersetting(self, target):
"""
Returns setting for this method for a given user
"""
return NotificationUserSetting.get_setting(f'NOTIFICATION_METHOD_{self.METHOD_NAME.upper()}', user=target, method=self.METHOD_NAME)
# endregion
@ -220,7 +226,7 @@ def trigger_notifaction(obj, category=None, obj_ref='pk', **kwargs):
if NotificationEntry.check_recent(category, obj_ref_value, delta):
logger.info(f"Notification '{category}' has recently been sent for '{str(obj)}' - SKIPPING")
return
# return
logger.info(f"Gathering users for notification '{category}'")
# Collect possible targets

View File

@ -7,7 +7,6 @@ from allauth.account.models import EmailAddress
from plugin import IntegrationPluginBase
from plugin.mixins import BulkNotificationMethod, SettingsMixin
from plugin.models import NotificationUserSetting
import InvenTree.tasks
@ -59,7 +58,7 @@ class CoreNotificationsPlugin(SettingsMixin, IntegrationPluginBase):
allowed_users = []
for user in self.targets:
allows_emails = NotificationUserSetting.get_setting('NOTIFICATION_METHOD_MAIL', user=user, method=self.METHOD_NAME)
allows_emails = self.usersetting(user)
if allows_emails:
allowed_users.append(user)