From 67d9d9413f5e75111b409568e7b5b9ddf2fb951a Mon Sep 17 00:00:00 2001 From: Oliver Date: Thu, 30 Dec 2021 22:58:11 +1100 Subject: [PATCH 01/11] Plugin code bug fix - handle case where self.plugin is None --- InvenTree/plugin/models.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/InvenTree/plugin/models.py b/InvenTree/plugin/models.py index b8178440af..811ed5b431 100644 --- a/InvenTree/plugin/models.py +++ b/InvenTree/plugin/models.py @@ -54,7 +54,11 @@ class PluginConfig(models.Model): # extra attributes from the registry def mixins(self): - return self.plugin._mixinreg + + if self.plugin: + return self.plugin._mixinreg + else: + return {} # functions From 690ba811efc70d76584eab8520f8fc97504cf5fd Mon Sep 17 00:00:00 2001 From: Oliver Date: Thu, 30 Dec 2021 22:58:52 +1100 Subject: [PATCH 02/11] require gnupg in docker image --- docker/Dockerfile | 1 + 1 file changed, 1 insertion(+) diff --git a/docker/Dockerfile b/docker/Dockerfile index 0978e43075..673792a22f 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -59,6 +59,7 @@ RUN apk -U upgrade # Install required system packages RUN apk add --no-cache git make bash \ gcc libgcc g++ libstdc++ \ + gnupg \ libjpeg-turbo libjpeg-turbo-dev jpeg jpeg-dev \ libffi libffi-dev \ zlib zlib-dev \ From 04820c894b35ad70910f53ee29eb2424129d6145 Mon Sep 17 00:00:00 2001 From: Oliver Date: Thu, 30 Dec 2021 23:04:08 +1100 Subject: [PATCH 03/11] getattr should look for "SETTINGS" and not "GLOBALSETTINGS" --- InvenTree/plugin/builtin/integration/mixins.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/InvenTree/plugin/builtin/integration/mixins.py b/InvenTree/plugin/builtin/integration/mixins.py index 3a6b558db7..0af66333cb 100644 --- a/InvenTree/plugin/builtin/integration/mixins.py +++ b/InvenTree/plugin/builtin/integration/mixins.py @@ -1,14 +1,19 @@ -"""default mixins for IntegrationMixins""" +""" +Plugin mixin classes +""" + from django.conf.urls import url, include from plugin.urls import PLUGIN_BASE class GlobalSettingsMixin: - """Mixin that enables global settings for the plugin""" + """ + Mixin that enables global settings for the plugin + """ + class MixinMeta: - """meta options for this mixin""" - MIXIN_NAME = 'Global settings' + MIXIN_NAME = 'Settings' def __init__(self): super().__init__() @@ -19,7 +24,7 @@ class GlobalSettingsMixin: """ setup global settings for this plugin """ - return getattr(self, 'GLOBALSETTINGS', None) + return getattr(self, 'SETTINGS', None) @property def has_globalsettings(self): From be3bb05eddff6f202affeb0753dc17d9cfc69f7e Mon Sep 17 00:00:00 2001 From: Oliver Date: Thu, 30 Dec 2021 23:06:28 +1100 Subject: [PATCH 04/11] Improve docstrings --- .../plugin/builtin/integration/mixins.py | 28 +++++++++++++------ 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/InvenTree/plugin/builtin/integration/mixins.py b/InvenTree/plugin/builtin/integration/mixins.py index 0af66333cb..03922603a7 100644 --- a/InvenTree/plugin/builtin/integration/mixins.py +++ b/InvenTree/plugin/builtin/integration/mixins.py @@ -11,7 +11,7 @@ class GlobalSettingsMixin: """ Mixin that enables global settings for the plugin """ - + class MixinMeta: MIXIN_NAME = 'Settings' @@ -22,28 +22,30 @@ class GlobalSettingsMixin: def setup_globalsettings(self): """ - setup global settings for this plugin + Setup global settings for this plugin """ return getattr(self, 'SETTINGS', None) @property def has_globalsettings(self): """ - does this plugin use custom global settings + Does this plugin use custom global settings """ return bool(self.globalsettings) @property def globalsettingspatterns(self): """ - get patterns for InvenTreeSetting defintion + Get patterns for InvenTreeSetting defintion """ if self.has_globalsettings: return {f'PLUGIN_{self.slug.upper()}_{key}': value for key, value in self.globalsettings.items()} return None def _globalsetting_name(self, key): - """get global name of setting""" + """ + Get global name of setting + """ return f'PLUGIN_{self.slug.upper()}_{key}' def get_globalsetting(self, key): @@ -62,9 +64,11 @@ class GlobalSettingsMixin: class UrlsMixin: - """Mixin that enables urls for the plugin""" + """ + Mixin that enables custom URLs for the plugin + """ + class MixinMeta: - """meta options for this mixin""" MIXIN_NAME = 'URLs' def __init__(self): @@ -110,7 +114,10 @@ class UrlsMixin: class NavigationMixin: - """Mixin that enables adding navigation links with the plugin""" + """ + Mixin that enables custom navigation links with the plugin + """ + NAVIGATION_TAB_NAME = None NAVIGATION_TAB_ICON = "fas fa-question" @@ -157,7 +164,10 @@ class NavigationMixin: class AppMixin: - """Mixin that enables full django app functions for a plugin""" + """ + Mixin that enables full django app functions for a plugin + """ + class MixinMeta: """meta options for this mixin""" MIXIN_NAME = 'App registration' From f97ffaf9c3d89a0a13ec43cc9db85014cdc7e168 Mon Sep 17 00:00:00 2001 From: Oliver Date: Thu, 30 Dec 2021 23:08:33 +1100 Subject: [PATCH 05/11] Visual tweak to settings page --- InvenTree/templates/InvenTree/settings/plugin.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/InvenTree/templates/InvenTree/settings/plugin.html b/InvenTree/templates/InvenTree/settings/plugin.html index e9f33bedaf..ac3129eddc 100644 --- a/InvenTree/templates/InvenTree/settings/plugin.html +++ b/InvenTree/templates/InvenTree/settings/plugin.html @@ -70,7 +70,7 @@ {% if mixin_list %} {% for mixin in mixin_list %} - {% blocktrans with name=mixin.human_name %}has {{name}}{% endblocktrans %} + {{ mixin.human_name }} {% endfor %} {% endif %} From 76fe774b6e3edc4a8a35cdc4ebf8f1897f55c383 Mon Sep 17 00:00:00 2001 From: Oliver Date: Thu, 30 Dec 2021 23:11:12 +1100 Subject: [PATCH 06/11] Visual tweaks --- InvenTree/templates/InvenTree/settings/plugin_settings.html | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/InvenTree/templates/InvenTree/settings/plugin_settings.html b/InvenTree/templates/InvenTree/settings/plugin_settings.html index e3b1f18046..f8ab02de3e 100644 --- a/InvenTree/templates/InvenTree/settings/plugin_settings.html +++ b/InvenTree/templates/InvenTree/settings/plugin_settings.html @@ -67,7 +67,10 @@ {% if plugin.is_package == False %} -

