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)
|
||||
|
||||
if plugin:
|
||||
config = plugin.plugin_config()
|
||||
|
||||
if config and config.active:
|
||||
if plugin.is_active():
|
||||
# Only return the plugin if it is enabled!
|
||||
return plugin
|
||||
else:
|
||||
|
@ -58,9 +58,8 @@ def register_event(event, *args, **kwargs):
|
||||
|
||||
if plugin.mixin_enabled('events'):
|
||||
|
||||
config = plugin.plugin_config()
|
||||
|
||||
if config and config.active:
|
||||
if plugin.is_active():
|
||||
# Only allow event registering for 'active' plugins
|
||||
|
||||
logger.debug(f"Registering callback for plugin '{slug}'")
|
||||
|
||||
|
@ -9,6 +9,8 @@ references model objects actually exist in the database.
|
||||
|
||||
import json
|
||||
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
from company.models import SupplierPart
|
||||
from InvenTree.helpers import hash_barcode
|
||||
from part.models import Part
|
||||
@ -64,6 +66,8 @@ class InvenTreeInternalBarcodePlugin(InvenTreeBarcodePlugin):
|
||||
|
||||
NAME = "InvenTreeInternalBarcode"
|
||||
TITLE = "Inventree Barcodes"
|
||||
VERSION = "2.0"
|
||||
AUTHOR = _("InvenTree contributors")
|
||||
|
||||
def scan(self, barcode_data):
|
||||
"""Scan a barcode against this plugin.
|
||||
|
@ -111,10 +111,10 @@ class MetaBase:
|
||||
if self.is_builtin:
|
||||
return True
|
||||
|
||||
cfg = self.plugin_config()
|
||||
config = self.plugin_config()
|
||||
|
||||
if cfg:
|
||||
return cfg.active
|
||||
if config:
|
||||
return config.active
|
||||
else:
|
||||
return False # pragma: no cover
|
||||
|
||||
|
@ -342,10 +342,7 @@ class PluginsRegistry:
|
||||
if plugin.mixin_enabled(mixin):
|
||||
|
||||
if active is not None:
|
||||
# Filter by 'enabled' status
|
||||
config = plugin.plugin_config()
|
||||
|
||||
if config.active != active:
|
||||
if active != plugin.is_active():
|
||||
continue
|
||||
|
||||
result.append(plugin)
|
||||
@ -402,8 +399,14 @@ class PluginsRegistry:
|
||||
# Append reference to plugin
|
||||
plg.db = plg_db
|
||||
|
||||
# Always activate if testing
|
||||
if settings.PLUGIN_TESTING or (plg_db and plg_db.active):
|
||||
# Check if this is a 'builtin' plugin
|
||||
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
|
||||
if disabled and ((plg.__name__ == disabled) or (plg.__module__ == disabled)):
|
||||
safe_reference(plugin=plg, key=plg_key, active=False)
|
||||
@ -497,10 +500,9 @@ class PluginsRegistry:
|
||||
for _key, plugin in plugins:
|
||||
|
||||
if plugin.mixin_enabled('schedule'):
|
||||
config = plugin.plugin_config()
|
||||
|
||||
if plugin.is_active():
|
||||
# Only active tasks for plugins which are enabled
|
||||
if config and config.active:
|
||||
plugin.register_tasks()
|
||||
task_keys += plugin.get_task_names()
|
||||
|
||||
|
Reference in New Issue
Block a user