Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[16.0][FIX] audit_log: fix regression (Add/Remove User Group) #2834

Merged
Merged
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
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)
Loading