[FIX] mail, website_mail: specific mailing-list footer + better unsubscribe option

- remove the default footer for mail.group messages,
  replace with specific footer with archive and unsubscribe
  link
- remove the automatic addition of user signature in
  mail.group messages, as many of them will be posted
  via the mail gateway and already contain a user signature.
- make it easier to unsubscribe even when not logged in,
  as followers who have not signed up will have no
  way to login short of signing up.
- remove tests looking for user signature in mail.group posts
This commit is contained in:
Olivier Dony 2014-07-16 22:51:43 +02:00
parent 9955624029
commit 6ac1deccf6
6 changed files with 59 additions and 24 deletions

View File

@ -138,10 +138,10 @@ class mail_notification(osv.Model):
company = "<a style='color:inherit' href='%s'>%s</a>" % (website_url, user.company_id.name)
else:
company = user.company_id.name
sent_by = _('Sent by %(company)s using %(openerp)s.')
sent_by = _('Sent by %(company)s using %(odoo)s.')
signature_company = '<small>%s</small>' % (sent_by % {
'company': company,
'openerp': "<a style='color:inherit' href='https://www.openerp.com/'>OpenERP</a>"
'odoo': "<a style='color:inherit' href='https://www.odoo.com/'>Odoo</a>"
})
footer = tools.append_content_to_html(footer, signature_company, plaintext=False, container_tag='div')
@ -174,8 +174,9 @@ class mail_notification(osv.Model):
# compute email body (signature, company data)
body_html = message.body
user_id = message.author_id and message.author_id.user_ids and message.author_id.user_ids[0] and message.author_id.user_ids[0].id or None
if user_signature:
# add user signature except for mail groups, where users are usually adding their own signatures already
if user_signature and message.model != 'mail.group':
user_id = message.author_id and message.author_id.user_ids and message.author_id.user_ids[0] and message.author_id.user_ids[0].id or None
signature_company = self.get_signature_footer(cr, uid, user_id, res_model=message.model, res_id=message.res_id, context=context)
body_html = tools.append_content_to_html(body_html, signature_company, plaintext=False, container_tag='div')

View File

@ -468,14 +468,10 @@ class test_mail(TestMail):
'message_post: notification email subject incorrect')
self.assertIn(_body1, sent_email['body'],
'message_post: notification email body incorrect')
self.assertIn(user_raoul.signature, sent_email['body'],
'message_post: notification email body should contain the sender signature')
self.assertIn('Pigs rules', sent_email['body_alternative'],
'message_post: notification email body alternative should contain the body')
self.assertNotIn('<p>', sent_email['body_alternative'],
'message_post: notification email body alternative still contains html')
self.assertIn(user_raoul.signature, sent_email['body_alternative'],
'message_post: notification email body alternative should contain the sender signature')
self.assertFalse(sent_email['references'],
'message_post: references should be False when sending a message that is not a reply')
@ -539,14 +535,10 @@ class test_mail(TestMail):
'message_post: notification email subject incorrect')
self.assertIn(html_sanitize(_body2), sent_email['body'],
'message_post: notification email does not contain the body')
self.assertIn(user_raoul.signature, sent_email['body'],
'message_post: notification email body should contain the sender signature')
self.assertIn('Pigs rocks', sent_email['body_alternative'],
'message_post: notification email body alternative should contain the body')
self.assertNotIn('<p>', sent_email['body_alternative'],
'message_post: notification email body alternative still contains html')
self.assertIn(user_raoul.signature, sent_email['body_alternative'],
'message_post: notification email body alternative should contain the sender signature')
self.assertIn(msg_message_id, sent_email['references'],
'message_post: notification email references lacks parent message message_id')
# Test: attachments + download

View File

