diff options
| author | Olivier Dony <odo@openerp.com> | 2014-07-16 22:51:43 +0200 |
|---|---|---|
| committer | Olivier Dony <odo@openerp.com> | 2014-07-16 23:21:30 +0200 |
| commit | 6ac1deccf64e35de062ed960f84bd8a794d310d4 (patch) | |
| tree | 05bfb24b38c1f22fe8e0af43b7bab28c46432309 /addons | |
| parent | 99556240299a8350f7b73534056e19ed2b1b3b39 (diff) | |
[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
Diffstat (limited to 'addons')
| -rw-r--r-- | addons/mail/mail_followers.py | 9 | ||||
| -rw-r--r-- | addons/mail/tests/test_mail_features.py | 8 | ||||
| -rw-r--r-- | addons/website_mail/static/src/js/follow.js | 24 | ||||
| -rw-r--r-- | addons/website_mail/views/website_mail.xml | 3 | ||||
| -rw-r--r-- | addons/website_mail_group/models/mail_group.py | 36 | ||||
| -rw-r--r-- | addons/website_mail_group/views/website_mail_group.xml | 3 |
6 files changed, 59 insertions, 24 deletions
diff --git a/addons/mail/mail_followers.py b/addons/mail/mail_followers.py index 1e2c6c8d9e6..a4eee04a69c 100644 --- a/addons/mail/mail_followers.py +++ b/addons/mail/mail_followers.py @@ -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') diff --git a/addons/mail/tests/test_mail_features.py b/addons/mail/tests/test_mail_features.py index bea80b729a4..ff9ce5d82cc 100644 --- a/addons/mail/tests/test_mail_features.py +++ b/addons/mail/tests/test_mail_features.py @@ -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 diff --git a/addons/website_mail/static/src/js/follow.js b/addons/website_mail/static/src/js/follow.js index 18c36378328..a8b351efa6c 100644 --- a/addons/website_mail/static/src/js/follow.js +++ b/addons/website_mail/static/src/js/follow.js @@ -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'); }, }); diff --git a/addons/website_mail/views/website_mail.xml b/addons/website_mail/views/website_mail.xml index 3b6d1bb96d6..8e365c1aaf5 100644 --- a/addons/website_mail/views/website_mail.xml +++ b/addons/website_mail/views/website_mail.xml @@ -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" diff --git a/addons/website_mail_group/models/mail_group.py b/addons/website_mail_group/models/mail_group.py index 804785b66f9..a0d2c69d969 100644 --- a/addons/website_mail_group/models/mail_group.py +++ b/addons/website_mail_group/models/mail_group.py @@ -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) diff --git a/addons/website_mail_group/views/website_mail_group.xml b/addons/website_mail_group/views/website_mail_group.xml index 21f046fc70b..4742c65c346 100644 --- a/addons/website_mail_group/views/website_mail_group.xml +++ b/addons/website_mail_group/views/website_mail_group.xml @@ -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&field=image_small&id='+str(group['id'])" class="pull-left"/> |
