diff --git a/InvenTree/InvenTree/settings.py b/InvenTree/InvenTree/settings.py index 6c6008a029..82ad722e2e 100644 --- a/InvenTree/InvenTree/settings.py +++ b/InvenTree/InvenTree/settings.py @@ -863,5 +863,5 @@ if DEBUG or TESTING: PLUGINS = [] INTEGRATION_PLUGINS = {} INTEGRATION_PLUGINS_INACTIVE = {} -INTEGRATION_PLUGIN_SETTING = {} +INTEGRATION_PLUGIN_GLOBALSETTING = {} INTEGRATION_APPS_LOADED = False # Marks if apps were reloaded yet diff --git a/InvenTree/common/models.py b/InvenTree/common/models.py index 762589a1b0..50b7beac13 100644 --- a/InvenTree/common/models.py +++ b/InvenTree/common/models.py @@ -979,9 +979,9 @@ class InvenTreeSetting(BaseInvenTreeSetting): 'validator': bool, 'requires_restart': True, }, - 'ENABLE_PLUGINS_SETTING': { - 'name': _('Enable setting integration'), - 'description': _('Enable plugins to integrate into inventree settings'), + 'ENABLE_PLUGINS_GLOBALSETTING': { + 'name': _('Enable global setting integration'), + 'description': _('Enable plugins to integrate into inventree global settings'), 'default': False, 'validator': bool, 'requires_restart': True, diff --git a/InvenTree/plugin/apps.py b/InvenTree/plugin/apps.py index 932ed22027..5ba9719a41 100644 --- a/InvenTree/plugin/apps.py +++ b/InvenTree/plugin/apps.py @@ -92,20 +92,20 @@ class PluginAppConfig(AppConfig): logger.info(f'Found {len(plugins)} active plugins') # if plugin settings are enabled enhance the settings - self.activate_integration_settings(plugins) + self.activate_integration_globalsettings(plugins) # if plugin apps are enabled self.activate_integration_app(plugins) - def activate_integration_settings(self, plugins): + def activate_integration_globalsettings(self, plugins): from common.models import InvenTreeSetting - if settings.PLUGIN_TESTING or InvenTreeSetting.get_setting('ENABLE_PLUGINS_SETTING'): - logger.info('Registering IntegrationPlugin settings') + if settings.PLUGIN_TESTING or InvenTreeSetting.get_setting('ENABLE_PLUGINS_GLOBALSETTING'): + logger.info('Registering IntegrationPlugin global settings') for slug, plugin in plugins: - if plugin.mixin_enabled('settings'): - plugin_setting = plugin.settingspatterns - settings.INTEGRATION_PLUGIN_SETTING[slug] = plugin_setting + if plugin.mixin_enabled('globalsettings'): + plugin_setting = plugin.globalsettingspatterns + settings.INTEGRATION_PLUGIN_GLOBALSETTING[slug] = plugin_setting # Add to settings dir InvenTreeSetting.GLOBAL_SETTINGS.update(plugin_setting) diff --git a/InvenTree/plugin/integration.py b/InvenTree/plugin/integration.py index 6b142e3b24..c734725a42 100644 --- a/InvenTree/plugin/integration.py +++ b/InvenTree/plugin/integration.py @@ -57,53 +57,53 @@ class MixinBase: return mixins -class SettingsMixin: - """Mixin that enables settings for the plugin""" +class GlobalSettingsMixin: + """Mixin that enables global settings for the plugin""" class Meta: """meta options for this mixin""" - MIXIN_NAME = 'Settings' + MIXIN_NAME = 'Global settings' def __init__(self): super().__init__() - self.add_mixin('settings', 'has_settings', __class__) - self.settings = self.setup_settings() + self.add_mixin('globalsettings', 'has_globalsettings', __class__) + self.globalsettings = self.setup_globalsettings() - def setup_settings(self): + def setup_globalsettings(self): """ - setup settings for this plugin + setup global settings for this plugin """ - return getattr(self, 'SETTINGS', None) + return getattr(self, 'GLOBALSETTINGS', None) @property - def has_settings(self): + def has_globalsettings(self): """ - does this plugin use custom settings + does this plugin use custom global settings """ - return bool(self.settings) + return bool(self.globalsettings) @property - def settingspatterns(self): + def globalsettingspatterns(self): """ get patterns for InvenTreeSetting defintion """ - if self.has_settings: - return {f'PLUGIN_{self.slug.upper()}_{key}': value for key, value in self.settings.items()} + if self.has_globalsettings: + return {f'PLUGIN_{self.slug.upper()}_{key}': value for key, value in self.globalsettings.items()} return None - def _setting_name(self, key): + def _globalsetting_name(self, key): """get global name of setting""" return f'PLUGIN_{self.slug.upper()}_{key}' - def get_setting(self, key): + def get_globalsetting(self, key): """ - get plugin setting by key + get plugin global setting by key """ from common.models import InvenTreeSetting - return InvenTreeSetting.get_setting(self._setting_name(key)) + return InvenTreeSetting.get_setting(self._globalsetting_name(key)) - def set_setting(self, key, value, user): + def set_globalsetting(self, key, value, user): """ - set plugin setting by key + set plugin global setting by key """ from common.models import InvenTreeSetting return InvenTreeSetting.set_setting(self._setting_name(key), value, user) diff --git a/InvenTree/plugin/samples/integration/sample.py b/InvenTree/plugin/samples/integration/sample.py index b6be51823d..bf99697b11 100644 --- a/InvenTree/plugin/samples/integration/sample.py +++ b/InvenTree/plugin/samples/integration/sample.py @@ -1,12 +1,12 @@ """sample implementations for IntegrationPlugin""" -from plugin.integration import AppMixin, SettingsMixin, UrlsMixin, NavigationMixin, IntegrationPluginBase +from plugin.integration import AppMixin, GlobalSettingsMixin, UrlsMixin, NavigationMixin, IntegrationPluginBase from django.http import HttpResponse from django.utils.translation import ugettext_lazy as _ from django.conf.urls import url, include -class SampleIntegrationPlugin(AppMixin, SettingsMixin, UrlsMixin, NavigationMixin, IntegrationPluginBase): +class SampleIntegrationPlugin(AppMixin, GlobalSettingsMixin, UrlsMixin, NavigationMixin, IntegrationPluginBase): """ An full integration plugin """ diff --git a/InvenTree/plugin/templatetags/plugin_extras.py b/InvenTree/plugin/templatetags/plugin_extras.py index 44a1c292ed..05ba26d09d 100644 --- a/InvenTree/plugin/templatetags/plugin_extras.py +++ b/InvenTree/plugin/templatetags/plugin_extras.py @@ -25,9 +25,9 @@ def inactive_plugin_list(*args, **kwargs): @register.simple_tag() -def plugin_settings(plugin, *args, **kwargs): - """ Return a list of all settings for a plugin """ - return djangosettings.INTEGRATION_PLUGIN_SETTING.get(plugin) +def plugin_globalsettings(plugin, *args, **kwargs): + """ Return a list of all global settings for a plugin """ + return djangosettings.INTEGRATION_PLUGIN_GLOBALSETTING.get(plugin) @register.simple_tag() diff --git a/InvenTree/plugin/test_integration.py b/InvenTree/plugin/test_integration.py index 3befdf6b00..9bc7c8639c 100644 --- a/InvenTree/plugin/test_integration.py +++ b/InvenTree/plugin/test_integration.py @@ -7,7 +7,7 @@ from django.contrib.auth import get_user_model from datetime import datetime -from plugin.integration import AppMixin, IntegrationPluginBase, SettingsMixin, UrlsMixin, NavigationMixin +from plugin.integration import AppMixin, IntegrationPluginBase, GlobalSettingsMixin, UrlsMixin, NavigationMixin class BaseMixinDefinition: @@ -18,19 +18,19 @@ class BaseMixinDefinition: self.assertEqual(self.mixin.registered_mixins[0]['human_name'], self.MIXIN_HUMAN_NAME) -class SettingsMixinTest(BaseMixinDefinition, TestCase): - MIXIN_HUMAN_NAME = 'Settings' - MIXIN_NAME = 'settings' - MIXIN_ENABLE_CHECK = 'has_settings' +class GlobalSettingsMixinTest(BaseMixinDefinition, TestCase): + MIXIN_HUMAN_NAME = 'Global settings' + MIXIN_NAME = 'globalsettings' + MIXIN_ENABLE_CHECK = 'has_globalsettings' TEST_SETTINGS = {'SETTING1': {'default': '123', }} def setUp(self): - class SettingsCls(SettingsMixin, IntegrationPluginBase): + class SettingsCls(GlobalSettingsMixin, IntegrationPluginBase): SETTINGS = self.TEST_SETTINGS self.mixin = SettingsCls() - class NoSettingsCls(SettingsMixin, IntegrationPluginBase): + class NoSettingsCls(GlobalSettingsMixin, IntegrationPluginBase): pass self.mixin_nothing = NoSettingsCls() @@ -40,25 +40,25 @@ class SettingsMixinTest(BaseMixinDefinition, TestCase): def test_function(self): # settings variable - self.assertEqual(self.mixin.settings, self.TEST_SETTINGS) + self.assertEqual(self.mixin.globalsettings, self.TEST_SETTINGS) # settings pattern target_pattern = {f'PLUGIN_{self.mixin.slug.upper()}_{key}': value for key, value in self.mixin.settings.items()} - self.assertEqual(self.mixin.settingspatterns, target_pattern) + self.assertEqual(self.mixin.globalsettingspatterns, target_pattern) # no settings - self.assertIsNone(self.mixin_nothing.settings) - self.assertIsNone(self.mixin_nothing.settingspatterns) + self.assertIsNone(self.mixin_nothing.globalsettings) + self.assertIsNone(self.mixin_nothing.globalsettingspatterns) # calling settings # not existing - self.assertEqual(self.mixin.get_setting('ABCD'), '') - self.assertEqual(self.mixin_nothing.get_setting('ABCD'), '') + self.assertEqual(self.mixin.get_globalsetting('ABCD'), '') + self.assertEqual(self.mixin_nothing.get_globalsetting('ABCD'), '') # right setting - self.mixin.set_setting('SETTING1', '12345', self.test_user) - self.assertEqual(self.mixin.get_setting('SETTING1'), '12345') + self.mixin.set_globalsetting('SETTING1', '12345', self.test_user) + self.assertEqual(self.mixin.get_globalsetting('SETTING1'), '12345') # no setting - self.assertEqual(self.mixin_nothing.get_setting(''), '') + self.assertEqual(self.mixin_nothing.get_globalsetting(''), '') class UrlsMixinTest(BaseMixinDefinition, TestCase): diff --git a/InvenTree/plugin/test_plugin.py b/InvenTree/plugin/test_plugin.py index bbdab1589d..f365944098 100644 --- a/InvenTree/plugin/test_plugin.py +++ b/InvenTree/plugin/test_plugin.py @@ -59,9 +59,9 @@ class PluginTagTests(TestCase): """test that all plugins are listed""" self.assertEqual(plugin_tags.plugin_list(), settings.INTEGRATION_PLUGINS) - def test_tag_plugin_settings(self): + def test_tag_plugin_globalsettings(self): """check all plugins are listed""" - self.assertEqual(plugin_tags.plugin_settings(self.sample), settings.INTEGRATION_PLUGIN_SETTING.get(self.sample)) + self.assertEqual(plugin_tags.plugin_globalsettings(self.sample), settings.INTEGRATION_PLUGIN_GLOBALSETTING.get(self.sample)) def test_tag_mixin_enabled(self): """check that mixin enabled functions work""" diff --git a/InvenTree/templates/InvenTree/settings/mixins/settings.html b/InvenTree/templates/InvenTree/settings/mixins/settings.html index 3b5b1e80e3..3c87da8678 100644 --- a/InvenTree/templates/InvenTree/settings/mixins/settings.html +++ b/InvenTree/templates/InvenTree/settings/mixins/settings.html @@ -2,7 +2,7 @@ {% load plugin_extras %}

