Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 19 additions & 10 deletions mail_tracking/models/mail_tracking_email.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,14 @@ class MailTrackingEmail(models.Model):
partner_id = fields.Many2one(
string="Partner", comodel_name="res.partner", readonly=True
)
company_id = fields.Many2one(
string="Company",
comodel_name="res.company",
related="mail_message_id.record_company_id",
store=True,
readonly=True,
index=True,
)
recipient = fields.Char(string="Recipient email", readonly=True)
recipient_address = fields.Char(
string="Recipient email address",
Expand Down Expand Up @@ -152,12 +160,9 @@ def _search(
_check_access() for more details about those rules.
"""
query = super()._search(domain, offset, limit, order)
if not self.env.is_superuser():
records = self.browse(query)
allowed_ids = self._get_allowed_ids(records.ids)
return self.browse(allowed_ids)._as_query(order)

return query
records = self.browse(query)
allowed_ids = self._get_allowed_ids(records.ids)
return self.browse(allowed_ids)._as_query(order)

def _make_access_error(self, operation: str) -> AccessError:
return AccessError(
Expand Down Expand Up @@ -234,11 +239,15 @@ def _get_allowed_ids(self, ids):
msg_ids, mail_ids, partner_ids = [], [], []
if result:
_, msg_ids, mail_ids, partner_ids = zip(*result, strict=True)
msg_ids = (
self.env["mail.message"]
.search([("id", "in", [x for x in msg_ids if x])])
.ids
msg_ids = self.env["mail.message"].search(
[("id", "in", [x for x in msg_ids if x])]
)
active_company_id = self.env.company.id
msg_ids = msg_ids.filtered(
lambda msg: not msg.record_company_id
or msg.record_company_id.id == active_company_id
)
msg_ids = msg_ids.ids
# Only users from group_system can read mail.mail
if self.env.user.has_group("base.group_system"):
mail_ids = (
Expand Down
3 changes: 2 additions & 1 deletion mail_tracking/views/mail_tracking_email_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@
decoration-info="state == 'unsub'"
>
<field name="time" />
<field name="date" invisible="1" />
<field name="date" />
<field name="company_id" invisible="1" />
<field name="name" />
<field name="sender" string="Sender" />
<field name="recipient" string="Recipient" />
Expand Down
Loading