mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-17 21:18:16 -06:00
Disable the Django admin UI by default
This commit is contained in:
parent
93b77cb4f0
commit
f447b21cd4
@ -99,6 +99,14 @@ The maximum size (in bytes) of an incoming HTTP request (i.e. `GET` or `POST` da
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
## DJANGO_ADMIN_ENABLED
|
||||||
|
|
||||||
|
Default: False
|
||||||
|
|
||||||
|
Setting this to True installs the `django.contrib.admin` app and enables the [Django admin UI](https://docs.djangoproject.com/en/5.0/ref/contrib/admin/). This may be necessary to support older plugins which do not integrate with the native NetBox interface.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
## ENFORCE_GLOBAL_UNIQUE
|
## ENFORCE_GLOBAL_UNIQUE
|
||||||
|
|
||||||
!!! tip "Dynamic Configuration Parameter"
|
!!! tip "Dynamic Configuration Parameter"
|
||||||
|
@ -115,6 +115,7 @@ DEFAULT_PERMISSIONS = getattr(configuration, 'DEFAULT_PERMISSIONS', {
|
|||||||
'users.delete_token': ({'user': '$user'},),
|
'users.delete_token': ({'user': '$user'},),
|
||||||
})
|
})
|
||||||
DEVELOPER = getattr(configuration, 'DEVELOPER', False)
|
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'))
|
DOCS_ROOT = getattr(configuration, 'DOCS_ROOT', os.path.join(os.path.dirname(BASE_DIR), 'docs'))
|
||||||
EMAIL = getattr(configuration, 'EMAIL', {})
|
EMAIL = getattr(configuration, 'EMAIL', {})
|
||||||
EVENTS_PIPELINE = getattr(configuration, 'EVENTS_PIPELINE', (
|
EVENTS_PIPELINE = getattr(configuration, 'EVENTS_PIPELINE', (
|
||||||
@ -355,7 +356,6 @@ SERVER_EMAIL = EMAIL.get('FROM_EMAIL')
|
|||||||
#
|
#
|
||||||
|
|
||||||
INSTALLED_APPS = [
|
INSTALLED_APPS = [
|
||||||
'django.contrib.admin',
|
|
||||||
'django.contrib.auth',
|
'django.contrib.auth',
|
||||||
'django.contrib.contenttypes',
|
'django.contrib.contenttypes',
|
||||||
'django.contrib.sessions',
|
'django.contrib.sessions',
|
||||||
@ -393,6 +393,9 @@ INSTALLED_APPS = [
|
|||||||
'drf_spectacular_sidecar',
|
'drf_spectacular_sidecar',
|
||||||
]
|
]
|
||||||
|
|
||||||
|
if DJANGO_ADMIN_ENABLED:
|
||||||
|
INSTALLED_APPS.insert(0, 'django.contrib.admin')
|
||||||
|
|
||||||
# Middleware
|
# Middleware
|
||||||
MIDDLEWARE = [
|
MIDDLEWARE = [
|
||||||
'graphiql_debug_toolbar.middleware.DebugToolbarMiddleware',
|
'graphiql_debug_toolbar.middleware.DebugToolbarMiddleware',
|
||||||
|
@ -32,6 +32,7 @@ class PluginTest(TestCase):
|
|||||||
instance.delete()
|
instance.delete()
|
||||||
self.assertIsNone(instance.pk)
|
self.assertIsNone(instance.pk)
|
||||||
|
|
||||||
|
@override_settings(DJANGO_ADMIN_ENABLED=True)
|
||||||
def test_admin(self):
|
def test_admin(self):
|
||||||
|
|
||||||
# Test admin view URL resolution
|
# Test admin view URL resolution
|
||||||
|
@ -11,7 +11,6 @@ from netbox.graphql.schema import schema
|
|||||||
from netbox.graphql.views import GraphQLView
|
from netbox.graphql.views import GraphQLView
|
||||||
from netbox.plugins.urls import plugin_patterns, plugin_api_patterns
|
from netbox.plugins.urls import plugin_patterns, plugin_api_patterns
|
||||||
from netbox.views import HomeView, StaticMediaFailureView, SearchView, htmx
|
from netbox.views import HomeView, StaticMediaFailureView, SearchView, htmx
|
||||||
from .admin import admin_site
|
|
||||||
|
|
||||||
_patterns = [
|
_patterns = [
|
||||||
|
|
||||||
@ -70,26 +69,25 @@ _patterns = [
|
|||||||
# Plugins
|
# Plugins
|
||||||
path('plugins/', include((plugin_patterns, 'plugins'))),
|
path('plugins/', include((plugin_patterns, 'plugins'))),
|
||||||
path('api/plugins/', include((plugin_api_patterns, 'plugins-api'))),
|
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:
|
if settings.DEBUG:
|
||||||
import debug_toolbar
|
import debug_toolbar
|
||||||
_patterns += [
|
_patterns.append(path('__debug__/', include(debug_toolbar.urls)))
|
||||||
path('__debug__/', include(debug_toolbar.urls)),
|
|
||||||
]
|
|
||||||
|
|
||||||
|
# Prometheus metrics
|
||||||
if settings.METRICS_ENABLED:
|
if settings.METRICS_ENABLED:
|
||||||
_patterns += [
|
_patterns.append(path('', include('django_prometheus.urls')))
|
||||||
path('', include('django_prometheus.urls')),
|
|
||||||
]
|
|
||||||
|
|
||||||
# Prepend BASE_PATH
|
# Prepend BASE_PATH
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('{}'.format(settings.BASE_PATH), include(_patterns))
|
path(settings.BASE_PATH, include(_patterns))
|
||||||
]
|
]
|
||||||
|
|
||||||
handler404 = 'netbox.views.errors.handler_404'
|
handler404 = 'netbox.views.errors.handler_404'
|
||||||
|
@ -38,7 +38,7 @@
|
|||||||
<td>{% checkmark request.user.is_superuser %}</td>
|
<td>{% checkmark request.user.is_superuser %}</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="row">{% trans "Admin Access" %}</th>
|
<th scope="row">{% trans "Staff" %}</th>
|
||||||
<td>{% checkmark request.user.is_staff %}</td>
|
<td>{% checkmark request.user.is_staff %}</td>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
|
@ -45,7 +45,11 @@
|
|||||||
<td>{{ param }}</td>
|
<td>{{ param }}</td>
|
||||||
<td>{{ current }}</td>
|
<td>{{ current }}</td>
|
||||||
<td>{{ new }}</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>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</tbody>
|
</tbody>
|
||||||
|
@ -9,9 +9,9 @@
|
|||||||
</div>
|
</div>
|
||||||
</a>
|
</a>
|
||||||
<div class="dropdown-menu dropdown-menu-end dropdown-menu-arrow">
|
<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' %}">
|
<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>
|
</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<a href="{% url 'account:profile' %}" class="dropdown-item">
|
<a href="{% url 'account:profile' %}" class="dropdown-item">
|
||||||
|
Loading…
Reference in New Issue
Block a user