mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
* Disable the Django admin UI by default * Remove outdated references to the admin UI * Update tests
This commit is contained in:
@@ -39,6 +39,8 @@ REDIS = {
|
||||
|
||||
SECRET_KEY = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'
|
||||
|
||||
DJANGO_ADMIN_ENABLED = True
|
||||
|
||||
DEFAULT_PERMISSIONS = {}
|
||||
|
||||
LOGGING = {
|
||||
|
||||
@@ -115,6 +115,7 @@ DEFAULT_PERMISSIONS = getattr(configuration, 'DEFAULT_PERMISSIONS', {
|
||||
'users.delete_token': ({'user': '$user'},),
|
||||
})
|
||||
DEVELOPER = getattr(configuration, 'DEVELOPER', False)
|
||||
DJANGO_ADMIN_ENABLED = getattr(configuration, 'DJANGO_ADMIN_ENABLED', False)
|
||||
DOCS_ROOT = getattr(configuration, 'DOCS_ROOT', os.path.join(os.path.dirname(BASE_DIR), 'docs'))
|
||||
EMAIL = getattr(configuration, 'EMAIL', {})
|
||||
EVENTS_PIPELINE = getattr(configuration, 'EVENTS_PIPELINE', (
|
||||
@@ -355,7 +356,6 @@ SERVER_EMAIL = EMAIL.get('FROM_EMAIL')
|
||||
#
|
||||
|
||||
INSTALLED_APPS = [
|
||||
'django.contrib.admin',
|
||||
'django.contrib.auth',
|
||||
'django.contrib.contenttypes',
|
||||
'django.contrib.sessions',
|
||||
@@ -393,6 +393,9 @@ INSTALLED_APPS = [
|
||||
'drf_spectacular_sidecar',
|
||||
]
|
||||
|
||||
if DJANGO_ADMIN_ENABLED:
|
||||
INSTALLED_APPS.insert(0, 'django.contrib.admin')
|
||||
|
||||
# Middleware
|
||||
MIDDLEWARE = [
|
||||
'graphiql_debug_toolbar.middleware.DebugToolbarMiddleware',
|
||||
|
||||
@@ -4,23 +4,23 @@ from netbox.plugins.navigation import PluginMenu, PluginMenuButton, PluginMenuIt
|
||||
|
||||
items = (
|
||||
PluginMenuItem(
|
||||
link='plugins:dummy_plugin:dummy_models',
|
||||
link='plugins:dummy_plugin:dummy_model_list',
|
||||
link_text='Item 1',
|
||||
buttons=(
|
||||
PluginMenuButton(
|
||||
link='admin:dummy_plugin_dummymodel_add',
|
||||
title='Add a new dummy model',
|
||||
link='plugins:dummy_plugin:dummy_model_add',
|
||||
title='Button 1',
|
||||
icon_class='mdi mdi-plus-thick',
|
||||
),
|
||||
PluginMenuButton(
|
||||
link='admin:dummy_plugin_dummymodel_add',
|
||||
title='Add a new dummy model',
|
||||
link='plugins:dummy_plugin:dummy_model_add',
|
||||
title='Button 2',
|
||||
icon_class='mdi mdi-plus-thick',
|
||||
),
|
||||
)
|
||||
),
|
||||
PluginMenuItem(
|
||||
link='plugins:dummy_plugin:dummy_models',
|
||||
link='plugins:dummy_plugin:dummy_model_list',
|
||||
link_text='Item 2',
|
||||
),
|
||||
)
|
||||
|
||||
@@ -4,5 +4,6 @@ from . import views
|
||||
|
||||
|
||||
urlpatterns = (
|
||||
path('models/', views.DummyModelsView.as_view(), name='dummy_models'),
|
||||
path('models/', views.DummyModelsView.as_view(), name='dummy_model_list'),
|
||||
path('models/add/', views.DummyModelAddView.as_view(), name='dummy_model_add'),
|
||||
)
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
import random
|
||||
import string
|
||||
|
||||
from django.http import HttpResponse
|
||||
from django.views.generic import View
|
||||
|
||||
@@ -15,6 +18,20 @@ class DummyModelsView(View):
|
||||
return HttpResponse(f"Instances: {instance_count}")
|
||||
|
||||
|
||||
class DummyModelAddView(View):
|
||||
|
||||
def get(self, request):
|
||||
return HttpResponse(f"Create an instance")
|
||||
|
||||
def post(self, request):
|
||||
instance = DummyModel(
|
||||
name=''.join(random.choices(string.ascii_lowercase, k=8)),
|
||||
number=random.randint(1, 100000)
|
||||
)
|
||||
instance.save()
|
||||
return HttpResponse(f"Instance created")
|
||||
|
||||
|
||||
@register_model_view(Site, 'extra', path='other-stuff')
|
||||
class ExtraCoreModelView(View):
|
||||
|
||||
|
||||
@@ -41,7 +41,7 @@ class PluginTest(TestCase):
|
||||
def test_views(self):
|
||||
|
||||
# Test URL resolution
|
||||
url = reverse('plugins:dummy_plugin:dummy_models')
|
||||
url = reverse('plugins:dummy_plugin:dummy_model_list')
|
||||
self.assertEqual(url, '/plugins/dummy-plugin/models/')
|
||||
|
||||
# Test GET request
|
||||
|
||||
@@ -11,7 +11,6 @@ from netbox.graphql.schema import schema
|
||||
from netbox.graphql.views import GraphQLView
|
||||
from netbox.plugins.urls import plugin_patterns, plugin_api_patterns
|
||||
from netbox.views import HomeView, StaticMediaFailureView, SearchView, htmx
|
||||
from .admin import admin_site
|
||||
|
||||
_patterns = [
|
||||
|
||||
@@ -70,26 +69,25 @@ _patterns = [
|
||||
# Plugins
|
||||
path('plugins/', include((plugin_patterns, 'plugins'))),
|
||||
path('api/plugins/', include((plugin_api_patterns, 'plugins-api'))),
|
||||
|
||||
# Admin
|
||||
path('admin/', admin_site.urls),
|
||||
]
|
||||
|
||||
# Django admin UI
|
||||
if settings.DJANGO_ADMIN_ENABLED:
|
||||
from .admin import admin_site
|
||||
_patterns.append(path('admin/', admin_site.urls))
|
||||
|
||||
# django-debug-toolbar
|
||||
if settings.DEBUG:
|
||||
import debug_toolbar
|
||||
_patterns += [
|
||||
path('__debug__/', include(debug_toolbar.urls)),
|
||||
]
|
||||
_patterns.append(path('__debug__/', include(debug_toolbar.urls)))
|
||||
|
||||
# Prometheus metrics
|
||||
if settings.METRICS_ENABLED:
|
||||
_patterns += [
|
||||
path('', include('django_prometheus.urls')),
|
||||
]
|
||||
_patterns.append(path('', include('django_prometheus.urls')))
|
||||
|
||||
# Prepend BASE_PATH
|
||||
urlpatterns = [
|
||||
path('{}'.format(settings.BASE_PATH), include(_patterns))
|
||||
path(settings.BASE_PATH, include(_patterns))
|
||||
]
|
||||
|
||||
handler404 = 'netbox.views.errors.handler_404'
|
||||
|
||||
@@ -38,7 +38,7 @@
|
||||
<td>{% checkmark request.user.is_superuser %}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">{% trans "Admin Access" %}</th>
|
||||
<th scope="row">{% trans "Staff" %}</th>
|
||||
<td>{% checkmark request.user.is_staff %}</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
@@ -45,7 +45,11 @@
|
||||
<td>{{ param }}</td>
|
||||
<td>{{ current }}</td>
|
||||
<td>{{ new }}</td>
|
||||
<td>{% if current != new %}<img src="{% static 'admin/img/icon-changelink.svg' %}" alt="*" title="{% trans "Changed" %}">{% endif %}</td>
|
||||
<td>
|
||||
{% if current != new %}
|
||||
<i class="mdi mdi-pencil text-warning" title="{% trans "Changed" %}"></i>
|
||||
{% endif %}
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
|
||||
@@ -9,9 +9,9 @@
|
||||
</div>
|
||||
</a>
|
||||
<div class="dropdown-menu dropdown-menu-end dropdown-menu-arrow">
|
||||
{% if request.user.is_staff %}
|
||||
{% if config.DJANGO_ADMIN_ENABLED and request.user.is_staff %}
|
||||
<a class="dropdown-item" href="{% url 'admin:index' %}">
|
||||
<i class="mdi mdi-cog"></i> {% trans "Admin" %}
|
||||
<i class="mdi mdi-cog"></i> {% trans "Django Admin" %}
|
||||
</a>
|
||||
{% endif %}
|
||||
<a href="{% url 'account:profile' %}" class="dropdown-item">
|
||||
|
||||
Reference in New Issue
Block a user