diff --git a/docs/configuration/security.md b/docs/configuration/security.md index 6aa363b1a..41f7cc71a 100644 --- a/docs/configuration/security.md +++ b/docs/configuration/security.md @@ -129,6 +129,14 @@ The lifetime (in seconds) of the authentication cookie issued to a NetBox user u --- +## LOGOUT_REDIRECT_URL + +Default: `'home'` + +The view name or URL to which a user is redirected after logging out. + +--- + ## SESSION_COOKIE_NAME Default: `sessionid` diff --git a/docs/release-notes/version-3.3.md b/docs/release-notes/version-3.3.md index 3f05c7977..c86317d26 100644 --- a/docs/release-notes/version-3.3.md +++ b/docs/release-notes/version-3.3.md @@ -4,6 +4,7 @@ ### Enhancements +* [#10255](https://github.com/netbox-community/netbox/issues/10255) - Introduce `LOGOUT_REDIRECT_URL` config parameter to control redirection of user after logout * [#10516](https://github.com/netbox-community/netbox/issues/10516) - Add vertical frame & cabinet rack types * [#10748](https://github.com/netbox-community/netbox/issues/10748) - Add provider selection field for provider networks to circuit termination edit view * [#11089](https://github.com/netbox-community/netbox/issues/11089) - Permit whitespace in MAC addresses diff --git a/netbox/netbox/configuration_example.py b/netbox/netbox/configuration_example.py index ad0dcc7c3..2601775e6 100644 --- a/netbox/netbox/configuration_example.py +++ b/netbox/netbox/configuration_example.py @@ -149,6 +149,9 @@ LOGIN_REQUIRED = False # re-authenticate. (Default: 1209600 [14 days]) LOGIN_TIMEOUT = None +# The view name or URL to which users are redirected after logging out. +LOGOUT_REDIRECT_URL = 'home' + # The file path where uploaded media such as image attachments are stored. A trailing slash is not needed. Note that # the default value of this setting is derived from the installed location. # MEDIA_ROOT = '/opt/netbox/netbox/media' diff --git a/netbox/netbox/settings.py b/netbox/netbox/settings.py index 773c8753f..663da3b32 100644 --- a/netbox/netbox/settings.py +++ b/netbox/netbox/settings.py @@ -102,6 +102,7 @@ LOGGING = getattr(configuration, 'LOGGING', {}) LOGIN_PERSISTENCE = getattr(configuration, 'LOGIN_PERSISTENCE', False) LOGIN_REQUIRED = getattr(configuration, 'LOGIN_REQUIRED', False) LOGIN_TIMEOUT = getattr(configuration, 'LOGIN_TIMEOUT', None) +LOGOUT_REDIRECT_URL = getattr(configuration, 'LOGOUT_REDIRECT_URL', 'home') MEDIA_ROOT = getattr(configuration, 'MEDIA_ROOT', os.path.join(BASE_DIR, 'media')).rstrip('/') METRICS_ENABLED = getattr(configuration, 'METRICS_ENABLED', False) PLUGINS = getattr(configuration, 'PLUGINS', []) diff --git a/netbox/users/views.py b/netbox/users/views.py index c688d6b4f..a02f1ae2c 100644 --- a/netbox/users/views.py +++ b/netbox/users/views.py @@ -7,7 +7,7 @@ from django.contrib.auth.mixins import LoginRequiredMixin from django.contrib.auth.models import update_last_login from django.contrib.auth.signals import user_logged_in from django.http import HttpResponseRedirect -from django.shortcuts import get_object_or_404, redirect, render +from django.shortcuts import get_object_or_404, redirect, render, resolve_url from django.urls import reverse from django.utils.decorators import method_decorator from django.utils.http import url_has_allowed_host_and_scheme, urlencode @@ -142,7 +142,7 @@ class LogoutView(View): messages.info(request, "You have logged out.") # Delete session key cookie (if set) upon logout - response = HttpResponseRedirect(reverse('home')) + response = HttpResponseRedirect(resolve_url(settings.LOGOUT_REDIRECT_URL)) response.delete_cookie('session_key') return response