mirror of
https://github.com/inventree/InvenTree.git
synced 2025-06-17 12:35:46 +00:00
Disable panel return if plugin integration is not enabled
This commit is contained in:
@ -17,6 +17,7 @@ from rest_framework.views import APIView
|
|||||||
|
|
||||||
import plugin.serializers as PluginSerializers
|
import plugin.serializers as PluginSerializers
|
||||||
from common.api import GlobalSettingsPermissions
|
from common.api import GlobalSettingsPermissions
|
||||||
|
from common.settings import get_global_setting
|
||||||
from InvenTree.api import MetadataView
|
from InvenTree.api import MetadataView
|
||||||
from InvenTree.filters import SEARCH_ORDER_FILTER
|
from InvenTree.filters import SEARCH_ORDER_FILTER
|
||||||
from InvenTree.mixins import (
|
from InvenTree.mixins import (
|
||||||
@ -429,53 +430,56 @@ class PluginPanelList(APIView):
|
|||||||
|
|
||||||
panels = []
|
panels = []
|
||||||
|
|
||||||
# Extract all plugins from the registry which provide custom panels
|
if get_global_setting('ENABLE_PLUGINS_INTERFACE'):
|
||||||
for _plugin in registry.with_mixin('ui', active=True):
|
# Extract all plugins from the registry which provide custom panels
|
||||||
# Allow plugins to fill this data out
|
for _plugin in registry.with_mixin('ui', active=True):
|
||||||
plugin_panels = _plugin.get_custom_panels(target_model, target_id, request)
|
# Allow plugins to fill this data out
|
||||||
|
plugin_panels = _plugin.get_custom_panels(
|
||||||
|
target_model, target_id, request
|
||||||
|
)
|
||||||
|
|
||||||
if plugin_panels and type(plugin_panels) is list:
|
if plugin_panels and type(plugin_panels) is list:
|
||||||
for panel in plugin_panels:
|
for panel in plugin_panels:
|
||||||
# TODO: Validate each panel before inserting
|
# TODO: Validate each panel before inserting
|
||||||
panels.append(panel)
|
panels.append(panel)
|
||||||
|
|
||||||
if target_model == 'part' and target_id:
|
if target_model == 'part' and target_id:
|
||||||
panels = [
|
panels = [
|
||||||
*panels,
|
*panels,
|
||||||
{
|
{
|
||||||
'plugin': 'myplugin',
|
'plugin': 'myplugin',
|
||||||
'name': 'test-plugin',
|
'name': 'test-plugin',
|
||||||
'label': 'My Plugin',
|
'label': 'My Plugin',
|
||||||
'icon': 'part',
|
'icon': 'part',
|
||||||
'content': '<div>hello world</div>',
|
'content': '<div>hello world</div>',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
'plugin': 'myplugin',
|
'plugin': 'myplugin',
|
||||||
'name': 'test-plugin-2',
|
'name': 'test-plugin-2',
|
||||||
'label': 'My Plugin 2',
|
'label': 'My Plugin 2',
|
||||||
'icon': 'email',
|
'icon': 'email',
|
||||||
'content': '<div>hello world 2</div>',
|
'content': '<div>hello world 2</div>',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
'plugin': 'myplugin',
|
'plugin': 'myplugin',
|
||||||
'name': 'test-plugin-3',
|
'name': 'test-plugin-3',
|
||||||
'label': 'My Plugin 3',
|
'label': 'My Plugin 3',
|
||||||
'icon': 'website',
|
'icon': 'website',
|
||||||
'content': '<div>hello world 3</div>',
|
'content': '<div>hello world 3</div>',
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
|
||||||
if target_model == 'partcategory':
|
if target_model == 'partcategory':
|
||||||
panels = [
|
panels = [
|
||||||
*panels,
|
*panels,
|
||||||
{
|
{
|
||||||
'plugin': 'cat',
|
'plugin': 'cat',
|
||||||
'name': 'demo-cat',
|
'name': 'demo-cat',
|
||||||
'label': 'Custom Category',
|
'label': 'Custom Category',
|
||||||
'icon': 'customer',
|
'icon': 'customer',
|
||||||
'content': 'This should only appear for a category',
|
'content': 'This should only appear for a category',
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
|
||||||
return Response(PluginSerializers.PluginPanelSerializer(panels, many=True).data)
|
return Response(PluginSerializers.PluginPanelSerializer(panels, many=True).data)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user