Skip to content
Open
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
24 changes: 24 additions & 0 deletions spp_audit/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,30 @@ External Python: ``requests`` (HTTP backend)
Changelog
=========

19.0.2.0.4
~~~~~~~~~~

- fix: ``audit_disable`` is honoured only when server-side code sets it
to the ``AUDIT_DISABLE`` marker
(``from odoo.addons.spp_audit.tools import AUDIT_DISABLE``;
``records.with_context(audit_disable=AUDIT_DISABLE)``). A plain value
such as ``True`` no longer skips audit logging, so flows that relied
on it are audited again until they pass the marker.
- fix: a write made inside an audited write is now audited when it
touches other records (for example a child record updated through its
parent's one2many field, or values synced to related records). Only
the records already being audited by the enclosing write are skipped,
so the same change is not logged twice. Expect more audit log rows for
such writes. The ``audit_in_progress`` context key is no longer read.

19.0.2.0.3
~~~~~~~~~~

- fix: mark the server-internal audit methods ``@api.private`` — backend
``write_entry`` / ``is_enabled`` and the rule's ``log``,
``log_lifecycle_action``, ``get_audit_rules``; server-side callers are
unaffected

19.0.2.0.2
~~~~~~~~~~

Expand Down
2 changes: 1 addition & 1 deletion spp_audit/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"name": "OpenSPP Audit",
"summary": "Comprehensively tracks all data modifications and user actions across the OpenSPP platform, recording old and new values for configured data. It enhances accountability and data integrity by maintaining an immutable history of changes, crucial for internal audits, compliance, and detecting unauthorized alterations. Supports multiple backends (database, file, syslog, HTTP) with tamper-resistant configuration.",
"category": "OpenSPP/Monitoring",
"version": "19.0.2.0.2",
"version": "19.0.2.0.4",
"sequence": 1,
"author": "OpenSPP.org",
"website": "https://github.com/OpenSPP/OpenSPP2",
Expand Down
13 changes: 13 additions & 0 deletions spp_audit/models/spp_audit_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,16 @@ class SppAuditBackend(models.AbstractModel):

Subclasses must implement _write_entry() to handle the actual
storage of audit entries.

Backend methods are private: they are for trusted server code only and
are not RPC-dispatchable.
"""

_name = "spp.audit.backend"
_description = "Abstract Audit Backend"

@api.model
@api.private
def write_entry(self, entry, env=None):
"""Write an audit entry to this backend.

Expand All @@ -144,6 +148,7 @@ def write_entry(self, entry, env=None):
raise NotImplementedError("Subclasses must implement write_entry()")

@api.model
@api.private
def is_enabled(self, env=None):
"""Check if this backend is enabled."""
raise NotImplementedError("Subclasses must implement is_enabled()")
Expand All @@ -157,10 +162,12 @@ class SppAuditBackendDb(models.AbstractModel):
_description = "Database Audit Backend"

@api.model
@api.private
def is_enabled(self, env=None):
return AuditConfig.get_bool("backend_db", env=env)

@api.model
@api.private
def write_entry(self, entry, env=None):
"""Write audit entry to database.

Expand Down Expand Up @@ -188,6 +195,7 @@ class SppAuditBackendFile(models.AbstractModel):
_current_date = None

@api.model
@api.private
def is_enabled(self, env=None):
return AuditConfig.get_bool("backend_file", env=env)

Expand Down Expand Up @@ -237,6 +245,7 @@ def _get_file_handle(cls, env=None):
return cls._file_handle

@api.model
@api.private
def write_entry(self, entry, env=None):
"""Write audit entry to JSONL file."""
try:
Expand Down Expand Up @@ -265,6 +274,7 @@ class SppAuditBackendSyslog(models.AbstractModel):
_syslog_initialized = False

@api.model
@api.private
def is_enabled(self, env=None):
return AuditConfig.get_bool("backend_syslog", env=env)

Expand Down Expand Up @@ -293,6 +303,7 @@ def _init_syslog(cls, env=None):
cls._syslog_initialized = True

@api.model
@api.private
def write_entry(self, entry, env=None):
"""Write audit entry to syslog."""
try:
Expand All @@ -317,6 +328,7 @@ class SppAuditBackendHttp(models.AbstractModel):
_description = "HTTP Webhook Audit Backend"

@api.model
@api.private
def is_enabled(self, env=None):
if not AuditConfig.get_bool("backend_http", env=env):
return False
Expand All @@ -325,6 +337,7 @@ def is_enabled(self, env=None):
return bool(endpoint)

@api.model
@api.private
def write_entry(self, entry, env=None):
"""Write audit entry to HTTP endpoint."""
endpoint = AuditConfig.get("http_endpoint", env=env)
Expand Down
9 changes: 9 additions & 0 deletions spp_audit/models/spp_audit_rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,10 +225,13 @@ def _process_action_id(self):
return

@api.model
@api.private
def get_audit_rules(self, method):
"""
The function returns audit rules based on the specified method.

Private: not RPC-dispatchable, on this model or on the audited models it is attached to.

:param method: The "method" parameter is a string that specifies the type of operation being
performed. It can have one of the following values: "create", "write", or "unlink"
:return: The method is returning a search result of "spp.audit.rule" records based on the
Expand Down Expand Up @@ -526,10 +529,13 @@ def get_audit_log_vals(self, res_id, method, data):
"parent_res_ids_str": ",".join(parent_res_ids),
}

