Skip to content

Commit

Permalink
[4986][FIX] auditlog (#27)
Browse files Browse the repository at this point in the history
patch away all write overrides in res.groups for test
  • Loading branch information
nobuQuartile authored Jan 8, 2025
1 parent e35ac19 commit 36b2a4b
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 12 deletions.
2 changes: 1 addition & 1 deletion auditlog/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Audit Log
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:0385a1c291a9a1ec310581bad8ffc88b9e349dd77279970782c84a79d199b268
!! source digest: sha256:f28a63269e62794edbb3bcf4f78727dd623d0a973a1ac6055d88c7078668d842
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
Expand Down
2 changes: 1 addition & 1 deletion auditlog/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

{
"name": "Audit Log",
"version": "16.0.2.2.0",
"version": "16.0.2.2.2",
"author": "ABF OSIELL, Odoo Community Association (OCA)",
"license": "AGPL-3",
"website": "https://github.com/OCA/server-tools",
Expand Down
2 changes: 1 addition & 1 deletion auditlog/models/rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ def get_auditlog_fields(self, model):
return list(
n
for n, f in model._fields.items()
if (not f.compute and not f.related) or f.store
if (not f.compute and not f.related) or f.store or f.company_dependent
)

def _make_create(self):
Expand Down
13 changes: 8 additions & 5 deletions auditlog/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@

/*
:Author: David Goodger ([email protected])
:Id: $Id: html4css1.css 8954 2022-01-20 10:10:25Z milde $
:Id: $Id: html4css1.css 9511 2024-01-13 09:50:07Z milde $
:Copyright: This stylesheet has been placed in the public domain.
Default cascading style sheet for the HTML output of Docutils.
Despite the name, some widely supported CSS2 features are used.
See https://docutils.sourceforge.io/docs/howto/html-stylesheets.html for how to
customize this style sheet.
Expand Down Expand Up @@ -274,7 +275,7 @@
margin-left: 2em ;
margin-right: 2em }

pre.code .ln { color: grey; } /* line numbers */
pre.code .ln { color: gray; } /* line numbers */
pre.code, code { background-color: #eeeeee }
pre.code .comment, code .comment { color: #5C6576 }
pre.code .keyword, code .keyword { color: #3B0D06; font-weight: bold }
Expand All @@ -300,7 +301,7 @@
span.pre {
white-space: pre }

span.problematic {
span.problematic, pre.problematic {
color: red }

span.section-subtitle {
Expand Down Expand Up @@ -366,7 +367,7 @@ <h1 class="title">Audit Log</h1>
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:0385a1c291a9a1ec310581bad8ffc88b9e349dd77279970782c84a79d199b268
!! source digest: sha256:f28a63269e62794edbb3bcf4f78727dd623d0a973a1ac6055d88c7078668d842
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/server-tools/tree/16.0/auditlog"><img alt="OCA/server-tools" src="https://img.shields.io/badge/github-OCA%2Fserver--tools-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/server-tools-16-0/server-tools-16-0-auditlog"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/server-tools&amp;target_branch=16.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>This module allows the administrator to log user operations performed on data
Expand Down Expand Up @@ -461,7 +462,9 @@ <h2><a class="toc-backref" href="#toc-entry-7">Other credits</a></h2>
<div class="section" id="maintainers">
<h2><a class="toc-backref" href="#toc-entry-8">Maintainers</a></h2>
<p>This module is maintained by the OCA.</p>
<a class="reference external image-reference" href="https://odoo-community.org"><img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" /></a>
<a class="reference external image-reference" href="https://odoo-community.org">
<img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" />
</a>
<p>OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.</p>
Expand Down
84 changes: 84 additions & 0 deletions auditlog/tests/test_auditlog.py
Original file line number Diff line number Diff line change
Expand Up @@ -691,3 +691,87 @@ def test_02_AuditlogFull_field_group_write_log(self):
]
).ensure_one()
self.assertTrue(write_log_record)


class AuditLogRuleTestPartnerCompanyDependentFields(TransactionCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
# get Contact model id
cls.contact_model_id = (
cls.env["ir.model"].search([("model", "=", "res.partner")]).id
)

# creating auditlog.rule
cls.auditlog_rule = (
cls.env["auditlog.rule"]
.with_context(tracking_disable=True)
.create(
{
"name": "testrule 01",
"model_id": cls.contact_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()

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

# Creating new res.partner
cls.testpartner = (
cls.env["res.partner"]
.with_context(tracking_disable=True)
.create(
{
"name": "testpartner",
"barcode": "0000",
}
)
)

def test_01_AuditlogFull_company_dependent_field_create_log(self):
"""Checks that the changes in a company dependent field are tracked"""
create_log_record = self.auditlog_log.search(
[
("model_id", "=", self.auditlog_rule.model_id.id),
("method", "=", "create"),
("res_id", "=", self.testpartner.id),
]
).ensure_one()
self.assertTrue(create_log_record)
field_names = create_log_record.line_ids.mapped("field_name")

# Checking log lines created for barcode
self.assertTrue("barcode" in field_names)

# Removing created log record
create_log_record.unlink()

def test_02_AuditlogFull_company_dependent_field_write_log(self):
"""Checks that the changes in a company dependent field are tracked"""
self.testpartner.with_context(tracking_disable=True).write(
{
"barcode": "0001",
}
)
# 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.testpartner.id),
]
).ensure_one()
self.assertTrue(write_log_record)
field_names = write_log_record.line_ids.mapped("field_name")

# Checking log lines not created for phone
self.assertTrue("barcode" in field_names)
9 changes: 5 additions & 4 deletions auditlog/tests/test_multi_company.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
from unittest.mock import patch

from odoo.fields import Command
from odoo.models import BaseModel
from odoo.tests.common import TransactionCase

from odoo.addons.base.models.res_users import Groups


class TestMultiCompany(TransactionCase):
@classmethod
Expand Down Expand Up @@ -78,10 +77,12 @@ def write(self, vals):
present in the cache at this point, leading to the deletion of the
value from the company that is inaccessible to the current user.
"""
return super(Groups, self).write(vals)
return BaseModel.write(self, vals)

# Do the write.
with patch.object(Groups, "write", side_effect=write, autospec=True):
with patch.object(
self.env["res.groups"].__class__, "write", side_effect=write, autospec=True
):
group_with_user.write({"users": [Command.set(self.user2.ids)]})
self.assertEqual(group_with_user.users, self.user2)
# Ensure that the users of the other companies are still there.
Expand Down

0 comments on commit 36b2a4b

Please sign in to comment.