[FIX] mail_plugin: do not allow to create a partner from notification email

Purpose
=======
When an email is opened and is from the default notification mechanism,
i.e: coming from something like "notifications@mail.odoo.com", we don't
want to try to match the email address to an existing contact partner.

Instead, we now display a custom message on the mail addon side
mentioning to search the contact manually.

Task-3557545

closes odoo/odoo#148073

X-original-commit: 9ff0815e258160f0eca595e0c3cce4b005e79eea
Signed-off-by: Warnon Aurélien (awa) <awa@odoo.com>
This commit is contained in:
std-odoo
2024-01-05 09:12:50 +00:00
parent b6ffd728fe
commit df218ad58a
3 changed files with 48 additions and 0 deletions
@@ -153,6 +153,18 @@ class MailPluginController(http.Controller):
if not normalized_email:
return {'error': _('Bad Email.')}
notification_emails = request.env['mail.alias.domain'].sudo().search([]).mapped('default_from_email')
if normalized_email in notification_emails:
return {
'partner': {
'name': _('Notification'),
'email': normalized_email,
'enrichment_info': {
'type': 'odoo_custom_error', 'info': _('This is your notification address. Search the Contact manually to link this email to a record.'),
},
},
}
# Search for the partner based on the email.
# If multiple are found, take the first one.
partner = request.env['res.partner'].search(['|', ('email', 'in', [normalized_email, email]),
@@ -215,6 +227,9 @@ class MailPluginController(http.Controller):
params name: name of the new partner
params company: parent company id of the new partner
"""
notification_emails = request.env['mail.alias.domain'].sudo().search([]).mapped('default_from_email')
if tools.email_normalize(email) in notification_emails:
raise Forbidden()
# old route name "/mail_client_extension/partner/create is deprecated as of saas-14.3,it is not needed for newer
# versions of the mail plugin but necessary for supporting older versions
# TODO search the company again instead of relying on the one provided here?
+14
View File
@@ -544,6 +544,13 @@ msgstr ""
msgid "Not enough credits to enrich."
msgstr ""
#. module: mail_plugin
#. odoo-python
#: code:addons/mail_plugin/controllers/mail_plugin.py:0
#, python-format
msgid "Notification"
msgstr ""
#. module: mail_plugin
#. odoo-javascript
#: code:addons/mail_plugin/static/src/to_translate/translations_gmail.xml:0
@@ -737,6 +744,13 @@ msgstr ""
msgid "This contact has no email address, no company could be enriched."
msgstr ""
#. module: mail_plugin
#. odoo-python
#: code:addons/mail_plugin/controllers/mail_plugin.py:0
#, python-format
msgid "This is your notification address. Search the Contact manually to link this email to a record."
msgstr ""
#. module: mail_plugin
#. odoo-python
#: code:addons/mail_plugin/controllers/mail_plugin.py:0
@@ -187,3 +187,22 @@ class TestMailPluginController(TestMailPluginControllerCommon):
)
second_company_id = result["partner"]["company"]["id"]
self.assertEqual(first_company_id, second_company_id, "Should not create a new company")
def test_get_partner_is_default_from(self):
"""When the email_from is the server default from address, we return a custom message instead of trying to match a partner record."""
self.env['mail.alias.domain'].create({'name': 'example.com', 'default_from': 'notification'})
mock_iap_enrich = Mock()
result = self.mock_plugin_partner_get("Test partner", "notificaTION@EXAMPLE.COM", mock_iap_enrich)
self.assertEqual(
result,
{
'partner': {
'name': 'Notification',
'email': 'notification@example.com',
'enrichment_info': {
'type': 'odoo_custom_error',
'info': 'This is your notification address. Search the Contact manually to link this email to a record.',
},
},
},
)