[FIX] mail: mail_mail: fixed url embedded in notification emails.
When having emails not linked to a notification (mail.notification = False) the link is generated without any clue about the source record. However we can try to use model and res_id defined on the mail_mail record to correctly format a link. Added support of model and res_id in message_redirect_action. This method now can redirect based on a message_id, or based on model / res_id. bzr revid: tde@openerp.com-20131018144924-j4f22hen3lsua7cb
This commit is contained in:
parent
a7e05f1af4
commit
62e88a16e4
|
@ -157,9 +157,9 @@ class mail_mail(osv.Model):
|
|||
'action': 'mail.action_mail_redirect',
|
||||
}
|
||||
if mail.notification:
|
||||
fragment.update({
|
||||
'message_id': mail.mail_message_id.id,
|
||||
})
|
||||
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, "?%s#%s" % (urlencode(query), urlencode(fragment)))
|
||||
return _("""<small>Access your messages and documents <a style='color:inherit' href="%s">in OpenERP</a></small>""") % url
|
||||
else:
|
||||
|
|
|
@ -566,29 +566,37 @@ class mail_thread(osv.AbstractModel):
|
|||
self.pool.get('res.users').browse(cr, SUPERUSER_ID, uid, context=context)
|
||||
act_model, act_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, *self._get_inbox_action_xml_id(cr, uid, context=context))
|
||||
action = self.pool.get(act_model).read(cr, uid, act_id, [])
|
||||
params = context.get('params')
|
||||
msg_id = model = res_id = None
|
||||
|
||||
# if msg_id specified: try to redirect to the document or fallback on the Inbox
|
||||
msg_id = context.get('params', {}).get('message_id')
|
||||
if not msg_id:
|
||||
if params:
|
||||
msg_id = params.get('message_id')
|
||||
model = params.get('model')
|
||||
res_id = params.get('res_id')
|
||||
if not msg_id and not (model and res_id):
|
||||
return action
|
||||
msg = self.pool.get('mail.message').browse(cr, uid, msg_id, context=context)
|
||||
if msg.model and msg.res_id:
|
||||
action.update({
|
||||
'context': {
|
||||
'search_default_model': msg.model,
|
||||
'search_default_res_id': msg.res_id,
|
||||
}
|
||||
})
|
||||
if self.pool.get(msg.model).check_access_rights(cr, uid, 'read', raise_exception=False):
|
||||
if msg_id and not (model and res_id):
|
||||
msg = self.pool.get('mail.message').browse(cr, uid, msg_id, context=context)
|
||||
model, res_id = msg.model, msg.res_id
|
||||
|
||||
# if model + res_id found: try to redirect to the document or fallback on the Inbox
|
||||
if model and res_id:
|
||||
model_obj = self.pool.get(model)
|
||||
if model_obj.check_access_rights(cr, uid, 'read', raise_exception=False):
|
||||
try:
|
||||
model_obj = self.pool.get(msg.model)
|
||||
model_obj.check_access_rule(cr, uid, [msg.res_id], 'read', context=context)
|
||||
model_obj.check_access_rule(cr, uid, [res_id], 'read', context=context)
|
||||
if not hasattr(model_obj, '_get_formview_action'):
|
||||
action = self.pool.get('mail.thread')._get_formview_action(cr, uid, msg.res_id, model=msg.model, context=context)
|
||||
action = self.pool.get('mail.thread')._get_formview_action(cr, uid, res_id, model=model, context=context)
|
||||
else:
|
||||
action = model_obj._get_formview_action(cr, uid, msg.res_id, context=context)
|
||||
action = model_obj._get_formview_action(cr, uid, res_id, context=context)
|
||||
except (osv.except_osv, orm.except_orm):
|
||||
pass
|
||||
action.update({
|
||||
'context': {
|
||||
'search_default_model': model,
|
||||
'search_default_res_id': res_id,
|
||||
}
|
||||
})
|
||||
return action
|
||||
|
||||
#------------------------------------------------------
|
||||
|
|
|
@ -231,6 +231,8 @@ class test_mail(TestMail):
|
|||
def test_11_notification_url(self):
|
||||
""" Tests designed to test the URL added in notification emails. """
|
||||
cr, uid, group_pigs = self.cr, self.uid, self.group_pigs
|
||||
# Test URL formatting
|
||||
base_url = self.registry('ir.config_parameter').get_param(cr, uid, 'web.base.url')
|
||||
|
||||
# Partner data
|
||||
partner_raoul = self.res_partner.browse(cr, uid, self.partner_raoul_id)
|
||||
|
@ -243,19 +245,59 @@ class test_mail(TestMail):
|
|||
# Test: link for nobody -> None
|
||||
url = mail_mail._get_partner_access_link(self.mail_mail, cr, uid, mail)
|
||||
self.assertEqual(url, None,
|
||||
'notification email: mails not send to a specific partner should not have any URL')
|
||||
'notification email: mails not send to a specific partner should not have any URL')
|
||||
|
||||
# Test: link for partner -> None
|
||||
url = mail_mail._get_partner_access_link(self.mail_mail, cr, uid, mail, partner=partner_bert)
|
||||
self.assertEqual(url, None,
|
||||
'notification email: mails send to a not-user partner should not have any URL')
|
||||
'notification email: mails send to a not-user partner should not have any URL')
|
||||
|
||||
# Test: link for user -> signin
|
||||
url = mail_mail._get_partner_access_link(self.mail_mail, cr, uid, mail, partner=partner_raoul)
|
||||
self.assertIn(base_url, url,
|
||||
'notification email: link should contain web.base.url')
|
||||
self.assertIn('db=%s' % cr.dbname, url,
|
||||
'notification email: link should contain database name')
|
||||
self.assertIn('action=mail.action_mail_redirect', url,
|
||||
'notification email: link should contain the redirect action')
|
||||
'notification email: link should contain the redirect action')
|
||||
self.assertIn('login=%s' % partner_raoul.user_ids[0].login, url,
|
||||
'notification email: link should contain the user login')
|
||||
'notification email: link should contain the user login')
|
||||
|
||||
# Test: link for user -> with model and res_id
|
||||
mail_mail_id = self.mail_mail.create(cr, uid, {'model': 'mail.group', 'res_id': group_pigs.id})
|
||||
mail = self.mail_mail.browse(cr, uid, mail_mail_id)
|
||||
url = mail_mail._get_partner_access_link(self.mail_mail, cr, uid, mail, partner=partner_raoul)
|
||||
self.assertIn(base_url, url,
|
||||
'notification email: link should contain web.base.url')
|
||||
self.assertIn('db=%s' % cr.dbname, url,
|
||||
'notification email: link should contain database name')
|
||||
self.assertIn('action=mail.action_mail_redirect', url,
|
||||
'notification email: link should contain the redirect action')
|
||||
self.assertIn('login=%s' % partner_raoul.user_ids[0].login, url,
|
||||
'notification email: link should contain the user login')
|
||||
self.assertIn('model=mail.group', url,
|
||||
'notification email: link should contain the model when having not notification email on a record')
|
||||
self.assertIn('res_id=%s' % group_pigs.id, url,
|
||||
'notification email: link should contain the res_id when having not notification email on a record')
|
||||
|
||||
# Test: link for user -> with model and res_id
|
||||
mail_mail_id = self.mail_mail.create(cr, uid, {'notification': True, 'model': 'mail.group', 'res_id': group_pigs.id})
|
||||
mail = self.mail_mail.browse(cr, uid, mail_mail_id)
|
||||
url = mail_mail._get_partner_access_link(self.mail_mail, cr, uid, mail, partner=partner_raoul)
|
||||
self.assertIn(base_url, url,
|
||||
'notification email: link should contain web.base.url')
|
||||
self.assertIn('db=%s' % cr.dbname, url,
|
||||
'notification email: link should contain database name')
|
||||
self.assertIn('action=mail.action_mail_redirect', url,
|
||||
'notification email: link should contain the redirect action')
|
||||
self.assertIn('login=%s' % partner_raoul.user_ids[0].login, url,
|
||||
'notification email: link should contain the user login')
|
||||
self.assertIn('message_id=%s' % mail.mail_message_id.id, url,
|
||||
'notification email: link based on message should contain the mail_message id')
|
||||
self.assertNotIn('model', url,
|
||||
'notification email: link based on message should not contain model')
|
||||
self.assertNotIn('res_id', url,
|
||||
'notification email: link based on message should not contain res_id')
|
||||
|
||||
@mute_logger('openerp.addons.mail.mail_thread', 'openerp.osv.orm')
|
||||
def test_12_inbox_redirection(self):
|
||||
|
@ -267,24 +309,54 @@ class test_mail(TestMail):
|
|||
|
||||
# No specific parameters -> should redirect to Inbox
|
||||
action = mail_thread.message_redirect_action(self.mail_thread, cr, self.user_raoul_id, {'params': {}})
|
||||
self.assertEqual(action.get('type'), 'ir.actions.client',
|
||||
'URL redirection: action without parameters should redirect to client action Inbox')
|
||||
self.assertEqual(action.get('id'), act_id,
|
||||
'URL redirection: action without parameters should redirect to client action Inbox')
|
||||
self.assertEqual(
|
||||
action.get('type'), 'ir.actions.client',
|
||||
'URL redirection: action without parameters should redirect to client action Inbox'
|
||||
)
|
||||
self.assertEqual(
|
||||
action.get('id'), act_id,
|
||||
'URL redirection: action without parameters should redirect to client action Inbox'
|
||||
)
|
||||
|
||||
# Bert has read access to Pigs -> should redirect to form view of Pigs
|
||||
# Raoul has read access to Pigs -> should redirect to form view of Pigs
|
||||
action = mail_thread.message_redirect_action(self.mail_thread, cr, self.user_raoul_id, {'params': {'message_id': msg_id}})
|
||||
self.assertEqual(action.get('type'), 'ir.actions.act_window',
|
||||
'URL redirection: action with message_id for read-accredited user should redirect to Pigs')
|
||||
self.assertEqual(action.get('res_id'), group_pigs.id,
|
||||
'URL redirection: action with message_id for read-accredited user should redirect to Pigs')
|
||||
self.assertEqual(
|
||||
action.get('type'), 'ir.actions.act_window',
|
||||
'URL redirection: action with message_id for read-accredited user should redirect to Pigs'
|
||||
)
|
||||
self.assertEqual(
|
||||
action.get('res_id'), group_pigs.id,
|
||||
'URL redirection: action with message_id for read-accredited user should redirect to Pigs'
|
||||
)
|
||||
action = mail_thread.message_redirect_action(self.mail_thread, cr, self.user_raoul_id, {'params': {'model': 'mail.group', 'res_id': group_pigs.id}})
|
||||
self.assertEqual(
|
||||
action.get('type'), 'ir.actions.act_window',
|
||||
'URL redirection: action with message_id for read-accredited user should redirect to Pigs'
|
||||
)
|
||||
self.assertEqual(
|
||||
action.get('res_id'), group_pigs.id,
|
||||
'URL redirection: action with message_id for read-accredited user should redirect to Pigs'
|
||||
)
|
||||
|
||||
# Bert has no read access to Pigs -> should redirect to Inbox
|
||||
action = mail_thread.message_redirect_action(self.mail_thread, cr, self.user_bert_id, {'params': {'message_id': msg_id}})
|
||||
self.assertEqual(action.get('type'), 'ir.actions.client',
|
||||
'URL redirection: action without parameters should redirect to client action Inbox')
|
||||
self.assertEqual(action.get('id'), act_id,
|
||||
'URL redirection: action without parameters should redirect to client action Inbox')
|
||||
self.assertEqual(
|
||||
action.get('type'), 'ir.actions.client',
|
||||
'URL redirection: action without parameters should redirect to client action Inbox'
|
||||
)
|
||||
self.assertEqual(
|
||||
action.get('id'), act_id,
|
||||
'URL redirection: action without parameters should redirect to client action Inbox'
|
||||
)
|
||||
action = mail_thread.message_redirect_action(self.mail_thread, cr, self.user_bert_id, {'params': {'model': 'mail.group', 'res_id': group_pigs.id}})
|
||||
self.assertEqual(
|
||||
action.get('type'), 'ir.actions.client',
|
||||
'URL redirection: action without parameters should redirect to client action Inbox'
|
||||
)
|
||||
self.assertEqual(
|
||||
action.get('id'), act_id,
|
||||
'URL redirection: action without parameters should redirect to client action Inbox'
|
||||
)
|
||||
|
||||
def test_20_message_post(self):
|
||||
""" Tests designed for message_post. """
|
||||
|
|
Loading…
Reference in New Issue