0001-misc-add-context-processor-user_urls-61192.patch
debian/debian_config_common.py | ||
---|---|---|
241 | 241 |
'hobo.context_processors.template_vars', |
242 | 242 |
'hobo.context_processors.theme_base', |
243 | 243 |
'hobo.context_processors.portal_agent_url', |
244 |
'hobo.context_processors.user_urls', |
|
244 | 245 |
) + TEMPLATE_CONTEXT_PROCESSORS |
245 | 246 |
else: |
246 | 247 |
assert len(TEMPLATES) |
hobo/context_processors.py | ||
---|---|---|
10 | 10 |
from django.core.cache import cache |
11 | 11 |
from django.template import Template |
12 | 12 |
from django.utils.encoding import smart_bytes |
13 |
from django.utils.http import urlencode |
|
13 | 14 |
from django.utils.six.moves.urllib import parse as urlparse |
14 | 15 | |
15 | 16 |
from hobo.scrutiny.wsgi.middleware import VersionMiddleware |
... | ... | |
187 | 188 |
context = TemplateVars.get_hobo_json_variables(get_hobo_json()) |
188 | 189 |
context['manager_homepage_url'] = context.get(settings.HOBO_MANAGER_HOMEPAGE_URL_VAR) |
189 | 190 |
return context |
191 | ||
192 | ||
193 |
def user_urls(request): |
|
194 |
template_vars = getattr(settings, 'TEMPLATE_VARS', {}) |
|
195 |
full_path = request.get_full_path() |
|
196 |
query_string = urlencode({'next': full_path}) |
|
197 |
context = { |
|
198 |
'login_url': '/login/?' + query_string, |
|
199 |
'logout_url': '/logout/?' + query_string, |
|
200 |
} |
|
201 |
absolute_uri = request.build_absolute_uri() |
|
202 |
if 'idp_account_url' in template_vars: |
|
203 |
context['account_url'] = template_vars['idp_account_url'] + '?' + urlencode({'next': absolute_uri}) |
|
204 |
if 'idp_registration_url' in template_vars: |
|
205 |
context['registration_url'] = ( |
|
206 |
template_vars['idp_registration_url'] + '?' + urlencode({'next': absolute_uri}) |
|
207 |
) |
|
208 |
return context |
hobo/multitenant/settings_loaders.py | ||
---|---|---|
183 | 183 |
# expect authentic to search first in the default ou |
184 | 184 |
params['service'] = variables['portal_user_slug'] |
185 | 185 |
if params: |
186 |
variables['idp_registration_url'] += '?%s' % urlencode(params) |
|
187 | 186 |
variables['idp_service_params'] = urlencode({k: v for k, v in params.items() if k != 'next'}) |
188 | 187 |
variables['idp_service_and_next_params'] = urlencode(params) |
189 | 188 |
tests/test_context_processors.py | ||
---|---|---|
6 | 6 |
from django.test import override_settings |
7 | 7 |
from httmock import HTTMock, urlmatch |
8 | 8 | |
9 |
from hobo.context_processors import theme_base |
|
9 |
from hobo.context_processors import theme_base, user_urls
|
|
10 | 10 | |
11 | 11 | |
12 | 12 |
def test_theme_base(settings, rf): |
... | ... | |
66 | 66 |
context = theme_base(rf.get('/page1/page2/')) |
67 | 67 |
check(context, TEMPLATE_PAGE2) |
68 | 68 |
assert len(seen_urls) == 0 |
69 | ||
70 | ||
71 |
def test_user_urls(settings, rf): |
|
72 |
settings.TEMPLATE_VARS = { |
|
73 |
'idp_registration_url': 'https://idp/register/', |
|
74 |
'idp_account_url': 'https://idp/accounts/', |
|
75 |
} |
|
76 | ||
77 |
request = rf.get('/page/') |
|
78 |
assert user_urls(request) == { |
|
79 |
'login_url': '/login/?next=%2Fpage%2F', |
|
80 |
'logout_url': '/logout/?next=%2Fpage%2F', |
|
81 |
'registration_url': 'https://idp/register/?next=http%3A%2F%2Ftestserver%2Fpage%2F', |
|
82 |
'account_url': 'https://idp/accounts/?next=http%3A%2F%2Ftestserver%2Fpage%2F', |
|
83 |
} |
tests/test_settings_loaders.py | ||
---|---|---|
173 | 173 |
loader.update_settings_from_path(tenant_settings, path) |
174 | 174 |
assert tenant_settings.SMS_URL == 'https://example.com/send/' |
175 | 175 |
assert tenant_settings.SMS_SENDER == 'Sender' |
176 | ||
177 | ||
178 |
def test_get_hobo_json_variables(tmpdir): |
|
179 |
from django.http.request import QueryDict |
|
180 | ||
181 |
a = Authentic(title='bar', slug='bar', base_url='http://bar.example.net') |
|
182 |
a.save() |
|
183 |
c = Combo(title='combo', slug='portal', base_url='http://portal.example.net', template_name='portal-user') |
|
184 |
c.save() |
|
185 | ||
186 |
loader = TemplateVars() |
|
187 |
env = get_hobo_json() |
|
188 | ||
189 |
variables = loader.get_hobo_json_variables(env) |
|
190 | ||
191 |
url, query = variables['idp_registration_url'].split('?') |
|
192 |
assert url == 'http://bar.example.net/accounts/register/' |
|
193 |
assert QueryDict(query).dict() == {'next': 'http://portal.example.net/', 'service': 'portal'} |
|
194 | ||
195 | ||
196 |
def test_get_hobo_json_variables_secondary(tmpdir): |
|
197 |
from django.http.request import QueryDict |
|
198 | ||
199 |
a = Authentic(title='bar', slug='bar', base_url='http://bar.example.net', secondary=True) |
|
200 |
a.save() |
|
201 |
c = Combo(title='combo', slug='portal', base_url='http://portal.example.net', template_name='portal-user') |
|
202 |
c.save() |
|
203 |
# simulate hobo.json from a secondary hobo |
|
204 |
v = Variable(name='ou-slug', auto=True, service_pk=None, value='hobo-othercol') |
|
205 |
v.save() |
|
206 | ||
207 |
loader = TemplateVars() |
|
208 |
env = get_hobo_json() |
|
209 | ||
210 |
variables = loader.get_hobo_json_variables(env) |
|
211 | ||
212 |
url, query = variables['idp_registration_url'].split('?') |
|
213 |
assert url == 'http://bar.example.net/accounts/register/' |
|
214 |
assert QueryDict(query).dict() == { |
|
215 |
'next': 'http://portal.example.net/', |
|
216 |
'service': 'hobo-othercol _hobo-othercol_portal', |
|
217 |
} |
|
218 |
- |