Skip to content

Commit

Permalink
Merge PR #2834 into 16.0
Browse files Browse the repository at this point in the history
Signed-off-by StefanRijnhart
  • Loading branch information
OCA-git-bot committed Feb 19, 2024
2 parents b7045fe + 8de1324 commit 4e8afe7
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 0 deletions.
3 changes: 3 additions & 0 deletions auditlog/models/rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,9 @@ def write_full(self, vals, **kwargs):
.with_context(prefetch_fields=False)
.read(fields_list)
}
# invalidate_recordset method must be called with existing fields
if self._name == "res.users":
vals = self._remove_reified_groups(vals)
# Prevent the cache of modified fields from being poisoned by
# x2many items inaccessible to the current user.
self.invalidate_recordset(vals.keys())
Expand Down
79 changes: 79 additions & 0 deletions auditlog/tests/test_auditlog.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from odoo.tests.common import Form, TransactionCase

from odoo.addons.base.models.ir_model import MODULE_UNINSTALL_FLAG
from odoo.addons.base.models.res_users import name_boolean_group


class AuditlogCommon(object):
Expand Down Expand Up @@ -612,3 +613,81 @@ def test_06_AuditlogFull_unlink_log(self):

# Removing auditlog_rule
self.auditlog_rule.unlink()


class AuditLogRuleTestForUserModel(TransactionCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
# get User model id
cls.user_model_id = cls.env["ir.model"].search([("model", "=", "res.users")]).id

# creating auditlog.rule
cls.auditlog_rule = (
cls.env["auditlog.rule"]
.with_context(tracking_disable=True)
.create(
{
"name": "testrule 01",
"model_id": cls.user_model_id,
"log_read": True,
"log_create": True,
"log_write": True,
"log_unlink": True,
"log_type": "full",
"capture_record": True,
}
)
)

# Subscribe auditlog.rule
cls.auditlog_rule.subscribe()

# Create user id
cls.user = (
cls.env["res.users"]
.with_context(no_reset_password=True, tracking_disable=True)
.create(
{
"name": "Test User",
"login": "testuser",
}
)
)
cls.group = cls.env.ref("auditlog.group_auditlog_manager")

cls.auditlog_log = cls.env["auditlog.log"]

def test_01_AuditlogFull_field_group_write_log(self):
"""Change group and check successfully created log"""
self.user.with_context(tracking_disable=True).write(
{"groups_id": [(4, self.group.id)]}
)
# Checking log is created for testpartner1
write_log_record = self.auditlog_log.search(
[
("model_id", "=", self.auditlog_rule.model_id.id),
("method", "=", "write"),
("res_id", "=", self.user.id),
]
).ensure_one()
self.assertTrue(write_log_record)

def test_02_AuditlogFull_field_group_write_log(self):
"""Change group and check successfully created log, but using reified fields"""
fname = name_boolean_group(self.group.id)

self.user.with_context(tracking_disable=True).write(
{
fname: True,
}
)
# Checking log is created for testpartner1
write_log_record = self.auditlog_log.search(
[
("model_id", "=", self.auditlog_rule.model_id.id),
("method", "=", "write"),
("res_id", "=", self.user.id),
]
).ensure_one()
self.assertTrue(write_log_record)

0 comments on commit 4e8afe7

Please sign in to comment.