diff options
| author | David Beguin <dbe@odoo.com> | 2018-10-26 12:47:27 +0000 |
|---|---|---|
| committer | David Beguin <dbe@odoo.com> | 2018-11-20 11:37:05 +0000 |
| commit | fc2a8d63ee09053f12493683400ec424cab8ce16 (patch) | |
| tree | dd01ccecc2982d25c46cb12a19fd601be8c8c420 /addons | |
| parent | 0fe50a01d2d4969f2a4cf85c36c2884407ccc682 (diff) | |
[IMP] mail, mass_mailing, mass_mailing_crm : Use normalized email in unsubscribe link
Use the email_normalized from mail.address.mixin if available to get always
a normalized email address in the unsubscribe link. That allows to simplify
the search on email address in the controllers -> Check blacklist,
send feedback, etc..
Task ID 1896677
Diffstat (limited to 'addons')
| -rw-r--r-- | addons/mail/models/mail_thread.py | 2 | ||||
| -rw-r--r-- | addons/mass_mailing/controllers/main.py | 8 | ||||
| -rw-r--r-- | addons/mass_mailing/models/mass_mailing.py | 4 | ||||
| -rw-r--r-- | addons/mass_mailing/views/unsubscribe_templates.xml | 24 | ||||
| -rw-r--r-- | addons/mass_mailing_crm/models/__init__.py | 1 | ||||
| -rw-r--r-- | addons/mass_mailing_crm/models/crm_lead.py | 18 | ||||
| -rw-r--r-- | addons/test_mass_mailing/tests/test_performance.py | 2 |
7 files changed, 40 insertions, 19 deletions
diff --git a/addons/mail/models/mail_thread.py b/addons/mail/models/mail_thread.py index a4feb61b3fb..3149780e926 100644 --- a/addons/mail/models/mail_thread.py +++ b/addons/mail/models/mail_thread.py @@ -1695,6 +1695,8 @@ class MailThread(models.AbstractModel): recipient_ids, email_to, email_cc = set(), False, False if 'partner_id' in self._fields and record.partner_id: recipient_ids.add(record.partner_id.id) + elif 'email_normalized' in self._fields and record.email_normalized: + email_to = record.email_normalized elif 'email_from' in self._fields and record.email_from: email_to = record.email_from elif 'partner_email' in self._fields and record.partner_email: diff --git a/addons/mass_mailing/controllers/main.py b/addons/mass_mailing/controllers/main.py index 66d17709b46..9f703881c46 100644 --- a/addons/mass_mailing/controllers/main.py +++ b/addons/mass_mailing/controllers/main.py @@ -39,7 +39,7 @@ class MassMailController(http.Controller): # Unsubscribe directly + Let the user choose his subscriptions mailing.update_opt_out(email, mailing.contact_list_ids.ids, True) - contacts = request.env['mail.mass_mailing.contact'].sudo().search([('email_normalized', '=ilike', email)]) + contacts = request.env['mail.mass_mailing.contact'].sudo().search([('email_normalized', '=', email)]) subscription_list_ids = contacts.mapped('subscription_list_ids') # In many user are found : if user is opt_out on the list with contact_id 1 but not with contact_id 2, # assume that the user is not opt_out on both @@ -63,7 +63,7 @@ class MassMailController(http.Controller): }) else: opt_in_lists = request.env['mail.mass_mailing.list_contact_rel'].sudo().search([ - ('contact_id.email', '=', email), + ('contact_id.email_normalized', '=', email), ('opt_out', '=', False) ]).mapped('list_id') blacklist_rec = request.env['mail.blacklist'].sudo()._add(email) @@ -115,7 +115,7 @@ class MassMailController(http.Controller): if not self._valid_unsubscribe_token(mailing_id, res_id, email, token): return 'unauthorized' if email: - record = request.env['mail.blacklist'].sudo().with_context(active_test=False).search([('email', '=ilike', email)]) + record = request.env['mail.blacklist'].sudo().with_context(active_test=False).search([('email', '=', email)]) if record['active']: return True return False @@ -152,7 +152,7 @@ class MassMailController(http.Controller): if not self._valid_unsubscribe_token(mailing_id, res_id, email, token): return 'unauthorized' model = request.env[mailing.mailing_model_real] - records = model.sudo().search([('email_normalized', '=ilike', email)]) + records = model.sudo().search([('email_normalized', '=', email)]) for record in records: record.sudo().message_post(body=_("Feedback from %s: %s" % (email, feedback))) return bool(records) diff --git a/addons/mass_mailing/models/mass_mailing.py b/addons/mass_mailing/models/mass_mailing.py index 33c202a396b..3397acdfba5 100644 --- a/addons/mass_mailing/models/mass_mailing.py +++ b/addons/mass_mailing/models/mass_mailing.py @@ -282,7 +282,7 @@ class MassMailingContact(models.Model): @api.multi def message_get_default_recipients(self): - return dict((record.id, {'partner_ids': [], 'email_to': record.email, 'email_cc': False}) for record in self) + return dict((record.id, {'partner_ids': [], 'email_to': record.email_normalized, 'email_cc': False}) for record in self) class MassMailingStage(models.Model): @@ -646,7 +646,7 @@ class MassMailing(models.Model): def update_opt_out(self, email, list_ids, value): if len(list_ids) > 0: model = self.env['mail.mass_mailing.contact'].with_context(active_test=False) - records = model.search([('email', '=ilike', email)]) + records = model.search([('email_normalized', '=', email)]) opt_out_records = self.env['mail.mass_mailing.list_contact_rel'].search([ ('contact_id', 'in', records.ids), ('list_id', 'in', list_ids), diff --git a/addons/mass_mailing/views/unsubscribe_templates.xml b/addons/mass_mailing/views/unsubscribe_templates.xml index 9417aeef044..621119c35b6 100644 --- a/addons/mass_mailing/views/unsubscribe_templates.xml +++ b/addons/mass_mailing/views/unsubscribe_templates.xml @@ -71,18 +71,18 @@ <p>You have been successfully <strong>unsubscribed</strong>!</p> </div> - <div t-if="list_ids" class="alert alert-warning"> - <p class="text-center">You are currently subscribed to those newsletters. Unsubscribing means you will not receive any news from them anymore:</p> - <ul class="list-group mb-4"> - <t t-foreach="list_ids" t-as="list_id"> - <t t-if="list_id.is_public == True"> - <li class="list-group-item bg-transparent"> - <strong><t t-esc="list_id.name"/></strong> - </li> - </t> - </t> - </ul> - </div> + <div t-if="list_ids" class="alert alert-warning"> + <p class="text-center">You were still subscribed to those newsletters. You will not receive any news from them anymore:</p> + <ul class="list-group mb-4"> + <t t-foreach="list_ids" t-as="list_id"> + <t t-if="list_id.is_public == True"> + <li class="list-group-item bg-transparent"> + <strong><t t-esc="list_id.name"/></strong> + </li> + </t> + </t> + </ul> + </div> <div t-if="show_blacklist_button" class="mb64"> <div class="btn btn-secondary pull-right" id="button_add_blacklist" style="display:none">Blacklist Me</div> diff --git a/addons/mass_mailing_crm/models/__init__.py b/addons/mass_mailing_crm/models/__init__.py index 972aef5812b..1f42c79380d 100644 --- a/addons/mass_mailing_crm/models/__init__.py +++ b/addons/mass_mailing_crm/models/__init__.py @@ -2,3 +2,4 @@ # Part of Odoo. See LICENSE file for full copyright and licensing details. from . import mass_mailing +from . import crm_lead diff --git a/addons/mass_mailing_crm/models/crm_lead.py b/addons/mass_mailing_crm/models/crm_lead.py new file mode 100644 index 00000000000..ec9553d777c --- /dev/null +++ b/addons/mass_mailing_crm/models/crm_lead.py @@ -0,0 +1,18 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from odoo import api, models + + +class Lead(models.Model): + _name = "crm.lead" + _inherit = ['crm.lead'] + + @api.multi + def message_get_default_recipients(self): + return { + r.id : {'partner_ids': [], + 'email_to': r.email_normalized, + 'email_cc': False} + for r in self.sudo() + } diff --git a/addons/test_mass_mailing/tests/test_performance.py b/addons/test_mass_mailing/tests/test_performance.py index 8fc27fe8cfb..54f9df307b3 100644 --- a/addons/test_mass_mailing/tests/test_performance.py +++ b/addons/test_mass_mailing/tests/test_performance.py @@ -49,7 +49,7 @@ class TestMassMailPerformance(TestMassMailPerformanceBase): 'mailing_domain': [('id', 'in', self.mm_recs.ids)], }) - with self.assertQueryCount(__system__=2433, marketing=3089): + with self.assertQueryCount(__system__=2435, marketing=3091): mailing.send_mail() self.assertEqual(mailing.sent, 50) |
