2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-06-16 03:55:41 +00:00

Only load plugins if PLUGINS_ENABLED is true

- Hide plugin settings
- Add plugin support status to "stats" dialog
This commit is contained in:
Oliver
2022-01-11 13:39:47 +11:00
parent 31df4eae83
commit 8aec055e6c
7 changed files with 68 additions and 15 deletions

View File

@ -1,21 +1,32 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
import logging
from django.apps import AppConfig
from django.conf import settings
from maintenance_mode.core import set_maintenance_mode
from plugin import plugin_registry
logger = logging.getLogger('inventree')
class PluginAppConfig(AppConfig):
name = 'plugin'
def ready(self):
if not plugin_registry.is_loading:
# this is the first startup
plugin_registry.collect_plugins()
plugin_registry.load_plugins()
# drop out of maintenance
# makes sure we did not have an error in reloading and maintenance is still active
set_maintenance_mode(False)
if settings.PLUGINS_ENABLED:
logger.info('Loading InvenTree plugins')
if not plugin_registry.is_loading:
# this is the first startup
plugin_registry.collect_plugins()
plugin_registry.load_plugins()
# drop out of maintenance
# makes sure we did not have an error in reloading and maintenance is still active
set_maintenance_mode(False)

View File

@ -31,6 +31,10 @@ def trigger_event(event, *args, **kwargs):
and the worker will respond to it later on.
"""
if not settings.PLUGINS_ENABLED:
# Do nothing if plugins are not enabled
return
if not canAppAccessDatabase():
logger.debug(f"Ignoring triggered event '{event}' - database not ready")
return

View File

@ -66,6 +66,10 @@ class PluginsRegistry:
Load and activate all IntegrationPlugins
"""
if not settings.PLUGINS_ENABLED:
# Plugins not enabled, do nothing
return
from plugin.helpers import log_plugin_error
logger.info('Start loading plugins')
@ -75,15 +79,16 @@ class PluginsRegistry:
if not _maintenance:
set_maintenance_mode(True)
registered_sucessfull = False
registered_successful = False
blocked_plugin = None
retry_counter = settings.PLUGIN_RETRY
while not registered_sucessfull:
while not registered_successful:
try:
# We are using the db so for migrations etc we need to try this block
self._init_plugins(blocked_plugin)
self._activate_plugins()
registered_sucessfull = True
registered_successful = True
except (OperationalError, ProgrammingError):
# Exception if the database has not been migrated yet
logger.info('Database not accessible while loading plugins')
@ -122,6 +127,10 @@ class PluginsRegistry:
Unload and deactivate all IntegrationPlugins
"""
if not settings.PLUGINS_ENABLED:
# Plugins not enabled, do nothing
return
logger.info('Start unloading plugins')
# Set maintanace mode
@ -162,6 +171,10 @@ class PluginsRegistry:
Collect integration plugins from all possible ways of loading
"""
if not settings.PLUGINS_ENABLED:
# Plugins not enabled, do nothing
return
self.plugin_modules = [] # clear
# Collect plugins from paths