context_processors: keep next_url for user urls on authentic (#67377)
This commit is contained in:
parent
5e5125c97d
commit
48f1e920bc
|
@ -190,6 +190,12 @@ def hobo_json(request):
|
|||
return context
|
||||
|
||||
|
||||
def _authentic2_get_next_url(request):
|
||||
from authentic2.utils.misc import get_next_url
|
||||
|
||||
return get_next_url(request.GET)
|
||||
|
||||
|
||||
def user_urls(request):
|
||||
# ugly, but necessary..
|
||||
if 'wcs.qommon' in settings.INSTALLED_APPS:
|
||||
|
@ -202,6 +208,8 @@ def user_urls(request):
|
|||
template_vars = getattr(settings, 'TEMPLATE_VARS', {})
|
||||
logout_url = '/logout/?'
|
||||
full_path = request.get_full_path()
|
||||
if 'authentic2' in settings.INSTALLED_APPS:
|
||||
full_path = _authentic2_get_next_url(request) or full_path
|
||||
query_string = urlencode({'next': full_path})
|
||||
context = {
|
||||
'login_url': '/login/?' + query_string,
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import json
|
||||
import time
|
||||
from unittest import mock
|
||||
|
||||
import django
|
||||
from django.core.cache import cache
|
||||
from django.test import override_settings
|
||||
from httmock import HTTMock, urlmatch
|
||||
|
@ -82,21 +82,23 @@ def test_user_urls(settings, rf):
|
|||
'account_url': 'https://idp/accounts/?next=http%3A%2F%2Ftestserver%2Fpage%2F',
|
||||
}
|
||||
|
||||
from django.conf import settings as real_settings
|
||||
with mock.patch('hobo.context_processors._authentic2_get_next_url', return_value='coin'):
|
||||
# simulate the real get_next_url of authentic2
|
||||
from django.conf import settings as real_settings
|
||||
|
||||
real_settings.INSTALLED_APPS += ('authentic2',)
|
||||
request = rf.get('/login/?next=coin&nonce=2')
|
||||
assert user_urls(request) == {
|
||||
'login_url': '#',
|
||||
'logout_url': '/logout/?next=%2F',
|
||||
'registration_url': '/register/?next=coin&nonce=2',
|
||||
'account_url': 'https://idp/accounts/?next=http%3A%2F%2Ftestserver%2Flogin%2F%3Fnext%3Dcoin%26nonce%3D2',
|
||||
}
|
||||
real_settings.INSTALLED_APPS += ('authentic2',)
|
||||
request = rf.get('/login/?next=coin&nonce=2')
|
||||
assert user_urls(request) == {
|
||||
'login_url': '#',
|
||||
'logout_url': '/logout/?next=%2F',
|
||||
'registration_url': '/register/?next=coin&nonce=2',
|
||||
'account_url': 'https://idp/accounts/?next=http%3A%2F%2Ftestserver%2Flogin%2F%3Fnext%3Dcoin%26nonce%3D2',
|
||||
}
|
||||
|
||||
request = rf.get('/register/?next=coin&nonce=2')
|
||||
assert user_urls(request) == {
|
||||
'login_url': '/login/?next=coin&nonce=2',
|
||||
'logout_url': '/logout/?next=%2F',
|
||||
'registration_url': '#',
|
||||
'account_url': 'https://idp/accounts/?next=http%3A%2F%2Ftestserver%2Fregister%2F%3Fnext%3Dcoin%26nonce%3D2',
|
||||
}
|
||||
request = rf.get('/register/?next=coin&nonce=2')
|
||||
assert user_urls(request) == {
|
||||
'login_url': '/login/?next=coin&nonce=2',
|
||||
'logout_url': '/logout/?next=%2F',
|
||||
'registration_url': '#',
|
||||
'account_url': 'https://idp/accounts/?next=http%3A%2F%2Ftestserver%2Fregister%2F%3Fnext%3Dcoin%26nonce%3D2',
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue