diff --git a/InvenTree/common/notifications.py b/InvenTree/common/notifications.py index ef4de4fc61..7f6aece282 100644 --- a/InvenTree/common/notifications.py +++ b/InvenTree/common/notifications.py @@ -108,7 +108,7 @@ class NotificationMethod: return False # Check if method globally enabled - plg_instance = registry.plugins.get(plg_cls.PLUGIN_NAME.lower()) + plg_instance = registry.plugins.get(plg_cls.NAME.lower()) if plg_instance and not plg_instance.get_setting(self.GLOBAL_SETTING): return True diff --git a/InvenTree/plugin/base/action/mixins.py b/InvenTree/plugin/base/action/mixins.py index 18a1876659..e2fef5869f 100644 --- a/InvenTree/plugin/base/action/mixins.py +++ b/InvenTree/plugin/base/action/mixins.py @@ -24,7 +24,7 @@ class ActionMixin: Action name for this plugin. If the ACTION_NAME parameter is empty, - uses the PLUGIN_NAME instead. + uses the NAME instead. """ if self.ACTION_NAME: return self.ACTION_NAME diff --git a/InvenTree/plugin/base/action/test_action.py b/InvenTree/plugin/base/action/test_action.py index 24caf175fc..97768e94a0 100644 --- a/InvenTree/plugin/base/action/test_action.py +++ b/InvenTree/plugin/base/action/test_action.py @@ -31,7 +31,7 @@ class ActionMixinTests(TestCase): self.action_plugin = TestActionPlugin('user') class NameActionPlugin(ActionMixin, InvenTreePlugin): - PLUGIN_NAME = 'Aplugin' + NAME = 'Aplugin' self.action_name = NameActionPlugin('user') diff --git a/InvenTree/plugin/base/integration/mixins.py b/InvenTree/plugin/base/integration/mixins.py index cf8b951a20..257493e156 100644 --- a/InvenTree/plugin/base/integration/mixins.py +++ b/InvenTree/plugin/base/integration/mixins.py @@ -373,7 +373,7 @@ class LabelPrintingMixin: """ Mixin which enables direct printing of stock labels. - Each plugin must provide a PLUGIN_NAME attribute, which is used to uniquely identify the printer. + Each plugin must provide a NAME attribute, which is used to uniquely identify the printer. The plugin must also implement the print_label() function """ @@ -428,7 +428,7 @@ class APICallMixin: ''' A small api call sample ''' - PLUGIN_NAME = "Sample API Caller" + NAME = "Sample API Caller" SETTINGS = { 'API_TOKEN': { diff --git a/InvenTree/plugin/base/integration/test_mixins.py b/InvenTree/plugin/base/integration/test_mixins.py index 2283a3a1d2..b87583f301 100644 --- a/InvenTree/plugin/base/integration/test_mixins.py +++ b/InvenTree/plugin/base/integration/test_mixins.py @@ -147,7 +147,7 @@ class APICallMixinTest(BaseMixinDefinition, TestCase): def setUp(self): class MixinCls(APICallMixin, SettingsMixin, InvenTreePlugin): - PLUGIN_NAME = "Sample API Caller" + NAME = "Sample API Caller" SETTINGS = { 'API_TOKEN': { diff --git a/InvenTree/plugin/builtin/action/simpleactionplugin.py b/InvenTree/plugin/builtin/action/simpleactionplugin.py index ef69511cfe..d2a321789d 100644 --- a/InvenTree/plugin/builtin/action/simpleactionplugin.py +++ b/InvenTree/plugin/builtin/action/simpleactionplugin.py @@ -10,7 +10,7 @@ class SimpleActionPlugin(ActionMixin, InvenTreePlugin): the capability of the ActionMixin class """ - PLUGIN_NAME = "SimpleActionPlugin" + NAME = "SimpleActionPlugin" ACTION_NAME = "simple" def perform_action(self): diff --git a/InvenTree/plugin/builtin/barcodes/inventree_barcode.py b/InvenTree/plugin/builtin/barcodes/inventree_barcode.py index 6b84f4a8c2..f9f498ccd8 100644 --- a/InvenTree/plugin/builtin/barcodes/inventree_barcode.py +++ b/InvenTree/plugin/builtin/barcodes/inventree_barcode.py @@ -24,7 +24,7 @@ from rest_framework.exceptions import ValidationError class InvenTreeBarcodePlugin(BarcodeMixin, InvenTreePlugin): - PLUGIN_NAME = "InvenTreeBarcode" + NAME = "InvenTreeBarcode" def validate(self): """ diff --git a/InvenTree/plugin/builtin/integration/core_notifications.py b/InvenTree/plugin/builtin/integration/core_notifications.py index dbde7747e9..67b61eea3b 100644 --- a/InvenTree/plugin/builtin/integration/core_notifications.py +++ b/InvenTree/plugin/builtin/integration/core_notifications.py @@ -20,7 +20,7 @@ class CoreNotificationsPlugin(SettingsMixin, InvenTreePlugin): Core notification methods for InvenTree """ - PLUGIN_NAME = "CoreNotificationsPlugin" + NAME = "CoreNotificationsPlugin" AUTHOR = _('InvenTree contributors') DESCRIPTION = _('Integrated outgoing notificaton methods') diff --git a/InvenTree/plugin/helpers.py b/InvenTree/plugin/helpers.py index db6f9635a2..1217fa4d47 100644 --- a/InvenTree/plugin/helpers.py +++ b/InvenTree/plugin/helpers.py @@ -205,7 +205,7 @@ def get_plugins(pkg, baseclass): Return a list of all modules under a given package. - Modules must be a subclass of the provided 'baseclass' - - Modules must have a non-empty PLUGIN_NAME parameter + - Modules must have a non-empty NAME parameter """ plugins = [] @@ -217,7 +217,7 @@ def get_plugins(pkg, baseclass): # Iterate through each class in the module for item in get_classes(mod): plugin = item[1] - if issubclass(plugin, baseclass) and plugin.PLUGIN_NAME: + if issubclass(plugin, baseclass) and plugin.NAME: plugins.append(plugin) return plugins diff --git a/InvenTree/plugin/registry.py b/InvenTree/plugin/registry.py index 4975144bfc..a17f802baf 100644 --- a/InvenTree/plugin/registry.py +++ b/InvenTree/plugin/registry.py @@ -281,8 +281,8 @@ class PluginsRegistry: # Check if activated # These checks only use attributes - never use plugin supplied functions -> that would lead to arbitrary code execution!! - plug_name = plugin.PLUGIN_NAME - plug_key = plugin.PLUGIN_SLUG if getattr(plugin, 'PLUGIN_SLUG', None) else plug_name + plug_name = plugin.NAME + plug_key = plugin.SLUG if getattr(plugin, 'SLUG', None) else plug_name plug_key = slugify(plug_key) # keys are slugs! try: plugin_db_setting, _ = PluginConfig.objects.get_or_create(key=plug_key, name=plug_name) @@ -314,7 +314,7 @@ class PluginsRegistry: # now we can be sure that an admin has activated the plugin # TODO check more stuff -> as of Nov 2021 there are not many checks in place # but we could enhance those to check signatures, run the plugin against a whitelist etc. - logger.info(f'Loading integration plugin {plugin.PLUGIN_NAME}') + logger.info(f'Loading plugin {plug_name}') try: plugin = plugin() @@ -322,7 +322,7 @@ class PluginsRegistry: # log error and raise it -> disable plugin handle_error(error, log_name='init') - logger.debug(f'Loaded integration plugin {plugin.PLUGIN_NAME}') + logger.debug(f'Loaded plugin {plug_name}') plugin.is_package = was_packaged @@ -516,7 +516,7 @@ class PluginsRegistry: plugin_path = '.'.join(pathlib.Path(plugin.path).relative_to(settings.BASE_DIR).parts) except ValueError: # pragma: no cover # plugin is shipped as package - plugin_path = plugin.PLUGIN_NAME + plugin_path = plugin.NAME return plugin_path def deactivate_integration_app(self): diff --git a/InvenTree/plugin/samples/event/event_sample.py b/InvenTree/plugin/samples/event/event_sample.py index 2e629a48a4..5411781e05 100644 --- a/InvenTree/plugin/samples/event/event_sample.py +++ b/InvenTree/plugin/samples/event/event_sample.py @@ -11,9 +11,9 @@ class EventPluginSample(EventMixin, InvenTreePlugin): A sample plugin which provides supports for triggered events """ - PLUGIN_NAME = "EventPlugin" - PLUGIN_SLUG = "event" - PLUGIN_TITLE = "Triggered Events" + NAME = "EventPlugin" + SLUG = "event" + TITLE = "Triggered Events" def process_event(self, event, *args, **kwargs): """ Custom event processing """ diff --git a/InvenTree/plugin/samples/integration/another_sample.py b/InvenTree/plugin/samples/integration/another_sample.py index d36dbf13e8..f6f9306a95 100644 --- a/InvenTree/plugin/samples/integration/another_sample.py +++ b/InvenTree/plugin/samples/integration/another_sample.py @@ -8,7 +8,7 @@ class NoIntegrationPlugin(InvenTreePlugin): An basic integration plugin """ - PLUGIN_NAME = "NoIntegrationPlugin" + NAME = "NoIntegrationPlugin" class WrongIntegrationPlugin(UrlsMixin, InvenTreePlugin): @@ -16,4 +16,4 @@ class WrongIntegrationPlugin(UrlsMixin, InvenTreePlugin): An basic integration plugin """ - PLUGIN_NAME = "WrongIntegrationPlugin" + NAME = "WrongIntegrationPlugin" diff --git a/InvenTree/plugin/samples/integration/api_caller.py b/InvenTree/plugin/samples/integration/api_caller.py index 3de07508a0..98a145de34 100644 --- a/InvenTree/plugin/samples/integration/api_caller.py +++ b/InvenTree/plugin/samples/integration/api_caller.py @@ -9,7 +9,7 @@ class SampleApiCallerPlugin(APICallMixin, SettingsMixin, InvenTreePlugin): """ A small api call sample """ - PLUGIN_NAME = "Sample API Caller" + NAME = "Sample API Caller" SETTINGS = { 'API_TOKEN': { diff --git a/InvenTree/plugin/samples/integration/broken_sample.py b/InvenTree/plugin/samples/integration/broken_sample.py index 50aecc3c35..0d17d661ae 100644 --- a/InvenTree/plugin/samples/integration/broken_sample.py +++ b/InvenTree/plugin/samples/integration/broken_sample.py @@ -6,9 +6,9 @@ class BrokenIntegrationPlugin(InvenTreePlugin): """ An very broken integration plugin """ - PLUGIN_NAME = 'Test' - PLUGIN_TITLE = 'Broken Plugin' - PLUGIN_SLUG = 'broken' + NAME = 'Test' + TITLE = 'Broken Plugin' + SLUG = 'broken' def __init__(self): super().__init__() diff --git a/InvenTree/plugin/samples/integration/custom_panel_sample.py b/InvenTree/plugin/samples/integration/custom_panel_sample.py index 36793ddf6a..0203fc4e04 100644 --- a/InvenTree/plugin/samples/integration/custom_panel_sample.py +++ b/InvenTree/plugin/samples/integration/custom_panel_sample.py @@ -14,9 +14,9 @@ class CustomPanelSample(PanelMixin, SettingsMixin, InvenTreePlugin): A sample plugin which renders some custom panels. """ - PLUGIN_NAME = "CustomPanelExample" - PLUGIN_SLUG = "panel" - PLUGIN_TITLE = "Custom Panel Example" + NAME = "CustomPanelExample" + SLUG = "panel" + TITLE = "Custom Panel Example" DESCRIPTION = "An example plugin demonstrating how custom panels can be added to the user interface" VERSION = "0.1" diff --git a/InvenTree/plugin/samples/integration/sample.py b/InvenTree/plugin/samples/integration/sample.py index 115a943f87..0d83c262d5 100644 --- a/InvenTree/plugin/samples/integration/sample.py +++ b/InvenTree/plugin/samples/integration/sample.py @@ -15,9 +15,9 @@ class SampleIntegrationPlugin(AppMixin, SettingsMixin, UrlsMixin, NavigationMixi A full integration plugin example """ - PLUGIN_NAME = "SampleIntegrationPlugin" - PLUGIN_SLUG = "sample" - PLUGIN_TITLE = "Sample Plugin" + NAME = "SampleIntegrationPlugin" + SLUG = "sample" + TITLE = "Sample Plugin" NAVIGATION_TAB_NAME = "Sample Nav" NAVIGATION_TAB_ICON = 'fas fa-plus' diff --git a/InvenTree/plugin/samples/integration/scheduled_task.py b/InvenTree/plugin/samples/integration/scheduled_task.py index fe1069efb8..2a59f820c6 100644 --- a/InvenTree/plugin/samples/integration/scheduled_task.py +++ b/InvenTree/plugin/samples/integration/scheduled_task.py @@ -20,9 +20,9 @@ class ScheduledTaskPlugin(ScheduleMixin, SettingsMixin, InvenTreePlugin): A sample plugin which provides support for scheduled tasks """ - PLUGIN_NAME = "ScheduledTasksPlugin" - PLUGIN_SLUG = "schedule" - PLUGIN_TITLE = "Scheduled Tasks" + NAME = "ScheduledTasksPlugin" + SLUG = "schedule" + TITLE = "Scheduled Tasks" SCHEDULED_TASKS = { 'member': { diff --git a/InvenTree/plugin/samples/integration/test_scheduled_task.py b/InvenTree/plugin/samples/integration/test_scheduled_task.py index c4d234b0ba..5be1dce250 100644 --- a/InvenTree/plugin/samples/integration/test_scheduled_task.py +++ b/InvenTree/plugin/samples/integration/test_scheduled_task.py @@ -54,7 +54,7 @@ class ScheduledTaskPluginTests(TestCase): def test_init(self): """Check that all MixinImplementationErrors raise""" class Base(ScheduleMixin, InvenTreePlugin): - PLUGIN_NAME = 'APlugin' + NAME = 'APlugin' class NoSchedules(Base): """Plugin without schedules""" diff --git a/InvenTree/plugin/test_plugin.py b/InvenTree/plugin/test_plugin.py index 84263979a0..f93ad3c67c 100644 --- a/InvenTree/plugin/test_plugin.py +++ b/InvenTree/plugin/test_plugin.py @@ -65,19 +65,19 @@ class InvenTreePluginTests(TestCase): class NamedPlugin(InvenTreePlugin): """a named plugin""" - PLUGIN_NAME = 'abc123' + NAME = 'abc123' self.named_plugin = NamedPlugin() class SimpleInvenTreePlugin(InvenTreePlugin): - PLUGIN_NAME = 'SimplePlugin' + NAME = 'SimplePlugin' self.plugin_simple = SimpleInvenTreePlugin() class NameInvenTreePlugin(InvenTreePlugin): - PLUGIN_NAME = 'Aplugin' - PLUGIN_SLUG = 'a' - PLUGIN_TITLE = 'a titel' + NAME = 'Aplugin' + SLUG = 'a' + TITLE = 'a titel' PUBLISH_DATE = "1111-11-11" AUTHOR = 'AA BB' DESCRIPTION = 'A description' @@ -90,12 +90,12 @@ class InvenTreePluginTests(TestCase): def test_basic_plugin_init(self): """check if a basic plugin intis""" - self.assertEqual(self.plugin.PLUGIN_NAME, '') + self.assertEqual(self.plugin.NAME, '') self.assertEqual(self.plugin.plugin_name(), '') def test_basic_plugin_name(self): """check if the name of a basic plugin can be set""" - self.assertEqual(self.named_plugin.PLUGIN_NAME, 'abc123') + self.assertEqual(self.named_plugin.NAME, 'abc123') self.assertEqual(self.named_plugin.plugin_name(), 'abc123') def test_basic_is_active(self):