fix: restrict journal access enforcement to write, create, and delete operations to prevent read errors
This commit is contained in:
parent
eceeef248d
commit
2ba3ca12eb
@ -40,7 +40,7 @@ class AccountJournal(models.Model):
|
|||||||
def check_access_rule(self, operation):
|
def check_access_rule(self, operation):
|
||||||
"""
|
"""
|
||||||
Overridden to bypass multi-company record rules for allowed journals,
|
Overridden to bypass multi-company record rules for allowed journals,
|
||||||
and enforce the allowed journals restriction for all operations.
|
and enforce the allowed journals restriction for write, create, and delete operations.
|
||||||
"""
|
"""
|
||||||
if self.env.su:
|
if self.env.su:
|
||||||
return super(AccountJournal, self).check_access_rule(operation)
|
return super(AccountJournal, self).check_access_rule(operation)
|
||||||
@ -48,11 +48,16 @@ class AccountJournal(models.Model):
|
|||||||
user = self.env.user
|
user = self.env.user
|
||||||
allowed_journals = user.sudo().allowed_journal_ids
|
allowed_journals = user.sudo().allowed_journal_ids
|
||||||
if allowed_journals:
|
if allowed_journals:
|
||||||
# Enforce restriction: all records in self MUST be in allowed_journal_ids
|
# Enforce restriction for write, create, and delete operations.
|
||||||
if not all(j.id in allowed_journals.ids for j in self):
|
# Read operations are allowed to prevent access errors when loading
|
||||||
raise AccessError(_("You do not have access to this journal."))
|
# documents (payments/moves) referencing other journals.
|
||||||
# If all records in self are allowed, bypass standard record rules
|
if operation in ('write', 'create', 'unlink'):
|
||||||
return
|
if not all(j.id in allowed_journals.ids for j in self):
|
||||||
|
raise AccessError(_("You do not have access to this journal."))
|
||||||
|
|
||||||
|
# If all records in self are allowed, bypass standard record rules.
|
||||||
|
if all(j.id in allowed_journals.ids for j in self):
|
||||||
|
return
|
||||||
|
|
||||||
return super(AccountJournal, self).check_access_rule(operation)
|
return super(AccountJournal, self).check_access_rule(operation)
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user