2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-05-01 13:06:45 +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

@ -7,6 +7,7 @@ over and above the built-in Django tags.
import os import os
import sys import sys
import django
from django.utils.html import format_html from django.utils.html import format_html
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
@ -107,6 +108,13 @@ def inventree_docker_mode(*args, **kwargs):
return djangosettings.DOCKER return djangosettings.DOCKER
@register.simple_tag()
def plugins_enabled(*args, **kwargs):
""" Return True if plugins are enabled for the server instance """
return djangosettings.PLUGINS_ENABLED
@register.simple_tag() @register.simple_tag()
def inventree_db_engine(*args, **kwargs): def inventree_db_engine(*args, **kwargs):
""" Return the InvenTree database backend e.g. 'postgresql' """ """ Return the InvenTree database backend e.g. 'postgresql' """

View File

@ -1,16 +1,27 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from __future__ import unicode_literals from __future__ import unicode_literals
import logging
from django.apps import AppConfig from django.apps import AppConfig
from django.conf import settings
from maintenance_mode.core import set_maintenance_mode from maintenance_mode.core import set_maintenance_mode
from plugin import plugin_registry from plugin import plugin_registry
logger = logging.getLogger('inventree')
class PluginAppConfig(AppConfig): class PluginAppConfig(AppConfig):
name = 'plugin' name = 'plugin'
def ready(self): def ready(self):
if settings.PLUGINS_ENABLED:
logger.info('Loading InvenTree plugins')
if not plugin_registry.is_loading: if not plugin_registry.is_loading:
# this is the first startup # this is the first startup
plugin_registry.collect_plugins() plugin_registry.collect_plugins()

View File

@ -31,6 +31,10 @@ def trigger_event(event, *args, **kwargs):
and the worker will respond to it later on. 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(): if not canAppAccessDatabase():
logger.debug(f"Ignoring triggered event '{event}' - database not ready") logger.debug(f"Ignoring triggered event '{event}' - database not ready")
return return

View File

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

View File

@ -39,14 +39,16 @@
{% include "InvenTree/settings/build.html" %} {% include "InvenTree/settings/build.html" %}
{% include "InvenTree/settings/po.html" %} {% include "InvenTree/settings/po.html" %}
{% include "InvenTree/settings/so.html" %} {% include "InvenTree/settings/so.html" %}
{% include "InvenTree/settings/plugin.html" %}
{% if plugins_enabled %}
{% include "InvenTree/settings/plugin.html" %}
{% plugin_list as pl_list %} {% plugin_list as pl_list %}
{% for plugin_key, plugin in pl_list.items %} {% for plugin_key, plugin in pl_list.items %}
{% if plugin.registered_mixins %} {% if plugin.registered_mixins %}
{% include "InvenTree/settings/plugin_settings.html" %} {% include "InvenTree/settings/plugin_settings.html" %}
{% endif %} {% endif %}
{% endfor %} {% endfor %}
{% endif %}
{% endif %} {% endif %}
@ -333,9 +335,11 @@ $("#import-part").click(function() {
launchModalForm("{% url 'api-part-import' %}?reset", {}); launchModalForm("{% url 'api-part-import' %}?reset", {});
}); });
{% if plugins_enabled %}
$("#install-plugin").click(function() { $("#install-plugin").click(function() {
installPlugin(); installPlugin();
}); });
{% endif %}
enableSidebar('settings'); enableSidebar('settings');

View File

@ -47,15 +47,16 @@
{% trans "Sales Orders" as text %} {% trans "Sales Orders" as text %}
{% include "sidebar_item.html" with label='sales-order' text=text icon="fa-truck" %} {% include "sidebar_item.html" with label='sales-order' text=text icon="fa-truck" %}
{% if plugins_enabled %}
{% include "sidebar_header.html" with text="Plugin Settings" %} {% include "sidebar_header.html" with text="Plugin Settings" %}
{% include "sidebar_item.html" with label='plugin' text="Plugins" icon="fa-plug" %} {% include "sidebar_item.html" with label='plugin' text="Plugins" icon="fa-plug" %}
{% plugin_list as pl_list %} {% plugin_list as pl_list %}
{% for plugin_key, plugin in pl_list.items %} {% for plugin_key, plugin in pl_list.items %}
{% if plugin.registered_mixins %} {% if plugin.registered_mixins %}
{% include "sidebar_item.html" with label='plugin-'|add:plugin_key text=plugin.human_name %} {% include "sidebar_item.html" with label='plugin-'|add:plugin_key text=plugin.human_name %}
{% endif %} {% endif %}
{% endfor %} {% endfor %}
{% endif %}
{% endif %} {% endif %}

View File

@ -34,6 +34,18 @@
<td>{% trans "Server is deployed using docker" %}</td> <td>{% trans "Server is deployed using docker" %}</td>
</tr> </tr>
{% endif %} {% endif %}
<tr>
<td><span class='fas fa-plug'></span></td>
<td>{% trans "Plugin Support" %}</td>
<td>
{% plugins_enabled as p_en %}
{% if p_en %}
<span class='badge rounded-pill bg-success'>{% trans "Plugin support enabled" %}</span>
{% else %}
<span class='badge rounded-pill bg-warning'>{% trans "Plugin support disabled" %}</span>
{% endif %}
</td>
</tr>
{% if user.is_staff %} {% if user.is_staff %}
<tr> <tr>
<td><span class='fas fa-server'></span></td> <td><span class='fas fa-server'></span></td>