Skip to content

Commit

Permalink
14728 Move installed plugins list from admin UI to NetBox UI (#14768)
Browse files Browse the repository at this point in the history
* 14728 move plugins view from admin

* 14728 move plugins view from admin

* 14728 remove plugins view from admin

* Update template for #12128

* 14728 review fixes

* 14728 review fixes

* 14728 review fixes

* 14728 review fixes

* 14728 configure table

* Clean up table columns

* Fix app config lookup for plugins referenced by dotted path

* Move template; fix table display

* Fix user table configuration

* Remove nonfunctional quick search

* Limit PluginListView to staff users

---------

Co-authored-by: Jeremy Stretch <[email protected]>
  • Loading branch information
arthanson and jeremystretch authored Jan 19, 2024
1 parent 073c2dc commit ef5e10d
Show file tree
Hide file tree
Showing 11 changed files with 118 additions and 74 deletions.
1 change: 1 addition & 0 deletions netbox/core/tables/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from .config import *
from .data import *
from .jobs import *
from .plugins import *
39 changes: 39 additions & 0 deletions netbox/core/tables/plugins.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import django_tables2 as tables
from django.utils.translation import gettext_lazy as _
from netbox.tables import BaseTable

__all__ = (
'PluginTable',
)


class PluginTable(BaseTable):
name = tables.Column(
accessor=tables.A('verbose_name'),
verbose_name=_('Name')
)
version = tables.Column(
verbose_name=_('Version')
)
package = tables.Column(
accessor=tables.A('name'),
verbose_name=_('Package')
)
author = tables.Column(
verbose_name=_('Author')
)
author_email = tables.Column(
verbose_name=_('Author Email')
)
description = tables.Column(
verbose_name=_('Description')
)

class Meta(BaseTable.Meta):
empty_text = _('No plugins found')
fields = (
'name', 'version', 'package', 'author', 'author_email', 'description',
)
default_columns = (
'name', 'version', 'package', 'author', 'author_email', 'description',
)
2 changes: 2 additions & 0 deletions netbox/core/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,6 @@
# Configuration
path('config/', views.ConfigView.as_view(), name='config'),

# Plugins
path('plugins/', views.PluginListView.as_view(), name='plugin_list'),
)
27 changes: 27 additions & 0 deletions netbox/core/views.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
from django.apps import apps
from django.conf import settings
from django.contrib import messages
from django.contrib.auth.mixins import UserPassesTestMixin
from django.core.cache import cache
from django.http import HttpResponseForbidden
from django.shortcuts import get_object_or_404, redirect, render
Expand Down Expand Up @@ -232,3 +235,27 @@ def post(self, request, pk):
messages.success(request, f"Restored configuration revision #{pk}")

return redirect(candidate_config.get_absolute_url())


#
# Plugins
#

class PluginListView(UserPassesTestMixin, View):

def test_func(self):
return self.request.user.is_staff

def get(self, request):
plugins = [
# Look up app config by package name
apps.get_app_config(plugin.rsplit('.', 1)[-1]) for plugin in settings.PLUGINS
]
table = tables.PluginTable(plugins, user=request.user)
table.configure(request)

return render(request, 'core/plugin_list.html', {
'plugins': plugins,
'active_tab': 'api-tokens',
'table': table,
})
2 changes: 2 additions & 0 deletions netbox/extras/views.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from django.apps import apps
from django.conf import settings
from django.contrib import messages
from django.contrib.auth.mixins import LoginRequiredMixin
from django.contrib.contenttypes.models import ContentType
Expand Down
10 changes: 10 additions & 0 deletions netbox/netbox/navigation/menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,16 @@
),
),
),
MenuGroup(
label=_('Plugins'),
items=(
MenuItem(
link='core:plugin_list',
link_text=_('Plugins'),
staff_only=True
),
),
),
),
)

Expand Down
3 changes: 0 additions & 3 deletions netbox/netbox/plugins/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@
path('', views.PluginsAPIRootView.as_view(), name='api-root'),
path('installed-plugins/', views.InstalledPluginsAPIView.as_view(), name='plugins-list')
]
plugin_admin_patterns = [
path('installed-plugins/', staff_member_required(views.InstalledPluginsAdminView.as_view()), name='plugins_list')
]

# Register base/API URL patterns for each plugin
for plugin_path in settings.PLUGINS:
Expand Down
11 changes: 0 additions & 11 deletions netbox/netbox/plugins/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,6 @@
from rest_framework.views import APIView


class InstalledPluginsAdminView(View):
"""
Admin view for listing all installed plugins
"""
def get(self, request):
plugins = [apps.get_app_config(plugin) for plugin in settings.PLUGINS]
return render(request, 'extras/admin/plugins_list.html', {
'plugins': plugins,
})


@extend_schema(exclude=True)
class InstalledPluginsAPIView(APIView):
"""
Expand Down
3 changes: 1 addition & 2 deletions netbox/netbox/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from netbox.api.views import APIRootView, StatusView
from netbox.graphql.schema import schema
from netbox.graphql.views import GraphQLView
from netbox.plugins.urls import plugin_admin_patterns, plugin_patterns, plugin_api_patterns
from netbox.plugins.urls import plugin_patterns, plugin_api_patterns
from netbox.views import HomeView, StaticMediaFailureView, SearchView, htmx
from .admin import admin_site

Expand Down Expand Up @@ -73,7 +73,6 @@

# Admin
path('admin/background-tasks/', include('django_rq.urls')),
path('admin/plugins/', include(plugin_admin_patterns)),
path('admin/', admin_site.urls),
]

Expand Down
36 changes: 36 additions & 0 deletions netbox/templates/core/plugin_list.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{% extends 'generic/_base.html' %}
{% load buttons %}
{% load helpers %}
{% load i18n %}
{% load render_table from django_tables2 %}

{% block title %}{% trans "Plugins" %}{% endblock %}

{% block tabs %}
<ul class="nav nav-tabs px-3">
<li class="nav-item" role="presentation">
<a class="nav-link active" role="tab">{% trans "Plugins" %}</a>
</li>
</ul>
{% endblock tabs %}

{% block content %}
<div class="row mb-3">
<div class="col-auto ms-auto d-print-none">
{# Table configuration button #}
<div class="table-configure input-group">
<button type="button" data-bs-toggle="modal" title="{% trans "Configure Table" %}" data-bs-target="#ObjectTable_config" class="btn">
<i class="mdi mdi-cog"></i> {% trans "Configure Table" %}
</button>
</div>
</div>
</div>

<div class="card">
{% render_table table %}
</div>
{% endblock content %}

{% block modals %}
{% table_config_form table table_name="ObjectTable" %}
{% endblock modals %}
58 changes: 0 additions & 58 deletions netbox/templates/extras/admin/plugins_list.html

This file was deleted.

0 comments on commit ef5e10d

Please sign in to comment.