[IMP] auth_signup: added a model parameter for generating URLs. Portal: improved code and url generation for links in send emails.
bzr revid: tde@openerp.com-20130104113241-z4go3ac6qtl23ke8
This commit is contained in:
parent
df7eb6120c
commit
c7a865754d
|
@ -52,7 +52,7 @@ class res_partner(osv.Model):
|
||||||
(not partner.signup_expiration or dt <= partner.signup_expiration)
|
(not partner.signup_expiration or dt <= partner.signup_expiration)
|
||||||
return res
|
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
|
""" generate a signup url for the given partner ids and action, possibly overriding
|
||||||
the url state components (menu_id, id, view_type) """
|
the url state components (menu_id, id, view_type) """
|
||||||
res = dict.fromkeys(ids, False)
|
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
|
# when required, make sure the partner has a valid signup token
|
||||||
if context and context.get('signup_valid') and not partner.user_ids:
|
if context and context.get('signup_valid') and not partner.user_ids:
|
||||||
self.signup_prepare(cr, uid, [partner.id], context=context)
|
self.signup_prepare(cr, uid, [partner.id], context=context)
|
||||||
|
partner.refresh()
|
||||||
|
|
||||||
# the parameters to encode for the query and fragment part of url
|
# the parameters to encode for the query and fragment part of url
|
||||||
query = {'db': cr.dbname}
|
query = {'db': cr.dbname}
|
||||||
|
@ -78,6 +79,8 @@ class res_partner(osv.Model):
|
||||||
fragment['view_type'] = view_type
|
fragment['view_type'] = view_type
|
||||||
if menu_id:
|
if menu_id:
|
||||||
fragment['menu_id'] = menu_id
|
fragment['menu_id'] = menu_id
|
||||||
|
if model:
|
||||||
|
fragment['model'] = model
|
||||||
if res_id:
|
if res_id:
|
||||||
fragment['id'] = res_id
|
fragment['id'] = res_id
|
||||||
|
|
||||||
|
|
|
@ -19,9 +19,6 @@
|
||||||
#
|
#
|
||||||
##############################################################################
|
##############################################################################
|
||||||
|
|
||||||
from urllib import urlencode
|
|
||||||
from urlparse import urljoin
|
|
||||||
|
|
||||||
from openerp import SUPERUSER_ID
|
from openerp import SUPERUSER_ID
|
||||||
from openerp.osv import osv
|
from openerp.osv import osv
|
||||||
from openerp.osv.orm import except_orm
|
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
|
:param partner: browse_record of the specific recipient partner
|
||||||
:return: the resulting body_html
|
: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)
|
body = super(mail_mail, self).send_get_mail_body(cr, uid, mail, partner, context=context)
|
||||||
if partner:
|
if partner:
|
||||||
context = dict(context or {}, signup_valid=True)
|
contex_signup = dict(context or {}, signup_valid=True)
|
||||||
partner = self.pool.get('res.partner').browse(cr, SUPERUSER_ID, partner.id, context=context)
|
partner = partner_obj.browse(cr, SUPERUSER_ID, partner.id, context=contex_signup)
|
||||||
text = ''
|
text = _("""<p>Access your messages and personal documents through <a href="%s">our Customer Portal</a></p>""") % partner.signup_url
|
||||||
# private message
|
# partner is an user: add a link to the document if read access
|
||||||
if not mail.model or not mail.res_id:
|
if partner.user_ids and mail.model and mail.res_id \
|
||||||
text = _("""<p>Access your messages through <a href="%s">our Customer Portal</a></p>""") % partner.signup_url
|
and self.check_access_rights(cr, partner.user_ids[0].id, 'read', raise_exception=False):
|
||||||
# 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):
|
|
||||||
related_user = partner.user_ids[0]
|
related_user = partner.user_ids[0]
|
||||||
try:
|
try:
|
||||||
self.pool.get(mail.model).check_access_rule(cr, related_user.id, [mail.res_id], 'read', context=context)
|
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 = 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]
|
||||||
url_params = {
|
|
||||||
'model': mail.model,
|
|
||||||
'id': mail.res_id,
|
|
||||||
}
|
|
||||||
url = urljoin(base_url, "?#%s" % (urlencode(url_params)))
|
|
||||||
text = _("""<p>Access this document <a href="%s">directly in OpenERP</a></p>""") % url
|
text = _("""<p>Access this document <a href="%s">directly in OpenERP</a></p>""") % url
|
||||||
except except_orm, e:
|
except except_orm, e:
|
||||||
text = _("""<p>Access your messages through <a href="%s">our Customer Portal</a></p>""") % partner.signup_url
|
pass
|
||||||
# partner not user
|
|
||||||
else:
|
|
||||||
text = _("""<p>Access your messages through <a href="%s">our Customer Portal</a></p>""") % partner.signup_url
|
|
||||||
body = append_content_to_html(body, ("<div><p>%s</p></div>" % text), plaintext=False)
|
body = append_content_to_html(body, ("<div><p>%s</p></div>" % text), plaintext=False)
|
||||||
return body
|
return body
|
||||||
|
|
Loading…
Reference in New Issue