mirror of
https://github.com/inventree/InvenTree.git
synced 2025-06-18 13:05:42 +00:00
Fixes for loading plugins
- Always load 'builtin' plugins - Refactor calls to "is_active" at various points in codebase
This commit is contained in:
@ -67,9 +67,7 @@ class LabelPrintMixin:
|
|||||||
plugin = registry.get_plugin(plugin_key)
|
plugin = registry.get_plugin(plugin_key)
|
||||||
|
|
||||||
if plugin:
|
if plugin:
|
||||||
config = plugin.plugin_config()
|
if plugin.is_active():
|
||||||
|
|
||||||
if config and config.active:
|
|
||||||
# Only return the plugin if it is enabled!
|
# Only return the plugin if it is enabled!
|
||||||
return plugin
|
return plugin
|
||||||
else:
|
else:
|
||||||
|
@ -58,9 +58,8 @@ def register_event(event, *args, **kwargs):
|
|||||||
|
|
||||||
if plugin.mixin_enabled('events'):
|
if plugin.mixin_enabled('events'):
|
||||||
|
|
||||||
config = plugin.plugin_config()
|
if plugin.is_active():
|
||||||
|
# Only allow event registering for 'active' plugins
|
||||||
if config and config.active:
|
|
||||||
|
|
||||||
logger.debug(f"Registering callback for plugin '{slug}'")
|
logger.debug(f"Registering callback for plugin '{slug}'")
|
||||||
|
|
||||||
|
@ -9,6 +9,8 @@ references model objects actually exist in the database.
|
|||||||
|
|
||||||
import json
|
import json
|
||||||
|
|
||||||
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
|
||||||
from company.models import SupplierPart
|
from company.models import SupplierPart
|
||||||
from InvenTree.helpers import hash_barcode
|
from InvenTree.helpers import hash_barcode
|
||||||
from part.models import Part
|
from part.models import Part
|
||||||
@ -64,6 +66,8 @@ class InvenTreeInternalBarcodePlugin(InvenTreeBarcodePlugin):
|
|||||||
|
|
||||||
NAME = "InvenTreeInternalBarcode"
|
NAME = "InvenTreeInternalBarcode"
|
||||||
TITLE = "Inventree Barcodes"
|
TITLE = "Inventree Barcodes"
|
||||||
|
VERSION = "2.0"
|
||||||
|
AUTHOR = _("InvenTree contributors")
|
||||||
|
|
||||||
def scan(self, barcode_data):
|
def scan(self, barcode_data):
|
||||||
"""Scan a barcode against this plugin.
|
"""Scan a barcode against this plugin.
|
||||||
|
@ -111,10 +111,10 @@ class MetaBase:
|
|||||||
if self.is_builtin:
|
if self.is_builtin:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
cfg = self.plugin_config()
|
config = self.plugin_config()
|
||||||
|
|
||||||
if cfg:
|
if config:
|
||||||
return cfg.active
|
return config.active
|
||||||
else:
|
else:
|
||||||
return False # pragma: no cover
|
return False # pragma: no cover
|
||||||
|
|
||||||
|
@ -342,10 +342,7 @@ class PluginsRegistry:
|
|||||||
if plugin.mixin_enabled(mixin):
|
if plugin.mixin_enabled(mixin):
|
||||||
|
|
||||||
if active is not None:
|
if active is not None:
|
||||||
# Filter by 'enabled' status
|
if active != plugin.is_active():
|
||||||
config = plugin.plugin_config()
|
|
||||||
|
|
||||||
if config.active != active:
|
|
||||||
continue
|
continue
|
||||||
|
|
||||||
result.append(plugin)
|
result.append(plugin)
|
||||||
@ -402,8 +399,14 @@ class PluginsRegistry:
|
|||||||
# Append reference to plugin
|
# Append reference to plugin
|
||||||
plg.db = plg_db
|
plg.db = plg_db
|
||||||
|
|
||||||
# Always activate if testing
|
# Check if this is a 'builtin' plugin
|
||||||
if settings.PLUGIN_TESTING or (plg_db and plg_db.active):
|
builtin = plg.check_is_builtin()
|
||||||
|
|
||||||
|
# Determine if this plugin should be loaded:
|
||||||
|
# - If PLUGIN_TESTING is enabled
|
||||||
|
# - If this is a 'builtin' plugin
|
||||||
|
# - If this plugin has been explicitly enabled by the user
|
||||||
|
if settings.PLUGIN_TESTING or builtin or (plg_db and plg_db.active):
|
||||||
# Check if the plugin was blocked -> threw an error; option1: package, option2: file-based
|
# Check if the plugin was blocked -> threw an error; option1: package, option2: file-based
|
||||||
if disabled and ((plg.__name__ == disabled) or (plg.__module__ == disabled)):
|
if disabled and ((plg.__name__ == disabled) or (plg.__module__ == disabled)):
|
||||||
safe_reference(plugin=plg, key=plg_key, active=False)
|
safe_reference(plugin=plg, key=plg_key, active=False)
|
||||||
@ -497,10 +500,9 @@ class PluginsRegistry:
|
|||||||
for _key, plugin in plugins:
|
for _key, plugin in plugins:
|
||||||
|
|
||||||
if plugin.mixin_enabled('schedule'):
|
if plugin.mixin_enabled('schedule'):
|
||||||
config = plugin.plugin_config()
|
|
||||||
|
|
||||||
# Only active tasks for plugins which are enabled
|
if plugin.is_active():
|
||||||
if config and config.active:
|
# Only active tasks for plugins which are enabled
|
||||||
plugin.register_tasks()
|
plugin.register_tasks()
|
||||||
task_keys += plugin.get_task_names()
|
task_keys += plugin.get_task_names()
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user