From c16c26c4967382a11487f038215a8954aca06174 Mon Sep 17 00:00:00 2001 From: Matthias Date: Sat, 16 Oct 2021 04:17:48 +0200 Subject: [PATCH] setting to control plugin settings ingestion --- InvenTree/InvenTree/settings.py | 6 +----- InvenTree/common/models.py | 7 ++++++- InvenTree/plugin/apps.py | 19 +++++++++++++++++++ .../templates/InvenTree/settings/plugin.html | 1 + 4 files changed, 27 insertions(+), 6 deletions(-) create mode 100644 InvenTree/plugin/apps.py diff --git a/InvenTree/InvenTree/settings.py b/InvenTree/InvenTree/settings.py index e1dabedc49..ba17ed6815 100644 --- a/InvenTree/InvenTree/settings.py +++ b/InvenTree/InvenTree/settings.py @@ -266,6 +266,7 @@ INSTALLED_APPS = [ 'report.apps.ReportConfig', 'stock.apps.StockConfig', 'users.apps.UsersConfig', + 'plugin.apps.PluginConfig', 'InvenTree.apps.InvenTreeConfig', # InvenTree app runs last # Third part add-ons @@ -764,11 +765,6 @@ for plugin in inventree_plugins.load_integration_plugins(): INTEGRATION_PLUGINS.append(plugin) INTEGRATION_PLUGIN_LIST[plugin.slug] = plugin - if plugin.mixin_enabled('settings'): - plugin_setting = plugin.settingspatterns - - INTEGRATION_PLUGIN_SETTING[plugin.slug] = plugin_setting - INTEGRATION_PLUGIN_SETTINGS.update(plugin_setting) if plugin.mixin_enabled('app'): plugin_path = '.'.join(pathlib.Path(plugin.path).relative_to(BASE_DIR).parts) diff --git a/InvenTree/common/models.py b/InvenTree/common/models.py index 8bdc48bbb1..1415319b58 100644 --- a/InvenTree/common/models.py +++ b/InvenTree/common/models.py @@ -866,7 +866,12 @@ class InvenTreeSetting(BaseInvenTreeSetting): 'default': False, 'validator': bool, }, - **settings.INTEGRATION_PLUGIN_SETTINGS, + 'ENABLE_PLUGINS_SETTING': { + 'name': _('Enable setting integration'), + 'description': _('Enable plugins to integrate into inventree settings'), + 'default': False, + 'validator': bool, + }, } class Meta: diff --git a/InvenTree/plugin/apps.py b/InvenTree/plugin/apps.py new file mode 100644 index 0000000000..197834c373 --- /dev/null +++ b/InvenTree/plugin/apps.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.apps import AppConfig +from django.conf import settings + + +class PluginConfig(AppConfig): + name = 'plugin' + + def ready(self): + from common.models import InvenTreeSetting + + if InvenTreeSetting.get_setting('ENABLE_PLUGINS_SETTING'): + for slug, plugin in settings.INTEGRATION_PLUGIN_LIST.items(): + if plugin.mixin_enabled('settings'): + plugin_setting = plugin.settingspatterns + settings.INTEGRATION_PLUGIN_SETTING[slug] = plugin_setting + settings.INTEGRATION_PLUGIN_SETTINGS.update(plugin_setting) diff --git a/InvenTree/templates/InvenTree/settings/plugin.html b/InvenTree/templates/InvenTree/settings/plugin.html index 19ab02761a..69c9bb719a 100644 --- a/InvenTree/templates/InvenTree/settings/plugin.html +++ b/InvenTree/templates/InvenTree/settings/plugin.html @@ -18,6 +18,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"%}