Skip to content

Commit 860805b

Browse files
committed
Closes #10255: Introduce LOGOUT_REDIRECT_URL config parameter to control redirection of user after logout
1 parent 1e0b024 commit 860805b

File tree

5 files changed

+15
-2
lines changed

5 files changed

+15
-2
lines changed

docs/configuration/security.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,14 @@ The lifetime (in seconds) of the authentication cookie issued to a NetBox user u
129129

130130
---
131131

132+
## LOGOUT_REDIRECT_URL
133+
134+
Default: `'home'`
135+
136+
The view name or URL to which a user is redirected after logging out.
137+
138+
---
139+
132140
## SESSION_COOKIE_NAME
133141

134142
Default: `sessionid`

docs/release-notes/version-3.3.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
### Enhancements
66

7+
* [#10255](https://github.com/netbox-community/netbox/issues/10255) - Introduce `LOGOUT_REDIRECT_URL` config parameter to control redirection of user after logout
78
* [#10516](https://github.com/netbox-community/netbox/issues/10516) - Add vertical frame & cabinet rack types
89
* [#10748](https://github.com/netbox-community/netbox/issues/10748) - Add provider selection field for provider networks to circuit termination edit view
910
* [#11089](https://github.com/netbox-community/netbox/issues/11089) - Permit whitespace in MAC addresses

netbox/netbox/configuration_example.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,9 @@
149149
# re-authenticate. (Default: 1209600 [14 days])
150150
LOGIN_TIMEOUT = None
151151

152+
# The view name or URL to which users are redirected after logging out.
153+
LOGOUT_REDIRECT_URL = 'home'
154+
152155
# The file path where uploaded media such as image attachments are stored. A trailing slash is not needed. Note that
153156
# the default value of this setting is derived from the installed location.
154157
# MEDIA_ROOT = '/opt/netbox/netbox/media'

netbox/netbox/settings.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@
102102
LOGIN_PERSISTENCE = getattr(configuration, 'LOGIN_PERSISTENCE', False)
103103
LOGIN_REQUIRED = getattr(configuration, 'LOGIN_REQUIRED', False)
104104
LOGIN_TIMEOUT = getattr(configuration, 'LOGIN_TIMEOUT', None)
105+
LOGOUT_REDIRECT_URL = getattr(configuration, 'LOGOUT_REDIRECT_URL', 'home')
105106
MEDIA_ROOT = getattr(configuration, 'MEDIA_ROOT', os.path.join(BASE_DIR, 'media')).rstrip('/')
106107
METRICS_ENABLED = getattr(configuration, 'METRICS_ENABLED', False)
107108
PLUGINS = getattr(configuration, 'PLUGINS', [])

netbox/users/views.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from django.contrib.auth.models import update_last_login
88
from django.contrib.auth.signals import user_logged_in
99
from django.http import HttpResponseRedirect
10-
from django.shortcuts import get_object_or_404, redirect, render
10+
from django.shortcuts import get_object_or_404, redirect, render, resolve_url
1111
from django.urls import reverse
1212
from django.utils.decorators import method_decorator
1313
from django.utils.http import url_has_allowed_host_and_scheme, urlencode
@@ -142,7 +142,7 @@ def get(self, request):
142142
messages.info(request, "You have logged out.")
143143

144144
# Delete session key cookie (if set) upon logout
145-
response = HttpResponseRedirect(reverse('home'))
145+
response = HttpResponseRedirect(resolve_url(settings.LOGOUT_REDIRECT_URL))
146146
response.delete_cookie('session_key')
147147

148148
return response

0 commit comments

Comments
 (0)