mirror of
				https://github.com/inventree/InvenTree.git
				synced 2025-10-31 05:05:42 +00:00 
			
		
		
		
	check if plugin is enabled
This commit is contained in:
		| @@ -22,6 +22,7 @@ class PluginConfig(AppConfig): | |||||||
|  |  | ||||||
|     def ready(self): |     def ready(self): | ||||||
|         from common.models import InvenTreeSetting |         from common.models import InvenTreeSetting | ||||||
|  |         from plugin.models import PluginConfig | ||||||
|  |  | ||||||
|         # Collect plugins from paths |         # Collect plugins from paths | ||||||
|         for plugin in settings.PLUGIN_DIRS: |         for plugin in settings.PLUGIN_DIRS: | ||||||
| @@ -40,12 +41,20 @@ class PluginConfig(AppConfig): | |||||||
|             # check if package |             # check if package | ||||||
|             was_packaged = getattr(plugin, 'is_package', False) |             was_packaged = getattr(plugin, 'is_package', False) | ||||||
|  |  | ||||||
|             # init package |             # check if activated | ||||||
|             plugin.is_package = was_packaged |             # these checks only use attributes - never use plugin supplied functions -> that would lead to arbitrary code execution!! | ||||||
|             plugin = plugin() |             plug_name = plugin.PLUGIN_NAME | ||||||
|             plugin.is_package = was_packaged |             plug_key = plugin.PLUGIN_SLUG if getattr(plugin, 'PLUGIN_SLUG', None) else plug_name | ||||||
|             # safe reference |             plugin_db_setting, _ = PluginConfig.objects.get_or_create(key=plug_key, name=plug_name) | ||||||
|             settings.INTEGRATION_PLUGINS[plugin.slug] = plugin |  | ||||||
|  |             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. | ||||||
|  |                 plugin = plugin() | ||||||
|  |                 plugin.is_package = was_packaged | ||||||
|  |                 # safe reference | ||||||
|  |                 settings.INTEGRATION_PLUGINS[plugin.slug] = plugin | ||||||
|  |  | ||||||
|         # activate integrations |         # activate integrations | ||||||
|         plugins = settings.INTEGRATION_PLUGINS.items() |         plugins = settings.INTEGRATION_PLUGINS.items() | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user