@ -40,17 +40,21 @@
}
this.$target.removeClass('has-error');
openerp.jsonRpc('/website_mail/follow', 'call', {
'id': +this.$target.data('id'),
'object': this.$target.data('object'),
'message_is_follower': this.$target.attr("data-follow") || "off",
'email': $email.length ? $email.val() : false,
}).then(function (follow) {
self.toggle_subscription(follow, self.email);
});
var email = $email.length ? $email.val() : false;
if (email) {
openerp.jsonRpc('/website_mail/follow', 'call', {
'id': +this.$target.data('id'),
'object': this.$target.data('object'),
'message_is_follower': this.$target.attr("data-follow") || "off",
'email': email,
}).then(function (follow) {
self.toggle_subscription(follow, email);
});
}
},
toggle_subscription: function(follow, email) {
console.log(follow, email);
follow = follow || (!email && this.$target.attr('data-unsubscribe'));
if (follow) {
this.$target.find(".js_follow_btn").addClass("hidden");
this.$target.find(".js_unfollow_btn").removeClass("hidden");
@ -60,8 +64,8 @@
this.$target.find(".js_unfollow_btn").addClass("hidden");
}
this.$target.find('input.js_follow_email')
.val(email ? email : "")
.attr("disabled", follow || (email.length && this.is_user) ? "disabled" : false);
.val(email || "")
.attr("disabled", email && (follow || this.is_user) ? "disabled" : false);
this.$target.attr("data-follow", follow ? 'on' : 'off');
},
});

View File

@ -5,7 +5,8 @@
<template id="follow">
<div class="input-group js_follow" t-att-data-id="object.id"
t-att-data-object="object._name"
t-att-data-follow="object.id and object.message_is_follower and 'on' or 'off'">
t-att-data-follow="object.id and object.message_is_follower and 'on' or 'off'"
t-att-data-unsubscribe="'unsubscribe' if 'unsubscribe' in request.params else None">
<input
type="email" name="email"
class="js_follow_email form-control"

View File

@ -1,6 +1,8 @@
# -*- coding: utf-8 -*-
from openerp.osv import osv
from openerp import tools
from openerp.tools.translate import _
class MailGroup(osv.Model):
@ -13,6 +15,38 @@ class MailGroup(osv.Model):
res['headers'].update({
'List-Archive': '<%s/groups/%s>' % (base_url, group.id),
'List-Subscribe': '<%s/groups>' % (base_url),
'List-Unsubscribe': '<%s/groups>' % (base_url),
'List-Unsubscribe': '<%s/groups?unsubscribe>' % (base_url,),
})
return res
class MailMail(osv.Model):
_inherit = 'mail.mail'
def send_get_mail_body(self, cr, uid, mail, partner=None, context=None):
""" Short-circuit parent method for mail groups, replace the default
footer with one appropriate for mailing-lists."""
if mail.model == 'mail.group' and mail.res_id:
# no super() call on purpose, no private links that could be quoted!
group = self.pool['mail.group'].browse(cr, uid, mail.res_id, context=context)
base_url = self.pool['ir.config_parameter'].get_param(cr, uid, 'web.base.url')
vals = {
'maillist': _('Mailing-List'),
'post_to': _('Post to'),
'unsub': _('Unsubscribe'),
'mailto': 'mailto:%s@%s' % (group.alias_name, group.alias_domain),
'group_url': '%s/groups/%s' % (base_url, group.id),
'unsub_url': '%s/groups?unsubscribe' % (base_url,),
}
footer = """_______________________________________________
%(maillist)s: %(group_url)s
%(post_to)s: %(mailto)s
%(unsub)s: %(unsub_url)s
""" % vals
body = tools.append_content_to_html(mail.body, footer, container_tag='div')
return body
else:
return super(MailMail, self).send_get_mail_body(cr, uid, mail,
partner=partner,
context=context)

View File

@ -26,6 +26,9 @@
</section>
</div>
<div class="container mt32">
<div t-if="'unsubscribe' in request.params" class="col-md-offset-9 col-md-3 alert alert-info">
<h3>Looking to unsubscribe? It's right here! <span class="fa fa-2x fa-arrow-down pull-right"></span></h3>
</div>
<div class="row mt8" t-foreach="groups" t-as="group">
<div class="col-md-3">
<img t-att-src="'/website/image?model=mail.group&amp;field=image_small&amp;id='+str(group['id'])" class="pull-left"/>