Skip to content

Commit

Permalink
[#4031] Remove methods that prevented custom types URLs
Browse files Browse the repository at this point in the history
These two methods had hardcoded calls to the group or org routes defined
in core, so custom types were ignored. Replace them with calls to
`redirect_to` or `url_for` that take the group type into account.
  • Loading branch information
amercader committed Feb 23, 2018
1 parent 8da2e48 commit 102f096
Showing 1 changed file with 8 additions and 20 deletions.
28 changes: 8 additions & 20 deletions ckan/controllers/group.py
Expand Up @@ -103,18 +103,6 @@ def _render_template(self, template_name, group_type):
return render(self._replace_group_org(template_name),
extra_vars={'group_type': group_type})

def _redirect_to_this_controller(self, *args, **kw):
''' wrapper around redirect_to but it adds in this request's controller
(so that it works for Organization or other derived controllers)'''
kw['controller'] = request.environ['pylons.routes_dict']['controller']
return h.redirect_to(*args, **kw)

def _url_for_this_controller(self, *args, **kw):
''' wrapper around url_for but it adds in this request's controller
(so that it works for Organization or other derived controllers)'''
kw['controller'] = request.environ['pylons.routes_dict']['controller']
return h.url_for(*args, **kw)

def _guess_group_type(self, expecting_name=False):
"""
Guess the type of group from the URL.
Expand Down Expand Up @@ -452,7 +440,7 @@ def bulk_process(self, id):
get_action(action_functions[action])(context, data_dict)
except NotAuthorized:
abort(403, _('Not authorized to perform bulk update'))
self._redirect_to_this_controller(action='bulk_process', id=id)
h.redirect_to(group_type + '_bulk_process', id=id)

def new(self, data=None, errors=None, error_summary=None):
if data and 'type' in data:
Expand Down Expand Up @@ -615,7 +603,7 @@ def delete(self, id):
group_type = self._ensure_controller_matches_group_type(id)

if 'cancel' in request.params:
self._redirect_to_this_controller(action='edit', id=id)
h.redirect_to(group_type + '_edit', id=id)

context = {'model': model, 'session': model.Session,
'user': c.user}
Expand All @@ -635,7 +623,7 @@ def delete(self, id):
else:
h.flash_notice(_('%s has been deleted.')
% _(group_type.capitalize()))
self._redirect_to_this_controller(action='index')
h.redirect_to(group_type + '_index')
c.group_dict = self._action('group_show')(context, {'id': id})
except NotAuthorized:
abort(403, _('Unauthorized to delete group %s') % '')
Expand Down Expand Up @@ -706,7 +694,7 @@ def member_new(self, id):
c.group_dict = self._action('group_member_create')(
context, data_dict)

self._redirect_to_this_controller(action='members', id=id)
h.redirect_to(group_type + '_members', id=id)
else:
user = request.params.get('user')
if user:
Expand All @@ -728,7 +716,7 @@ def member_delete(self, id):
group_type = self._ensure_controller_matches_group_type(id)

if 'cancel' in request.params:
self._redirect_to_this_controller(action='members', id=id)
h.redirect_to(group_type + '_members', id=id)

context = {'model': model, 'session': model.Session,
'user': c.user}
Expand All @@ -744,7 +732,7 @@ def member_delete(self, id):
self._action('group_member_delete')(
context, {'id': id, 'user_id': user_id})
h.flash_notice(_('Group member has been deleted.'))
self._redirect_to_this_controller(action='members', id=id)
h.redirect_to(group_type + '_members', id=id)
c.user_dict = self._action('user_show')(context, {'id': user_id})
c.user_id = user_id
c.group_id = id
Expand Down Expand Up @@ -792,8 +780,8 @@ def history(self, id):
from webhelpers.feedgenerator import Atom1Feed
feed = Atom1Feed(
title=_(u'CKAN Group Revision History'),
link=self._url_for_this_controller(
action='read',
link=h.url_for(
group_type + '_read',
id=c.group_dict['name']),
description=_(u'Recent changes to CKAN Group: ') +
c.group_dict['display_name'],
Expand Down

0 comments on commit 102f096

Please sign in to comment.