diff --git a/models/__init__.py b/models/__init__.py index 4d63f95effbe23e3131105afa04ed9096c0f8253..24777f8ed7773441288eb09a2a925a50abf955eb 100644 --- a/models/__init__.py +++ b/models/__init__.py @@ -11,3 +11,4 @@ from . import res_partner_ministere from . import scop_liasse_fiscale from . import scop_models_lm from . import scop_partner_staff +from . import mail_tracking_email diff --git a/models/mail_tracking_email.py b/models/mail_tracking_email.py new file mode 100644 index 0000000000000000000000000000000000000000..eaf37ac3ceeb915e4011e847410cebc3762146be --- /dev/null +++ b/models/mail_tracking_email.py @@ -0,0 +1,43 @@ + +from odoo import models + + +class MailTrackingEmail(models.Model): + _inherit = "mail.tracking.email" + + def _find_allowed_tracking_ids(self): + """ + Override parent + TODO: delete afer merge PR https://github.com/OCA/social/pull/1128 + """ + # Admins passby this filter + if not self or self.env.user.has_group("base.group_system"): + return self.ids + # Override ORM to get the values directly + self._cr.execute( + """ + SELECT id, mail_message_id, partner_id + FROM mail_tracking_email WHERE id IN %s + """, + (tuple(self.ids),), + ) + msg_linked = self._cr.fetchall() + if not msg_linked: + return [] + _, msg_ids, partner_ids = zip(*msg_linked) + # Filter messages with their ACL rules avoiding False values fetched in the set + msg_ids = self.env["mail.message"]._search( + [("id", "in", [x for x in msg_ids if x])] + ) + partner_ids = self.env["res.partner"]._search( + [("id", "in", [x for x in partner_ids if x])] + ) + return [ + x[0] + for x in msg_linked + if (x[1] in msg_ids) # We can read the linked message + or ( + not any({x[1], x[2]}) and x[2] in partner_ids + ) # No linked msg/mail but we can read the linked partner + or (not any({x[1], x[2], x[2]})) # No linked record + ]