This commit is contained in:
Matthias 2021-11-12 02:39:06 +01:00
parent 9ae8474ed9
commit da7dd0a4ac
No known key found for this signature in database
GPG Key ID: F50EF5741D33E076

View File

@ -57,29 +57,30 @@ class PluginAppConfig(AppConfig):
from plugin.models import PluginConfig
logger.info('Starting plugin initialisation')
# Initialize integration plugins
# Initialize integration plugins
for plugin in inventree_plugins.load_integration_plugins():
# check if package
# check if package
was_packaged = getattr(plugin, 'is_package', False)
# check if activated
# these checks only use attributes - never use plugin supplied functions -> that would lead to arbitrary code execution!!
# 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
plugin_db_setting, _ = PluginConfig.objects.get_or_create(key=plug_key, name=plug_name)
if plugin_db_setting.active:
# init package
# now we can be sure that an admin has activated the plugin -> 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.
# init package
# now we can be sure that an admin has activated the plugin -> 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}')
plugin = plugin()
logger.info(f'Loaded integration plugin {plugin.slug}')
plugin.is_package = was_packaged
# safe reference
# safe reference
settings.INTEGRATION_PLUGINS[plugin.slug] = plugin
else:
# save for later reference
# save for later reference
settings.INTEGRATION_PLUGINS_INACTIVE[plug_key] = plugin_db_setting
def activate_integration(self):
@ -115,21 +116,21 @@ class PluginAppConfig(AppConfig):
settings.INTEGRATION_APPS_LOADED = True # ensure this section will not run again
apps_changed = False
# add them to the INSTALLED_APPS
# add them to the INSTALLED_APPS
for slug, plugin in plugins:
if plugin.mixin_enabled('app'):
try:
# for local path plugins
# for local path plugins
plugin_path = '.'.join(pathlib.Path(plugin.path).relative_to(settings.BASE_DIR).parts)
except ValueError:
# plugin is shipped as package
# plugin is shipped as package
plugin_path = plugin.PLUGIN_NAME
if plugin_path not in settings.INSTALLED_APPS:
settings.INSTALLED_APPS += [plugin_path]
apps_changed = True
# if apps were changed reload
# TODO this is a bit jankey to be honest
# if apps were changed reload
# TODO this is a bit jankey to be honest
if apps_changed:
apps.app_configs = OrderedDict()
apps.apps_ready = apps.models_ready = apps.loading = apps.ready = False