Skip to content

fix(notifications): dedupe marketing_consent audit (#182)#185

Open
b3lz3but wants to merge 1 commit intocaptainpragmatic:masterfrom
b3lz3but:fix/consent-audit-dedup
Open

fix(notifications): dedupe marketing_consent audit (#182)#185
b3lz3but wants to merge 1 commit intocaptainpragmatic:masterfrom
b3lz3but:fix/consent-audit-dedup

Conversation

@b3lz3but
Copy link
Copy Markdown
Contributor

@b3lz3but b3lz3but commented May 8, 2026

Summary

Test plan

  • pytest tests/notifications/test_unsubscribe_tokens.py — 26 passed (includes new test_single_compliance_record_per_consent_flip acceptance test).
  • mypy apps/customers/signals.py apps/notifications/services.py — clean.
  • ruff check — clean.
  • Verified pre-existing failures in tests/customers/ are unrelated (django_fsm Direct status modification, Romanian IBAN) — same failures on master.
  • Reviewer: confirm reporting tools that count consent changes still work after dropping AuditEvent rows for marketing_consent_* actions on Customer (User.accepts_marketing path is unaffected — separate signal in apps/audit/signals.py).

🤖 Generated with Claude Code

)

Marketing-consent changes on Customer were producing two audit records:
the post_save signal (log_compliance_event) plus a service-layer
log_simple_event added in PR captainpragmatic#162 to capture source attribution.

Thread the source through the signal via instance._consent_source (and
_consent_category for unsubscribe paths), drop the service-layer call.
The signal is now the single audit writer for every Customer mutation
path — including admin actions, fixtures, and direct Customer.save() —
with origin recorded in evidence ("preference_center" / "unsubscribe_link"
/ "system" fallback for ad-hoc callers).

Acceptance test (test_single_compliance_record_per_consent_flip)
verifies exactly one ComplianceLog row per consent flip with source
attribution. Existing audit-failure tests collapsed to the single
remaining path.
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.

1 participant