diff --git a/r2/r2/config/routing.py b/r2/r2/config/routing.py index 680d478fd..df137ea30 100644 --- a/r2/r2/config/routing.py +++ b/r2/r2/config/routing.py @@ -338,7 +338,7 @@ def make_map(config): mc('/w/*page', controller='wiki', action='wiki_redirect') mc('/goto', controller='toolbar', action='goto') - mc('/tb/:id', controller='toolbar', action='tb') + mc('/tb/:link_id', controller='redirect', action='link_id_redirect') mc('/toolbar/*frame', controller='toolbar', action='redirect') mc('/c/:comment_id', controller='front', action='comment_by_id') @@ -478,10 +478,9 @@ def make_map(config): # these should be near the buttom, because they should only kick # in if everything else fails. It's the attempted catch-all - # reddit.com/http://... and reddit.com/34fr, but these redirect to - # the less-guessy versions at /s/ and /tb/ - mc('/:linkoid', controller='toolbar', action='linkoid', - requirements=dict(linkoid='[0-9a-z]{1,6}')) + # reddit.com/http://... and reddit.com/34fr + mc('/:link_id', controller='redirect', action='link_id_redirect', + requirements=dict(link_id='[0-9a-z]{1,6}')) mc('/:urloid', controller='toolbar', action='s', requirements=dict(urloid=r'(\w+\.\w{2,}|https?).*')) diff --git a/r2/r2/controllers/redirect.py b/r2/r2/controllers/redirect.py index 3e00e5536..098576b29 100644 --- a/r2/r2/controllers/redirect.py +++ b/r2/r2/controllers/redirect.py @@ -25,7 +25,8 @@ from pylons import tmpl_context as c from pylons.controllers.util import abort from r2.lib.base import BaseController -from r2.lib.validator import chkuser +from r2.lib.utils import UrlParser +from r2.lib.validator import chkuser, validate, VLink from r2.models import Subreddit @@ -57,3 +58,21 @@ class RedirectController(BaseController): else: rest = '' return self.redirect("/r/%s/%s" % (sr_name, rest), code=301) + + @validate(link=VLink('link_id')) + def GET_link_id_redirect(self, link): + if not link: + abort(404) + elif not link.subreddit_slow.can_view(c.user): + # don't disclose the subreddit/title of a post via the redirect url + abort(403) + else: + redirect_url = link.make_permalink_slow(force_domain=True) + + query_params = dict(request.GET) + if query_params: + url = UrlParser(redirect_url) + url.update_query(**query_params) + redirect_url = url.unparse() + + return self.redirect(redirect_url, code=301) diff --git a/r2/r2/controllers/toolbar.py b/r2/r2/controllers/toolbar.py index 5858d0d0d..810d3f02d 100644 --- a/r2/r2/controllers/toolbar.py +++ b/r2/r2/controllers/toolbar.py @@ -99,31 +99,6 @@ class ToolbarController(RedditController): return self.redirect(add_sr("/tb/" + link._id36)) return self.abort404() - @validate(link = VLink('id')) - def GET_tb(self, link): - '''/tb/$id36, former toolbar - The reddit toolbar is no longer supported, redirect to comments page. - The /tb url is still used as redirect from the linkoid short link. - - ''' - if not link: - return self.abort404() - elif not link.subreddit_slow.can_view(c.user): - # don't disclose the subreddit/title of a post via the redirect url - self.abort403() - elif link.is_self: - redirect_url = link.url - else: - redirect_url = link.make_permalink_slow(force_domain=True) - - query_params = dict(request.GET) - if query_params: - url = UrlParser(redirect_url) - url.update_query(**query_params) - redirect_url = url.unparse() - - return self.redirect(redirect_url) - @validate(urloid=nop('urloid')) def GET_s(self, urloid): """/s/http://..., show a given URL with the toolbar. if it's @@ -153,10 +128,3 @@ class ToolbarController(RedditController): def GET_redirect(self): return self.redirect('/', code=301) - - @validate(link = VLink('linkoid')) - def GET_linkoid(self, link): - if not link: - return self.abort404() - return self.redirect(add_sr("/tb/" + link._id36)) -