Skip to content
Closed
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,4 @@ docs/_build/

# OCA rules
!static/lib/
*.bak.*
65 changes: 36 additions & 29 deletions mail_tracking/models/mail_tracking_email.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,25 +139,29 @@ def write(self, vals):
self.mapped("mail_message_id").write({"mail_tracking_needs_action": True})
return res

@api.model
@api.model
@api.model
@api.model
def _search(
self,
domain,
offset=0,
limit=None,
order=None,
count=False,
access_rights_uid=None,
):
"""Override that adds specific access rights of mail.tracking.email, to remove
ids uid could not see according to our custom rules. Please refer to
_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
"""Odoo 18: count NICHT an super()._search geben; access_rights_uid korrekt anwenden."""
env_model = self.with_user(access_rights_uid) if access_rights_uid else self
if count:
return env_model.search_count(domain)
return super(MailTrackingEmail, env_model)._search(
domain,
offset=offset,
limit=limit,
order=order,
)

def _make_access_error(self, operation: str) -> AccessError:
return AccessError(
Expand Down Expand Up @@ -230,29 +234,33 @@ def _get_allowed_ids(self, ids):
(ids,),
)
)
result = self.env.cr.fetchall()
_, 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
)
# Only users from group_system can read mail.mail
result = self.env.cr.fetchall() or []

msg_ids, mail_ids, partner_ids = set(), set(), set()
for row in result:
if not row or len(row) < 4:
continue
_, mmsg, mmail, ptnr = row
if mmsg:
msg_ids.add(mmsg)
if mmail:
mail_ids.add(mmail)
if ptnr:
partner_ids.add(ptnr)

msg_ids = self.env["mail.message"].search([("id", "in", list(msg_ids))]).ids
if self.env.user.has_group("base.group_system"):
mail_ids = (
self.env["mail.mail"]
.search([("id", "in", [x for x in mail_ids if x])])
.ids
)
mail_ids = self.env["mail.mail"].search([("id", "in", list(mail_ids))]).ids
else:
mail_ids = []
partner_ids = (
self.env["res.partner"]
.search([("id", "in", [x for x in partner_ids if x])])
.ids
self.env["res.partner"].search([("id", "in", list(partner_ids))]).ids
)

for id_, mail_msg_id, mail_id, partner_id in result:
for row in result:
if not row or len(row) < 4:
continue
id_, mail_msg_id, mail_id, partner_id = row
if (
(mail_msg_id in msg_ids)
or (mail_id in mail_ids)
Expand All @@ -262,7 +270,6 @@ def _get_allowed_ids(self, ids):
allowed_ids.add(id_)
return allowed_ids

@api.model
def email_is_bounced(self, email):
if not email:
return False
Expand Down
Loading