def get_usersettings(self, user) -> list: """Returns all user settings for a specific user. This is needed to show them in the settings UI. Args: user (User): User that should be used as a filter. Returns: list: All applicablae notification settings. """ 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': getattr(item, 'METHOD_ICON', ''), 'method': item.METHOD_NAME, }) return methods
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)
def test_email(self): """ Ensure that the email notifications run """ # enable plugin and set mail setting to true plugin = registry.plugins.get('corenotificationsplugin') plugin.set_setting('ENABLE_NOTIFICATION_EMAILS', True) NotificationUserSetting.set_setting( key='NOTIFICATION_METHOD_MAIL', value=True, change_user=self.user, user=self.user, method=CoreNotificationsPlugin.EmailNotification.METHOD_NAME) # run through self._notification_run(CoreNotificationsPlugin.EmailNotification)
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': getattr(item, 'METHOD_ICON', ''), 'method': item.METHOD_NAME, }) return methods
def setting_object(key, *args, **kwargs): """ Return a setting object speciifed by the given key (Or return None if the setting does not exist) if a user-setting was requested return that """ if 'plugin' in kwargs: # Note, 'plugin' is an instance of an InvenTreePlugin class plugin = kwargs['plugin'] return PluginSetting.get_setting_object(key, plugin=plugin) if 'method' in kwargs: return NotificationUserSetting.get_setting_object(key, user=kwargs['user'], method=kwargs['method']) if 'user' in kwargs: return InvenTreeUserSetting.get_setting_object(key, user=kwargs['user']) return InvenTreeSetting.get_setting_object(key)
def test_setting(self): """Test the string name for NotificationUserSetting.""" test_setting = NotificationUserSetting.get_setting_object('NOTIFICATION_METHOD_MAIL', user=self.user) self.assertEqual(str(test_setting), 'NOTIFICATION_METHOD_MAIL (for testuser): ')