Skip to content

Migrate AuditLog to Dexterity and move audit log machinery to senaite.core - #2980

Merged
xispa merged 16 commits into
2.xfrom
refactor/auditlog-to-senaite-core
Sep 8, 2026
Merged

Migrate AuditLog to Dexterity and move audit log machinery to senaite.core#2980
xispa merged 16 commits into
2.xfrom
refactor/auditlog-to-senaite-core

Conversation

@ramonski

@ramonski ramonski commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Description of the issue/feature this PR addresses

The audit log / snapshot machinery still lived under the legacy bika.lims namespace, and the AuditLog container was still an Archetypes content type. This PR moves the whole audit log stack into senaite.core and replaces the Archetypes AuditLog folder with a Dexterity one that lives in the new SENAITE setup, alongside the other AT to DX migrations (Laboratory, Calculations, ...).

Backwards compatibility is preserved for add-ons (e.g. senaite.storage) via thin re-export shims at the old import locations.

Stacked on #2979 (this PR is based on that branch so the diff stays scoped). #2979 should be merged first, then this branch rebased onto 2.x.

Current behavior before PR

  • bika.lims.api.snapshot holds the snapshot storage and diff logic.
  • Audit log subscribers live in bika.lims.subscribers.auditlog.
  • The @@auditlog view and the site-wide audit log control panel live in bika.lims.browser / bika.lims.controlpanel.
  • AuditLog is an Archetypes ATFolder (bika.lims.controlpanel.auditlog), registered with a Factory-based FTI, and lives at bika_setup/auditlog. IAuditLog is defined in bika.lims.interfaces.

Desired behavior after PR is merged

  • Snapshot API moved to senaite.core.api.snapshot (re-export shim kept at bika.lims.api.snapshot).
  • Audit log subscribers moved to senaite.core.subscribers.auditlog and registered there.
  • @@auditlog view + auditlog_diff.pt moved to senaite.core.browser; the site-wide audit log control panel moved to senaite.core.browser.controlpanel.auditlog.
  • AuditLog is now a Dexterity content type (senaite.core.content.auditlog.AuditLog) with a Dexterity FTI; IAuditLog moved to senaite.core.interfaces (with a bika.lims.interfaces re-export so providedBy checks are unaffected).
  • The AuditLog folder now lives in the new SENAITE setup at setup/auditlog (next to Laboratory, Calculations, ...) instead of bika_setup/auditlog. Fresh installs create it there via the setup handler.
  • The site-wide "Audit Log" action now points to setup/auditlog. The per-object audit trail keeps using the explicit @@auditlog form; because BTreeFolder2 exposes contained items via __getattr__, traversal resolves the auditlog folder before the same-named per-object view, so setup/auditlog renders the global listing.

Migration

The AuditLog folder never holds content of its own; it only backs the listing view (the audit snapshots live as annotations on the audited objects and are looked up through the auditlog catalog, not through this folder). The upgrade step (2750 to 2751) therefore does not migrate any data: it removes the old bika_setup/auditlog folder and creates a fresh Dexterity AuditLog in the SENAITE setup.

A minimal Archetypes AuditLog stub is kept at bika.lims.controlpanel.auditlog so that folders persisted by earlier versions still load as regular objects (instead of unpickling as Broken ones, now that the real AT class is gone) and can be removed cleanly through the normal uncatalog/delete path. The remaining legacy AT classes will be dropped before 3.0.

Testing

  • Full ZCML load + senaite.core profile install succeed (this exercises the fresh-install creation of the DX AuditLog folder in the SENAITE setup).
  • bin/test-senaite -s senaite.core -t API_snapshot and -t Catalogs pass.
  • The ZODB upgrade step was verified against a restored production database that still had a legacy AT auditlog folder: the old folder is removed, the DX setup/auditlog is created, and the audit log listing renders at the new URL.

--
I confirm I have tested this PR thoroughly and coded it according to PEP8
and Plone's Python styleguide standards.

@ramonski
ramonski requested a review from xispa July 8, 2026 14:32
@ramonski ramonski added the Content Migration ♻️ Migrate contents to Dexterity label Jul 8, 2026
xispa and others added 2 commits July 8, 2026 22:58
…refactor/auditlog-to-senaite-core

# Conflicts:
#	src/senaite/core/upgrade/v02_07_000.zcml
@ramonski
ramonski marked this pull request as draft July 8, 2026 21:49
@ramonski
ramonski force-pushed the refactor/auditlog-to-senaite-core branch 2 times, most recently from 8dcb843 to 0426956 Compare July 9, 2026 05:52
The AuditLog folder only backs the listing view and holds no content of
its own; the audit snapshots live on the audited objects and are found
via the auditlog catalog. It is recreated rather than migrated: the old
bika_setup/auditlog folder is removed and a fresh DX folder is created at
setup/auditlog, and fresh installs create it alongside the other SENAITE
setup items.

A minimal AT AuditLog stub is kept at bika.lims.controlpanel.auditlog so
the legacy folder still loads as a regular object and deletes cleanly via
the normal uncatalog/delete path. The remaining AT classes will be
dropped before 3.0.

The global audit log action now points to setup/auditlog, while the
per-object audit trail keeps using @@auditlog, so traversal resolves the
contained folder first.
@ramonski
ramonski force-pushed the refactor/auditlog-to-senaite-core branch from 0426956 to 82ec6f3 Compare July 9, 2026 06:02
@ramonski
ramonski marked this pull request as ready for review July 9, 2026 06:18
Base automatically changed from fix/auditlog-diff-precise to 2.x July 14, 2026 10:27
…enaite-core

# Conflicts:
#	src/bika/lims/api/snapshot.py
#	src/bika/lims/browser/templates/auditlog_diff.pt
#	src/bika/lims/controlpanel/auditlog.py
#	src/senaite/core/profiles/default/metadata.xml
#	src/senaite/core/upgrade/v02_07_000.zcml
storage = annotation.get(SNAPSHOT_STORAGE)
if storage:
del(annotation[SNAPSHOT_STORAGE])
from senaite.core.api.snapshot import * # noqa: F401,F403

@xispa xispa left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Working well, thanks!

@xispa
xispa merged commit 2b95604 into 2.x Sep 8, 2026
4 checks passed
@xispa
xispa deleted the refactor/auditlog-to-senaite-core branch September 8, 2026 13:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Content Migration ♻️ Migrate contents to Dexterity

Development

Successfully merging this pull request may close these issues.

2 participants