2018-01-16 06:58:15 +01:00
|
|
|
# -*- coding: utf-8 -*-
|
2018-01-16 11:34:37 +01:00
|
|
|
# Part of Odoo, Flectra. See LICENSE file for full copyright and licensing details.
|
2018-01-16 06:58:15 +01:00
|
|
|
|
|
|
|
import werkzeug
|
|
|
|
|
2018-01-16 11:34:37 +01:00
|
|
|
from flectra.addons.mail.controllers.main import MailController
|
|
|
|
from flectra.exceptions import AccessError
|
|
|
|
from flectra.http import request
|
|
|
|
from flectra.tools.misc import consteq
|
2018-01-16 06:58:15 +01:00
|
|
|
|
|
|
|
|
|
|
|
class MailController(MailController):
|
|
|
|
|
2018-04-05 10:25:40 +02:00
|
|
|
@classmethod
|
2018-01-16 06:58:15 +01:00
|
|
|
def _redirect_to_record(cls, model, res_id, access_token=None):
|
|
|
|
# If the current user doesn't have access to the sales order, but provided
|
|
|
|
# a valid access token, redirect him to the front-end view.
|
|
|
|
if model == 'sale.order' and res_id and access_token:
|
|
|
|
uid = request.session.uid or request.env.ref('base.public_user').id
|
|
|
|
record_sudo = request.env[model].sudo().browse(res_id).exists()
|
|
|
|
try:
|
|
|
|
record_sudo.sudo(uid).check_access_rights('read')
|
|
|
|
record_sudo.sudo(uid).check_access_rule('read')
|
|
|
|
except AccessError:
|
|
|
|
if record_sudo.access_token and consteq(record_sudo.access_token, access_token):
|
|
|
|
record_action = record_sudo.with_context(
|
|
|
|
force_website=True).get_access_action(uid)
|
|
|
|
if record_action['type'] == 'ir.actions.act_url':
|
|
|
|
return werkzeug.utils.redirect(record_action['url'])
|
2018-06-22 08:03:22 +02:00
|
|
|
return super(MailController, cls)._redirect_to_record(cls, model, res_id, access_token=access_token)
|