Skip to content

Add audit logs - #647

Open
varmar05 wants to merge 13 commits into
developfrom
audit_logs
Open

Add audit logs#647
varmar05 wants to merge 13 commits into
developfrom
audit_logs

Conversation

@varmar05

@varmar05 varmar05 commented Jul 1, 2026

Copy link
Copy Markdown
Collaborator

Introduce a pluggable audit module with NullSink default and emit() API.

Wire SQLAlchemy listeners for user and project lifecycle events, explicit emits for auth and sync endpoints (login, password, access grants/revocations, version push, soft/hard delete, restore).

Add actor_context()/request_context() helpers, device_id capture, scope_id for workspace-scoped filtering, and target_type auto-derivation.

Introduce a pluggable audit module with NullSink default and emit() API.

Wire SQLAlchemy listeners for user and project lifecycle events,
explicit emits for auth and sync endpoints (login, password, access
grants/revocations, version push, soft/hard delete, restore).

Add actor_context()/request_context() helpers, device_id capture, scope_id
for workspace-scoped filtering, and target_type auto-derivation.

This is groundwork for adding more events and to be extended in EE with custom sinks, query API, and retention policy.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@coveralls

coveralls commented Jul 1, 2026

Copy link
Copy Markdown

Coverage Report for CI Build 33164069128

Coverage increased (+0.3%) to 92.625%

Details

  • Coverage increased (+0.3%) from the base build.
  • Patch coverage: 15 uncovered changes across 6 files (587 of 602 lines covered, 97.51%).
  • 4 coverage regressions across 2 files.

Uncovered Changes

File Changed Covered %
server/mergin/utils.py 12 8 66.67%
server/mergin/audit/app.py 16 13 81.25%
server/mergin/audit/listeners.py 47 45 95.74%
server/mergin/auth/controller.py 31 29 93.55%
server/mergin/auth/listeners.py 35 33 94.29%
server/mergin/tests/test_audit_events.py 267 265 99.25%
Total (27 files) 602 587 97.51%

Coverage Regressions

4 previously-covered lines in 2 files lost coverage.

File Lines Losing Coverage Coverage
server/mergin/auth/controller.py 2 93.15%
server/mergin/sync/utils.py 2 85.4%

Coverage Stats

Coverage Status
Relevant Lines: 10943
Covered Lines: 10136
Line Coverage: 92.63%
Coverage Strength: 0.93 hits per line

💛 - Coveralls

varmar05 and others added 6 commits July 6, 2026 16:45
Implements structured audit event emission for all relevant user and project actions.
Update AuditEvent dataclass with new target columns: project_id, workspace_id and user_id.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…events

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Also simplify test_get_projects_by_uuids to avoid the fake-workspace-id hack.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@varmar05
varmar05 marked this pull request as ready for review July 30, 2026 07:25
@varmar05
varmar05 requested review from MarcelGeo and harminius and removed request for MarcelGeo July 30, 2026 07:25
… events

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@varmar05
varmar05 changed the base branch from master to develop July 30, 2026 08:03

@harminius harminius left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Some minor questions.

Comment thread server/mergin/auth/controller.py Outdated
Comment thread server/mergin/auth/controller.py
Comment thread server/mergin/auth/controller.py
Comment thread server/mergin/auth/controller.py
Comment thread server/mergin/auth/controller.py
Comment thread server/mergin/sync/private_api_controller.py
Comment thread server/mergin/sync/private_api_controller.py
Comment thread server/mergin/sync/private_api_controller.py Outdated
Comment thread server/mergin/sync/public_api_v2_controller.py
Comment thread server/mergin/sync/tasks.py Outdated
Comment thread .gitignore
Comment thread server/mergin/tests/utils.py
Comment thread server/mergin/sync/listeners.py
Comment thread server/mergin/sync/listeners.py Outdated
Comment thread server/mergin/sync/listeners.py Outdated
Comment thread server/mergin/sync/private_api_controller.py Outdated
Comment thread server/mergin/auth/controller.py
Comment thread server/mergin/audit/listeners.py Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants