[IMP] mail_restrict_follower_selection: Adding tests and improving pre-commit
This commit is contained in:
parent
d6cc4a8aa9
commit
9b95ddd50c
@ -35,11 +35,10 @@ class MailFollowers(models.Model):
|
|||||||
existing_policy=existing_policy,
|
existing_policy=existing_policy,
|
||||||
)
|
)
|
||||||
domain = self.env[
|
domain = self.env[
|
||||||
'mail.wizard.invite'
|
"mail.wizard.invite"
|
||||||
]._mail_restrict_follower_selection_get_domain(res_model=res_model)
|
]._mail_restrict_follower_selection_get_domain(res_model=res_model)
|
||||||
partners = self.env['res.partner'].search(
|
partners = self.env["res.partner"].search(
|
||||||
[('id', 'in', partner_ids)] +
|
[("id", "in", partner_ids)] + safe_eval(domain)
|
||||||
safe_eval(domain)
|
|
||||||
)
|
)
|
||||||
_res_ids = res_ids.copy() or [0]
|
_res_ids = res_ids.copy() or [0]
|
||||||
new, update = super()._add_followers(
|
new, update = super()._add_followers(
|
||||||
|
@ -13,13 +13,17 @@ class MailWizardInvite(models.TransientModel):
|
|||||||
@api.model
|
@api.model
|
||||||
def _mail_restrict_follower_selection_get_domain(self, res_model=None):
|
def _mail_restrict_follower_selection_get_domain(self, res_model=None):
|
||||||
if not res_model:
|
if not res_model:
|
||||||
res_model = self.env.context.get('default_res_model')
|
res_model = self.env.context.get("default_res_model")
|
||||||
parameter_name = 'mail_restrict_follower_selection.domain'
|
parameter_name = "mail_restrict_follower_selection.domain"
|
||||||
return self.env['ir.config_parameter'].sudo().get_param(
|
return (
|
||||||
"{0}.{1}".format(parameter_name,
|
self.env["ir.config_parameter"]
|
||||||
res_model),
|
.sudo()
|
||||||
self.env['ir.config_parameter'].sudo().get_param(
|
.get_param(
|
||||||
parameter_name, default='[]')
|
"{}.{}".format(parameter_name, res_model),
|
||||||
|
self.env["ir.config_parameter"]
|
||||||
|
.sudo()
|
||||||
|
.get_param(parameter_name, default="[]"),
|
||||||
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
@api.model
|
@api.model
|
||||||
|
@ -64,3 +64,19 @@ class TestMailRestrictFollowerSelection(TransactionCase):
|
|||||||
self.assertNotIn(
|
self.assertNotIn(
|
||||||
self.partner, self.partner.message_follower_ids.mapped("partner_id")
|
self.partner, self.partner.message_follower_ids.mapped("partner_id")
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def test_message_add_suggested_recipient(self):
|
||||||
|
res = self.partner.with_context(
|
||||||
|
test_restrict_follower=True
|
||||||
|
)._message_add_suggested_recipient({self.partner.id: []}, partner=self.partner)
|
||||||
|
self.assertEqual(res[self.partner.id][0][0], self.partner.id)
|
||||||
|
self.env["ir.config_parameter"].create(
|
||||||
|
{
|
||||||
|
"key": "mail_restrict_follower_selection.domain.res.partner",
|
||||||
|
"value": "[('category_id.name', '!=', 'Employees')]",
|
||||||
|
}
|
||||||
|
)
|
||||||
|
new_res = self.partner.with_context(
|
||||||
|
test_restrict_follower=True
|
||||||
|
)._message_add_suggested_recipient({self.partner.id: []})
|
||||||
|
self.assertFalse(new_res[self.partner.id][0][0])
|
||||||
|
Loading…
Reference in New Issue
Block a user