Skip to content

Commit

Permalink
Try to handle repoze who urls without hard coding them to helper
Browse files Browse the repository at this point in the history
  • Loading branch information
Zharktas committed Aug 24, 2017
1 parent b774b6c commit 18c08da
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 12 deletions.
8 changes: 3 additions & 5 deletions ckan/controllers/user.py
Expand Up @@ -397,8 +397,7 @@ def login(self, error=None):
if not c.user:
came_from = request.params.get('came_from')
if not came_from:
came_from = h.url_for(controller='user', action='logged_in',
__ckan_no_root=True)
came_from = h.url_for(controller='user', action='logged_in')
c.login_handler = h.url_for(
self._get_repoze_handler('login_handler_path'),
came_from=came_from)
Expand Down Expand Up @@ -436,10 +435,9 @@ def logout(self):
# Do any plugin logout stuff
for item in p.PluginImplementations(p.IAuthenticator):
item.logout()
url = h.url_for(controller='user', action='logged_out_page',
__ckan_no_root=True)
url = h.url_for(controller='user', action='logged_out_page')
h.redirect_to(self._get_repoze_handler('logout_handler_path') +
'?came_from=' + url)
'?came_from=' + url, parse_url=True)

def logged_out(self):
# redirect if needed
Expand Down
9 changes: 2 additions & 7 deletions ckan/lib/helpers.py
Expand Up @@ -166,17 +166,12 @@ def redirect_to(*args, **kw):
uargs = map(lambda arg: str(arg) if isinstance(arg, unicode) else arg,
args)

# Repoze.who redirects with single strings
# which need to be parsed by url_for
exempt_urls = ['/user/logout', '/user/logged_out_redirect',
'/user/logged_in']
matching = [s for s in uargs if any(xs in s for xs in exempt_urls)]

_url = ''
skip_url_parsing = False
parse_url = kw.pop('parse_url', False)
if uargs and len(uargs) is 1 and isinstance(uargs[0], basestring) \
and (uargs[0].startswith('/') or is_url(uargs[0])) \
and len(matching) is 0:
and parse_url is False:
skip_url_parsing = True
_url = uargs[0]

Expand Down

0 comments on commit 18c08da

Please sign in to comment.