[FIX] website_forum: when sending emails about forum post, use the public url instead of the private

This commit is contained in:
Martin Trigaux 2014-05-20 13:10:44 +02:00
parent 96128a678e
commit 4c822b1a3b
3 changed files with 25 additions and 14 deletions

View File

@ -149,19 +149,9 @@ class mail_mail(osv.Model):
link to action_mail_redirect action that will redirect to doc or Inbox """ link to action_mail_redirect action that will redirect to doc or Inbox """
if partner and partner.user_ids: if partner and partner.user_ids:
base_url = self.pool.get('ir.config_parameter').get_param(cr, uid, 'web.base.url') base_url = self.pool.get('ir.config_parameter').get_param(cr, uid, 'web.base.url')
# the parameters to encode for the query and fragment part of url mail_model = mail.model or 'mail.thread'
query = {'db': cr.dbname} url = urljoin(base_url, self.pool[mail_model]._get_access_link(cr, uid, mail, partner, context=context))
fragment = { return _("""<span class='oe_mail_footer_access'><small>Access your messages and documents <a style='color:inherit' href="%s">in Odoo</a></small></span>""") % url
'login': partner.user_ids[0].login,
'action': 'mail.action_mail_redirect',
}
if mail.notification:
fragment['message_id'] = mail.mail_message_id.id
elif mail.model and mail.res_id:
fragment.update(model=mail.model, res_id=mail.res_id)
url = urljoin(base_url, "/web?%s#%s" % (urlencode(query), urlencode(fragment)))
return _("""<span class='oe_mail_footer_access'><small>Access your messages and documents <a style='color:inherit' href="%s">in OpenERP</a></small></span>""") % url
else: else:
return None return None

View File

@ -35,6 +35,7 @@ import socket
import time import time
import xmlrpclib import xmlrpclib
from email.message import Message from email.message import Message
from urllib import urlencode
from openerp import tools from openerp import tools
from openerp import SUPERUSER_ID from openerp import SUPERUSER_ID
@ -641,6 +642,20 @@ class mail_thread(osv.AbstractModel):
}) })
return action return action
def _get_access_link(self, cr, uid, mail, partner, context=None):
# the parameters to encode for the query and fragment part of url
query = {'db': cr.dbname}
fragment = {
'login': partner.user_ids[0].login,
'action': 'mail.action_mail_redirect',
}
if mail.notification:
fragment['message_id'] = mail.mail_message_id.id
elif mail.model and mail.res_id:
fragment.update(model=mail.model, res_id=mail.res_id)
return "/web?%s#%s" % (urlencode(query), urlencode(fragment))
#------------------------------------------------------ #------------------------------------------------------
# Email specific # Email specific
#------------------------------------------------------ #------------------------------------------------------

View File

@ -1,7 +1,8 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import openerp from urlparse import urljoin
import openerp
from openerp import SUPERUSER_ID from openerp import SUPERUSER_ID
from openerp.addons.website.models.website import slug from openerp.addons.website.models.website import slug
from openerp.osv import osv, fields from openerp.osv import osv, fields
@ -272,6 +273,11 @@ class Post(osv.Model):
cr.execute("""UPDATE forum_post SET views = views+1 WHERE id IN %s""", (tuple(ids),)) cr.execute("""UPDATE forum_post SET views = views+1 WHERE id IN %s""", (tuple(ids),))
return True return True
def _get_access_link(self, cr, uid, mail, partner, context=None):
post = self.pool['forum.post'].browse(cr, uid, mail.res_id, context=context)
res_id = post.parent_id and "%s#answer-%s" % (post.parent_id.id, post.id) or post.id
return "/forum/%s/question/%s" % (post.forum_id.id, res_id)
class PostReason(osv.Model): class PostReason(osv.Model):
_name = "forum.post.reason" _name = "forum.post.reason"