From e8ae6410cea0ddccde2588babb5ffd018a71d04b Mon Sep 17 00:00:00 2001
From: Oliver Walters <oliver.henry.walters@gmail.com>
Date: Sun, 11 Aug 2024 06:25:48 +0000
Subject: [PATCH] Disable panel return if plugin integration is not enabled

---
 src/backend/InvenTree/plugin/api.py | 92 +++++++++++++++--------------
 1 file changed, 48 insertions(+), 44 deletions(-)

diff --git a/src/backend/InvenTree/plugin/api.py b/src/backend/InvenTree/plugin/api.py
index 6cf51cc60f..9d74f024ab 100644
--- a/src/backend/InvenTree/plugin/api.py
+++ b/src/backend/InvenTree/plugin/api.py
@@ -17,6 +17,7 @@ from rest_framework.views import APIView
 
 import plugin.serializers as PluginSerializers
 from common.api import GlobalSettingsPermissions
+from common.settings import get_global_setting
 from InvenTree.api import MetadataView
 from InvenTree.filters import SEARCH_ORDER_FILTER
 from InvenTree.mixins import (
@@ -429,53 +430,56 @@ class PluginPanelList(APIView):
 
         panels = []
 
-        # Extract all plugins from the registry which provide custom panels
-        for _plugin in registry.with_mixin('ui', active=True):
-            # Allow plugins to fill this data out
-            plugin_panels = _plugin.get_custom_panels(target_model, target_id, request)
+        if get_global_setting('ENABLE_PLUGINS_INTERFACE'):
+            # Extract all plugins from the registry which provide custom panels
+            for _plugin in registry.with_mixin('ui', active=True):
+                # 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:
-                for panel in plugin_panels:
-                    # TODO: Validate each panel before inserting
-                    panels.append(panel)
+                if plugin_panels and type(plugin_panels) is list:
+                    for panel in plugin_panels:
+                        # TODO: Validate each panel before inserting
+                        panels.append(panel)
 
-        if target_model == 'part' and target_id:
-            panels = [
-                *panels,
-                {
-                    'plugin': 'myplugin',
-                    'name': 'test-plugin',
-                    'label': 'My Plugin',
-                    'icon': 'part',
-                    'content': '<div>hello world</div>',
-                },
-                {
-                    'plugin': 'myplugin',
-                    'name': 'test-plugin-2',
-                    'label': 'My Plugin 2',
-                    'icon': 'email',
-                    'content': '<div>hello world 2</div>',
-                },
-                {
-                    'plugin': 'myplugin',
-                    'name': 'test-plugin-3',
-                    'label': 'My Plugin 3',
-                    'icon': 'website',
-                    'content': '<div>hello world 3</div>',
-                },
-            ]
+            if target_model == 'part' and target_id:
+                panels = [
+                    *panels,
+                    {
+                        'plugin': 'myplugin',
+                        'name': 'test-plugin',
+                        'label': 'My Plugin',
+                        'icon': 'part',
+                        'content': '<div>hello world</div>',
+                    },
+                    {
+                        'plugin': 'myplugin',
+                        'name': 'test-plugin-2',
+                        'label': 'My Plugin 2',
+                        'icon': 'email',
+                        'content': '<div>hello world 2</div>',
+                    },
+                    {
+                        'plugin': 'myplugin',
+                        'name': 'test-plugin-3',
+                        'label': 'My Plugin 3',
+                        'icon': 'website',
+                        'content': '<div>hello world 3</div>',
+                    },
+                ]
 
-        if target_model == 'partcategory':
-            panels = [
-                *panels,
-                {
-                    'plugin': 'cat',
-                    'name': 'demo-cat',
-                    'label': 'Custom Category',
-                    'icon': 'customer',
-                    'content': 'This should only appear for a category',
-                },
-            ]
+            if target_model == 'partcategory':
+                panels = [
+                    *panels,
+                    {
+                        'plugin': 'cat',
+                        'name': 'demo-cat',
+                        'label': 'Custom Category',
+                        'icon': 'customer',
+                        'content': 'This should only appear for a category',
+                    },
+                ]
 
         return Response(PluginSerializers.PluginPanelSerializer(panels, many=True).data)