diff --git a/addons/auth_signup/res_users.py b/addons/auth_signup/res_users.py index 5c558ca68d7..b35ff274a6d 100644 --- a/addons/auth_signup/res_users.py +++ b/addons/auth_signup/res_users.py @@ -52,7 +52,7 @@ class res_partner(osv.Model): (not partner.signup_expiration or dt <= partner.signup_expiration) return res - def _get_signup_url_for_action(self, cr, uid, ids, action='login', view_type=None, menu_id=None, res_id=None, context=None): + def _get_signup_url_for_action(self, cr, uid, ids, action='login', view_type=None, menu_id=None, res_id=None, model=None, context=None): """ generate a signup url for the given partner ids and action, possibly overriding the url state components (menu_id, id, view_type) """ res = dict.fromkeys(ids, False) @@ -61,6 +61,7 @@ class res_partner(osv.Model): # when required, make sure the partner has a valid signup token if context and context.get('signup_valid') and not partner.user_ids: self.signup_prepare(cr, uid, [partner.id], context=context) + partner.refresh() # the parameters to encode for the query and fragment part of url query = {'db': cr.dbname} @@ -78,6 +79,8 @@ class res_partner(osv.Model): fragment['view_type'] = view_type if menu_id: fragment['menu_id'] = menu_id + if model: + fragment['model'] = model if res_id: fragment['id'] = res_id diff --git a/addons/portal/mail_mail.py b/addons/portal/mail_mail.py index 80c76602419..5f73deccf9d 100644 --- a/addons/portal/mail_mail.py +++ b/addons/portal/mail_mail.py @@ -19,9 +19,6 @@ # ############################################################################## -from urllib import urlencode -from urlparse import urljoin - from openerp import SUPERUSER_ID from openerp.osv import osv from openerp.osv.orm import except_orm @@ -39,30 +36,21 @@ class mail_mail(osv.Model): :param partner: browse_record of the specific recipient partner :return: the resulting body_html """ + partner_obj = self.pool.get('res.partner') body = super(mail_mail, self).send_get_mail_body(cr, uid, mail, partner, context=context) if partner: - context = dict(context or {}, signup_valid=True) - partner = self.pool.get('res.partner').browse(cr, SUPERUSER_ID, partner.id, context=context) - text = '' - # private message - if not mail.model or not mail.res_id: - text = _("""
Access your messages through our Customer Portal
""") % partner.signup_url - # partner is also an user: add a link if read access to the document - elif partner.user_ids and self.check_access_rights(cr, partner.user_ids[0].id, 'read', raise_exception=False): + contex_signup = dict(context or {}, signup_valid=True) + partner = partner_obj.browse(cr, SUPERUSER_ID, partner.id, context=contex_signup) + text = _("""Access your messages and personal documents through our Customer Portal
""") % partner.signup_url + # partner is an user: add a link to the document if read access + if partner.user_ids and mail.model and mail.res_id \ + and self.check_access_rights(cr, partner.user_ids[0].id, 'read', raise_exception=False): related_user = partner.user_ids[0] try: self.pool.get(mail.model).check_access_rule(cr, related_user.id, [mail.res_id], 'read', context=context) - base_url = self.pool.get('ir.config_parameter').get_param(cr, uid, 'web.base.url') - url_params = { - 'model': mail.model, - 'id': mail.res_id, - } - url = urljoin(base_url, "?#%s" % (urlencode(url_params))) + url = partner_obj._get_signup_url_for_action(cr, related_user.id, [partner.id], action='', res_id=mail.res_id, model=mail.model, context=context)[partner.id] text = _("""Access this document directly in OpenERP
""") % url except except_orm, e: - text = _("""Access your messages through our Customer Portal
""") % partner.signup_url - # partner not user - else: - text = _("""Access your messages through our Customer Portal
""") % partner.signup_url + pass body = append_content_to_html(body, ("%s