@api.private
def log(self, method, old_values=None, new_values=None):
"""
Log changes made to a model's records by dispatching to all enabled backends.

Private: for server-side callers only, not RPC-dispatchable.

:param method: The operation type: "create", "write", "unlink", or lifecycle action
:param old_values: Dict of previous field values
:param new_values: Dict of updated field values
Expand Down Expand Up @@ -572,12 +578,15 @@ def log(self, method, old_values=None, new_values=None):
)

@api.model
@api.private
def log_lifecycle_action(self, model_name, record_id, action, old_values=None, new_values=None):
"""Log a lifecycle action for a record.

This is called explicitly from models (not via decorator).
Used for activate/deactivate/approve/reject/set_draft/download/preview/export actions.

Private: for server-side callers only, not RPC-dispatchable.

:param model_name: Technical model name (e.g., 'spp.studio.field')
:param record_id: ID of the record being logged
:param action: Action type - 'activate', 'deactivate', 'set_draft', 'approve', 'reject',
Expand Down
9 changes: 9 additions & 0 deletions spp_audit/readme/HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
### 19.0.2.0.4

- fix: `audit_disable` is honoured only when server-side code sets it to the `AUDIT_DISABLE` marker (`from odoo.addons.spp_audit.tools import AUDIT_DISABLE`; `records.with_context(audit_disable=AUDIT_DISABLE)`). A plain value such as `True` no longer skips audit logging, so flows that relied on it are audited again until they pass the marker.
- fix: a write made inside an audited write is now audited when it touches other records (for example a child record updated through its parent's one2many field, or values synced to related records). Only the records already being audited by the enclosing write are skipped, so the same change is not logged twice. Expect more audit log rows for such writes. The `audit_in_progress` context key is no longer read.

### 19.0.2.0.3

- fix: mark the server-internal audit methods `@api.private` — backend `write_entry` / `is_enabled` and the rule's `log`, `log_lifecycle_action`, `get_audit_rules`; server-side callers are unaffected

### 19.0.2.0.2

- feat: `audit_disable` context key lets trusted machine flows (e.g. cross-instance replication of records already audited at their source) bypass audit logging and its full-record snapshot reads in create/write/unlink
Expand Down
30 changes: 28 additions & 2 deletions spp_audit/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,32 @@ <h2><a class="toc-backref" href="#toc-entry-1">Changelog</a></h2>
</div>
</div>
<div class="section" id="section-1">
<h1>19.0.2.0.4</h1>
<ul class="simple">
<li>fix: <tt class="docutils literal">audit_disable</tt> is honoured only when server-side code sets it
to the <tt class="docutils literal">AUDIT_DISABLE</tt> marker
(<tt class="docutils literal">from odoo.addons.spp_audit.tools import AUDIT_DISABLE</tt>;
<tt class="docutils literal">records.with_context(audit_disable=AUDIT_DISABLE)</tt>). A plain value
such as <tt class="docutils literal">True</tt> no longer skips audit logging, so flows that relied
on it are audited again until they pass the marker.</li>
<li>fix: a write made inside an audited write is now audited when it
touches other records (for example a child record updated through its
parent’s one2many field, or values synced to related records). Only
the records already being audited by the enclosing write are skipped,
so the same change is not logged twice. Expect more audit log rows for
such writes. The <tt class="docutils literal">audit_in_progress</tt> context key is no longer read.</li>
</ul>
</div>
<div class="section" id="section-2">
<h1>19.0.2.0.3</h1>
<ul class="simple">
<li>fix: mark the server-internal audit methods <tt class="docutils literal">&#64;api.private</tt> — backend
<tt class="docutils literal">write_entry</tt> / <tt class="docutils literal">is_enabled</tt> and the rule’s <tt class="docutils literal">log</tt>,
<tt class="docutils literal">log_lifecycle_action</tt>, <tt class="docutils literal">get_audit_rules</tt>; server-side callers are
unaffected</li>
</ul>
</div>
<div class="section" id="section-3">
<h1>19.0.2.0.2</h1>
<ul class="simple">
<li>feat: <tt class="docutils literal">audit_disable</tt> context key lets trusted machine flows (e.g.
Expand All @@ -529,7 +555,7 @@ <h1>19.0.2.0.2</h1>
per-record searches) on every create/write of an audited model</li>
</ul>
</div>
<div class="section" id="section-2">
<div class="section" id="section-4">
<h1>19.0.2.0.1</h1>
<ul class="simple">
<li>fix: use &#64;api.model_create_multi for audit_create to support Odoo 19
Expand All @@ -542,7 +568,7 @@ <h1>19.0.2.0.1</h1>
<tt class="docutils literal">parent_data_html</tt> fields to prevent stored XSS (#50)</li>
</ul>
</div>
<div class="section" id="section-3">
<div class="section" id="section-5">
<h1>19.0.2.0.0</h1>
<ul class="simple">
<li>Initial migration to OpenSPP2</li>
Expand Down
2 changes: 2 additions & 0 deletions spp_audit/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from . import test_audit_backend
from . import test_audit_disable
from . import test_context_flags
from . import test_html_escaping
from . import test_rpc_exposure
from . import test_spp_audit_rule
10 changes: 7 additions & 3 deletions spp_audit/tests/test_audit_disable.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
from odoo import Command
from odoo.tests.common import TransactionCase

from ..tools import AUDIT_DISABLE


class AuditDisableCommon(TransactionCase):
"""Shared fixture: a res.partner audit rule with all methods logged."""
Expand Down Expand Up @@ -57,7 +59,9 @@ class TestAuditDisableContext(AuditDisableCommon):
def test_create_bypassed(self):
patcher, reads = self._classic_write_read_spy()
with patcher:
partner = self.env["res.partner"].with_context(audit_disable=True).create({"name": "Disable Create"})
partner = (
self.env["res.partner"].with_context(audit_disable=AUDIT_DISABLE).create({"name": "Disable Create"})
)
self.assertTrue(partner.exists())
self.assertFalse(self._logs(partner, "create"))
self.assertFalse(reads, "audit_disable must skip the full-record snapshot read on create")
Expand All @@ -66,7 +70,7 @@ def test_write_bypassed(self):
partner = self.env["res.partner"].create({"name": "Disable Write"})
patcher, reads = self._classic_write_read_spy()
with patcher:
partner.with_context(audit_disable=True).write({"name": "Disable Write Changed"})
partner.with_context(audit_disable=AUDIT_DISABLE).write({"name": "Disable Write Changed"})
self.assertEqual(partner.name, "Disable Write Changed")
self.assertFalse(self._logs(partner, "write"))
self.assertFalse(reads, "audit_disable must skip the full-record snapshot reads on write")
Expand All @@ -76,7 +80,7 @@ def test_unlink_bypassed(self):
partner_id = partner.id
patcher, reads = self._classic_write_read_spy()
with patcher:
partner.with_context(audit_disable=True).unlink()
partner.with_context(audit_disable=AUDIT_DISABLE).unlink()
self.assertFalse(partner.exists())
self.assertFalse(
self._logs(self.env["res.partner"].browse(partner_id), "unlink"),
Expand Down
Loading
Loading