Files
odoo_source/addons/website_links/controller/main.py
T
Xavier Morel 630beba02e [FIX] website_links: incorrect uses of redirect
Until Werkzeug 0.14, redirect() would resolve all URLs to absolute
paths or even absolute URL, because relative paths were not valid
according to the HTTP RFCs (though most browsers supported them).

However RFC 7231 allows them, so Werkzeug 0.15 removes this rewrite on
URLs, and `redirect('foo/bar')` now redirects *relative to the current
URL* instead of the old `/foo/bar`.

If `code` is not found, the link tracker loops on the current
URL (`/r/{code}`) instead of redirecting to `/` as was intended.

Going through uses of redirect() this seems to be the only problematic
call site left, others either use absolute paths or they use URLs
coming from the outside.

Task 2254691

closes odoo/odoo#53327

X-original-commit: 3a6e079e54a6f973cfc96995a84a7fabff803f1c
Signed-off-by: Xavier Morel (xmo) <xmo@odoo.com>
2020-06-19 13:05:11 +00:00

42 lines
1.7 KiB
Python

# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
import werkzeug
from odoo import http
from odoo.http import request
class WebsiteUrl(http.Controller):
@http.route('/website_links/new', type='json', auth='user', methods=['POST'])
def create_shorten_url(self, **post):
if 'url' not in post or post['url'] == '':
return {'error': 'empty_url'}
return request.env['link.tracker'].create(post).read()
@http.route('/r', type='http', auth='user', website=True)
def shorten_url(self, **post):
return request.render("website_links.page_shorten_url", post)
@http.route('/website_links/add_code', type='json', auth='user')
def add_code(self, **post):
link_id = request.env['link.tracker.code'].search([('code', '=', post['init_code'])], limit=1).link_id.id
new_code = request.env['link.tracker.code'].search_count([('code', '=', post['new_code']), ('link_id', '=', link_id)])
if new_code > 0:
return new_code.read()
else:
return request.env['link.tracker.code'].create({'code': post['new_code'], 'link_id': link_id})[0].read()
@http.route('/website_links/recent_links', type='json', auth='user')
def recent_links(self, **post):
return request.env['link.tracker'].recent_links(post['filter'], post['limit'])
@http.route('/r/<string:code>+', type='http', auth="user", website=True)
def statistics_shorten_url(self, code, **post):
code = request.env['link.tracker.code'].search([('code', '=', code)], limit=1)
if code:
return request.render("website_links.graphs", code.link_id.read()[0])
else:
return werkzeug.utils.redirect('/', 301)