From 076d16ca6b782d380b2d6007a33c46622f645122 Mon Sep 17 00:00:00 2001 From: Arthur Hanson Date: Wed, 9 Apr 2025 05:02:38 -0700 Subject: [PATCH] 19073 allow plugins to be marked as hidden or disabled in plugins table (#19087) * 19073 allow plugins to be marked as hidden or disabled in plugins table * 19073 allow plugins to be marked as hidden or disabled in plugins table * 19073 allow plugins to be marked as hidden or disabled in plugins table * 19073 review changes * Rename 'unlinked' to 'static' & update docs --------- Co-authored-by: Jeremy Stretch --- docs/configuration/plugins.md | 18 ++++++++++++++++++ netbox/core/plugins.py | 7 +++++++ netbox/core/tables/plugins.py | 11 +++++++++-- netbox/core/views.py | 2 ++ netbox/netbox/settings.py | 1 + 5 files changed, 37 insertions(+), 2 deletions(-) diff --git a/docs/configuration/plugins.md b/docs/configuration/plugins.md index a3e691f63..765c3d50f 100644 --- a/docs/configuration/plugins.md +++ b/docs/configuration/plugins.md @@ -33,3 +33,21 @@ Note that a plugin must be listed in `PLUGINS` for its configuration to take eff --- +## PLUGINS_CATALOG_CONFIG + +Default: Empty + +This parameter controls how individual plugins are displayed in the plugins catalog under Admin > System > Plugins. Adding a plugin to the `hidden` list will omit that plugin from the catalog. Adding a plugin to the `static` list will display the plugin, but not link to the plugin details or upgrade instructions. + +An example configuration is shown below: + +```python +PLUGINS_CATALOG_CONFIG = { + 'hidden': [ + 'plugin1', + ], + 'static': [ + 'plugin2', + ], +} +``` diff --git a/netbox/core/plugins.py b/netbox/core/plugins.py index e4d14b810..42930bbc8 100644 --- a/netbox/core/plugins.py +++ b/netbox/core/plugins.py @@ -109,6 +109,13 @@ def get_local_plugins(plugins=None): else: plugins[k] = v + # Update plugin table config for hidden and static plugins + hidden = settings.PLUGINS_CATALOG_CONFIG.get('hidden', []) + static = settings.PLUGINS_CATALOG_CONFIG.get('static', []) + for k, v in plugins.items(): + v.hidden = k in hidden + v.static = k in static + return plugins diff --git a/netbox/core/tables/plugins.py b/netbox/core/tables/plugins.py index a7773b4de..20bd0eee6 100644 --- a/netbox/core/tables/plugins.py +++ b/netbox/core/tables/plugins.py @@ -1,4 +1,6 @@ import django_tables2 as tables +from django.urls import reverse +from django.utils.safestring import mark_safe from django.utils.translation import gettext_lazy as _ from netbox.tables import BaseTable, columns @@ -41,8 +43,7 @@ class PluginVersionTable(BaseTable): class CatalogPluginTable(BaseTable): title_long = tables.Column( - linkify=('core:plugin', [tables.A('config_name')]), - verbose_name=_('Name') + verbose_name=_('Name'), ) author = tables.Column( accessor=tables.A('author__name'), @@ -86,3 +87,9 @@ class CatalogPluginTable(BaseTable): # List installed plugins first, then certified plugins, then # everything else (with each tranche ordered alphabetically) order_by = ('-is_installed', '-is_certified', 'name') + + def render_title_long(self, value, record): + if record.static: + return value + url = reverse('core:plugin', args=[record.config_name]) + return mark_safe(f"{value}") diff --git a/netbox/core/views.py b/netbox/core/views.py index 1f8bff923..c63aa3f81 100644 --- a/netbox/core/views.py +++ b/netbox/core/views.py @@ -613,6 +613,8 @@ class PluginListView(BasePluginView): if q: plugins = [obj for obj in plugins if q.casefold() in obj.title_short.casefold()] + plugins = [plugin for plugin in plugins if not plugin.hidden] + table = CatalogPluginTable(plugins, user=request.user) table.configure(request) diff --git a/netbox/netbox/settings.py b/netbox/netbox/settings.py index 43dcaeed2..c453817d0 100644 --- a/netbox/netbox/settings.py +++ b/netbox/netbox/settings.py @@ -141,6 +141,7 @@ MEDIA_ROOT = getattr(configuration, 'MEDIA_ROOT', os.path.join(BASE_DIR, 'media' METRICS_ENABLED = getattr(configuration, 'METRICS_ENABLED', False) PLUGINS = getattr(configuration, 'PLUGINS', []) PLUGINS_CONFIG = getattr(configuration, 'PLUGINS_CONFIG', {}) +PLUGINS_CATALOG_CONFIG = getattr(configuration, 'PLUGINS_CATALOG_CONFIG', {}) PROXY_ROUTERS = getattr(configuration, 'PROXY_ROUTERS', ['utilities.proxy.DefaultProxyRouter']) QUEUE_MAPPINGS = getattr(configuration, 'QUEUE_MAPPINGS', {}) REDIS = getattr(configuration, 'REDIS') # Required