[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) <bedo@odoo.com>
This commit is contained in:
@@ -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:
|
||||
|
||||
@@ -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" <mail-to-blacklist@gmail.com>',
|
||||
'from': '"Mail to Blacklist Name" <mail-to-blacklist@gmail.com>',
|
||||
'subject': 'CV',
|
||||
'body': 'I want to apply to your company',
|
||||
})
|
||||
self.assertFalse(applicant.email_from)
|
||||
self.assertFalse(applicant.partner_id)
|
||||
|
||||
Reference in New Issue
Block a user