Separate "linkoid" (id36) redirection from toolbar

The redirection to a particular submission from visiting something like
https://www.reddit.com/<id36> was previously being handled by going
through the /tb/ address, which would use the reddit toolbar (now
removed). This gets rid of that unnecessary step and just redirects to
the submission directly from either the "linkoid" address, or the /tb/
one.
This commit is contained in:
Chad Birch
2015-12-22 18:23:16 -07:00
parent 0bbc1e465c
commit a0d15d8540
3 changed files with 24 additions and 38 deletions

View File

@@ -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?).*'))

View File

@@ -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)

View File

@@ -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))