From c02eb17aae97b41bd6e7a4d3a2dd5f6ec0a15f53 Mon Sep 17 00:00:00 2001 From: sofiagvaladze Date: Fri, 8 Mar 2024 15:39:35 +0100 Subject: [PATCH] [FIX] hr_recruitment: blacklist providers properly In https://github.com/odoo/odoo/pull/126065 we introduced the feature, that blacklists providers. The issue with it, is that even if we only provide email_from once we check it's not blacklisted [1], when we call the super method, email_from is still filled in [2] In order to correct it, we also delete blacklisted mail from msg_dict [1] - https://github.com/odoo/odoo/blob/aed0e74462b15085c09d9ab5ff029810f1238aeb/addons/hr_recruitment/models/hr_applicant.py#L615-L616 [2] -https://github.com/odoo/odoo/blob/aed0e74462b15085c09d9ab5ff029810f1238aeb/addons/mail/models/mail_thread.py#L1388-L1390 task-3793345 closes odoo/odoo#157107 Signed-off-by: Bertrand Dossogne (bedo) --- addons/hr_recruitment/models/hr_applicant.py | 7 +++++-- .../tests/test_recruitment_process.py | 20 +++++++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/addons/hr_recruitment/models/hr_applicant.py b/addons/hr_recruitment/models/hr_applicant.py index cd8f97f95f2..18b05892aab 100644 --- a/addons/hr_recruitment/models/hr_applicant.py +++ b/addons/hr_recruitment/models/hr_applicant.py @@ -413,7 +413,8 @@ class Applicant(models.Model): return res def _email_is_blacklisted(self, mail): - return mail in [m.strip() for m in self.env['ir.config_parameter'].sudo().get_param('hr_recruitment.blacklisted_emails', '').split(',')] + normalized_mail = tools.email_normalize(mail) + return normalized_mail in [m.strip() for m in self.env['ir.config_parameter'].sudo().get_param('hr_recruitment.blacklisted_emails', '').split(',')] def get_empty_list_help(self, help_message): if 'active_id' in self.env.context and self.env.context.get('active_model') == 'hr.job': @@ -610,10 +611,12 @@ class Applicant(models.Model): defaults = { 'name': msg.get('subject') or _("No Subject"), 'partner_name': partner_name or email_from_normalized, - 'partner_id': msg.get('author_id', False), } if msg.get('from') and not self._email_is_blacklisted(msg.get('from')): defaults['email_from'] = msg.get('from') + defaults['partner_id'] = msg.get('author_id', False) + if msg.get('email_from') and self._email_is_blacklisted(msg.get('email_from')): + del msg['email_from'] if msg.get('priority'): defaults['priority'] = msg.get('priority') if stage and stage.id: diff --git a/addons/hr_recruitment/tests/test_recruitment_process.py b/addons/hr_recruitment/tests/test_recruitment_process.py index 5cbaab8eef2..215d82da040 100644 --- a/addons/hr_recruitment/tests/test_recruitment_process.py +++ b/addons/hr_recruitment/tests/test_recruitment_process.py @@ -95,3 +95,23 @@ class TestRecruitmentProcess(TestHrCommon): self.assertTrue( user.partner_id in new_application_message.notified_partner_ids ) + + def test_blacklist_providers(self): + """Test blacklisting providers feature. + In case the mail comes from the blacklisted mails list, + we should not: + - set the email_from to the newly created applicant + - create an partner for the blaclisted mail and link it + with the newly created applicant + """ + self.env['ir.config_parameter'].set_param('hr_recruitment.blacklisted_emails', + 'bla@com.com, mail-to-blacklist@gmail.com, bla1@odoo.com') + applicant = self.env['hr.applicant'].message_new({ + 'message_id': 'message_id_for_rec', + 'email_from': '"Mail to Blacklist Name" ', + 'from': '"Mail to Blacklist Name" ', + 'subject': 'CV', + 'body': 'I want to apply to your company', + }) + self.assertFalse(applicant.email_from) + self.assertFalse(applicant.partner_id)