{% trans "Settings" %}

-{% plugin_settings plugin_key as plugin_settings %} +{% plugin_globalsettings plugin_key as plugin_settings %} diff --git a/InvenTree/templates/InvenTree/settings/plugin.html b/InvenTree/templates/InvenTree/settings/plugin.html index fae029b687..d996933007 100644 --- a/InvenTree/templates/InvenTree/settings/plugin.html +++ b/InvenTree/templates/InvenTree/settings/plugin.html @@ -20,7 +20,7 @@ {% include "InvenTree/settings/setting.html" with key="ENABLE_PLUGINS_URL" %} {% include "InvenTree/settings/setting.html" with key="ENABLE_PLUGINS_NAVIGATION" %} - {% include "InvenTree/settings/setting.html" with key="ENABLE_PLUGINS_SETTING"%} + {% include "InvenTree/settings/setting.html" with key="ENABLE_PLUGINS_GLOBALSETTING"%} {% include "InvenTree/settings/setting.html" with key="ENABLE_PLUGINS_APP"%}
diff --git a/InvenTree/templates/InvenTree/settings/plugin_settings.html b/InvenTree/templates/InvenTree/settings/plugin_settings.html index 22e81e1873..3ae22371c2 100644 --- a/InvenTree/templates/InvenTree/settings/plugin_settings.html +++ b/InvenTree/templates/InvenTree/settings/plugin_settings.html @@ -120,8 +120,8 @@ -{% mixin_enabled plugin 'settings' as settings %} -{% if settings %} +{% mixin_enabled plugin 'globalsettings' as globalsettings %} +{% if globalsettings %} {% include 'InvenTree/settings/mixins/settings.html' %} {% endif %}