{% trans 'The code information is pulled from the latest git commit for this plugin. It might not reflect official version numbers or information but the actual code running.' %}

+
+ {% trans 'The code information is pulled from the latest git commit for this plugin. It might not reflect official version numbers or information but the actual code running.' %} +
+ {% endif %}
From 572f4a21b3a40b2c3ca90160b2ea0f4478276f6b Mon Sep 17 00:00:00 2001 From: Oliver Date: Thu, 30 Dec 2021 23:13:33 +1100 Subject: [PATCH 07/11] capitalization --- InvenTree/templates/InvenTree/settings/mixins/urls.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/InvenTree/templates/InvenTree/settings/mixins/urls.html b/InvenTree/templates/InvenTree/settings/mixins/urls.html index 1f317b5dc0..4bebfbce89 100644 --- a/InvenTree/templates/InvenTree/settings/mixins/urls.html +++ b/InvenTree/templates/InvenTree/settings/mixins/urls.html @@ -18,7 +18,7 @@ {{key}} {{entry.1}} - {% trans 'open in new tab' %} + {% trans 'Open in new tab' %} {% endif %}{% endfor %} From e02a2cef1b5c6e3f6fd76bf9bef68bd998525da7 Mon Sep 17 00:00:00 2001 From: Oliver Date: Fri, 31 Dec 2021 14:18:27 +1100 Subject: [PATCH 08/11] Fixes unit test --- InvenTree/plugin/test_integration.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/InvenTree/plugin/test_integration.py b/InvenTree/plugin/test_integration.py index df80016dc8..fa585d0a40 100644 --- a/InvenTree/plugin/test_integration.py +++ b/InvenTree/plugin/test_integration.py @@ -21,7 +21,7 @@ class BaseMixinDefinition: class GlobalSettingsMixinTest(BaseMixinDefinition, TestCase): - MIXIN_HUMAN_NAME = 'Global settings' + MIXIN_HUMAN_NAME = 'Settings' MIXIN_NAME = 'globalsettings' MIXIN_ENABLE_CHECK = 'has_globalsettings' From 02e0ea6e3aeda8b8a27726eed16ab39bd5700320 Mon Sep 17 00:00:00 2001 From: Oliver Date: Fri, 31 Dec 2021 14:25:22 +1100 Subject: [PATCH 09/11] Rename "GlobalSettingsPlugin" -> "SettingsPlugin" --- InvenTree/plugin/builtin/integration/mixins.py | 2 +- InvenTree/plugin/mixins/__init__.py | 7 +++++-- InvenTree/plugin/samples/integration/sample.py | 11 +++++++---- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/InvenTree/plugin/builtin/integration/mixins.py b/InvenTree/plugin/builtin/integration/mixins.py index 03922603a7..7ddfeeccb8 100644 --- a/InvenTree/plugin/builtin/integration/mixins.py +++ b/InvenTree/plugin/builtin/integration/mixins.py @@ -7,7 +7,7 @@ from django.conf.urls import url, include from plugin.urls import PLUGIN_BASE -class GlobalSettingsMixin: +class SettingsMixin: """ Mixin that enables global settings for the plugin """ diff --git a/InvenTree/plugin/mixins/__init__.py b/InvenTree/plugin/mixins/__init__.py index feb6bc3466..ceb5de5885 100644 --- a/InvenTree/plugin/mixins/__init__.py +++ b/InvenTree/plugin/mixins/__init__.py @@ -1,6 +1,9 @@ """utility class to enable simpler imports""" -from ..builtin.integration.mixins import AppMixin, GlobalSettingsMixin, UrlsMixin, NavigationMixin +from ..builtin.integration.mixins import AppMixin, SettingsMixin, UrlsMixin, NavigationMixin __all__ = [ - 'AppMixin', 'GlobalSettingsMixin', 'UrlsMixin', 'NavigationMixin', + 'AppMixin', + 'NavigationMixin', + 'SettingsMixin', + 'UrlsMixin', ] diff --git a/InvenTree/plugin/samples/integration/sample.py b/InvenTree/plugin/samples/integration/sample.py index d7321f8a88..afc4a8fe8a 100644 --- a/InvenTree/plugin/samples/integration/sample.py +++ b/InvenTree/plugin/samples/integration/sample.py @@ -1,15 +1,18 @@ -"""sample implementations for IntegrationPlugin""" +""" +Sample implementations for IntegrationPlugin +""" + from plugin import IntegrationPluginBase -from plugin.mixins import AppMixin, GlobalSettingsMixin, UrlsMixin, NavigationMixin +from plugin.mixins import AppMixin, SettingsMixin, UrlsMixin, NavigationMixin from django.http import HttpResponse from django.utils.translation import ugettext_lazy as _ from django.conf.urls import url, include -class SampleIntegrationPlugin(AppMixin, GlobalSettingsMixin, UrlsMixin, NavigationMixin, IntegrationPluginBase): +class SampleIntegrationPlugin(AppMixin, SettingsMixin, UrlsMixin, NavigationMixin, IntegrationPluginBase): """ - An full integration plugin + A full integration plugin example """ PLUGIN_NAME = "SampleIntegrationPlugin" From 4b4d4be13ecbf57a526978b4f14230bb17052599 Mon Sep 17 00:00:00 2001 From: Oliver Date: Fri, 31 Dec 2021 14:28:16 +1100 Subject: [PATCH 10/11] Registry name fixes --- InvenTree/plugin/builtin/integration/mixins.py | 10 ++-------- InvenTree/plugin/registry.py | 2 +- InvenTree/plugin/test_integration.py | 10 +++++----- 3 files changed, 8 insertions(+), 14 deletions(-) diff --git a/InvenTree/plugin/builtin/integration/mixins.py b/InvenTree/plugin/builtin/integration/mixins.py index 7ddfeeccb8..c7edc8ac36 100644 --- a/InvenTree/plugin/builtin/integration/mixins.py +++ b/InvenTree/plugin/builtin/integration/mixins.py @@ -17,14 +17,8 @@ class SettingsMixin: def __init__(self): super().__init__() - self.add_mixin('globalsettings', 'has_globalsettings', __class__) - self.globalsettings = self.setup_globalsettings() - - def setup_globalsettings(self): - """ - Setup global settings for this plugin - """ - return getattr(self, 'SETTINGS', None) + self.add_mixin('settings', 'has_globalsettings', __class__) + self.globalsettings = getattr(self, 'SETTINGS', None) @property def has_globalsettings(self): diff --git a/InvenTree/plugin/registry.py b/InvenTree/plugin/registry.py index 4fc5330f8b..d858d6c7f0 100644 --- a/InvenTree/plugin/registry.py +++ b/InvenTree/plugin/registry.py @@ -251,7 +251,7 @@ class Plugins: 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('globalsettings'): + if plugin.mixin_enabled('settings'): plugin_setting = plugin.globalsettingspatterns self.mixins_globalsettings[slug] = plugin_setting diff --git a/InvenTree/plugin/test_integration.py b/InvenTree/plugin/test_integration.py index fa585d0a40..c83be385a6 100644 --- a/InvenTree/plugin/test_integration.py +++ b/InvenTree/plugin/test_integration.py @@ -8,7 +8,7 @@ from django.contrib.auth import get_user_model from datetime import datetime from plugin import IntegrationPluginBase -from plugin.mixins import AppMixin, GlobalSettingsMixin, UrlsMixin, NavigationMixin +from plugin.mixins import AppMixin, SettingsMixin, UrlsMixin, NavigationMixin from plugin.urls import PLUGIN_BASE @@ -20,19 +20,19 @@ class BaseMixinDefinition: self.assertEqual(self.mixin.registered_mixins[0]['human_name'], self.MIXIN_HUMAN_NAME) -class GlobalSettingsMixinTest(BaseMixinDefinition, TestCase): +class SettingsMixinTest(BaseMixinDefinition, TestCase): MIXIN_HUMAN_NAME = 'Settings' - MIXIN_NAME = 'globalsettings' + MIXIN_NAME = 'settings' MIXIN_ENABLE_CHECK = 'has_globalsettings' TEST_SETTINGS = {'SETTING1': {'default': '123', }} def setUp(self): - class SettingsCls(GlobalSettingsMixin, IntegrationPluginBase): + class SettingsCls(SettingsMixin, IntegrationPluginBase): GLOBALSETTINGS = self.TEST_SETTINGS self.mixin = SettingsCls() - class NoSettingsCls(GlobalSettingsMixin, IntegrationPluginBase): + class NoSettingsCls(SettingsMixin, IntegrationPluginBase): pass self.mixin_nothing = NoSettingsCls() From 78120bb0207866fa4277866f8c179b20fc6c4697 Mon Sep 17 00:00:00 2001 From: Oliver Date: Fri, 31 Dec 2021 14:54:19 +1100 Subject: [PATCH 11/11] Fixes for unit tests --- InvenTree/plugin/test_integration.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/InvenTree/plugin/test_integration.py b/InvenTree/plugin/test_integration.py index c83be385a6..1371535cfa 100644 --- a/InvenTree/plugin/test_integration.py +++ b/InvenTree/plugin/test_integration.py @@ -29,7 +29,7 @@ class SettingsMixinTest(BaseMixinDefinition, TestCase): def setUp(self): class SettingsCls(SettingsMixin, IntegrationPluginBase): - GLOBALSETTINGS = self.TEST_SETTINGS + SETTINGS = self.TEST_SETTINGS self.mixin = SettingsCls() class NoSettingsCls(SettingsMixin, IntegrationPluginBase):