fix(notifications): dedupe marketing_consent audit (#182)#185
Open
b3lz3but wants to merge 1 commit intocaptainpragmatic:masterfrom
Open
fix(notifications): dedupe marketing_consent audit (#182)#185b3lz3but wants to merge 1 commit intocaptainpragmatic:masterfrom
b3lz3but wants to merge 1 commit intocaptainpragmatic:masterfrom
Conversation
) 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
log_compliance_event+ service-layerlog_simple_eventfrom PR fix(notifications): atomicity, audit trail, and TOCTOU fixes for consent ops (#94) #162).instance._consent_source/_consent_category); drop the service-layer audit call.apps/customers/signals.py::_handle_marketing_consent_change, so every consent mutation path (admin, fixtures, imports, directCustomer.save()) is captured. Source falls back to"system"when not set.Test plan
pytest tests/notifications/test_unsubscribe_tokens.py— 26 passed (includes newtest_single_compliance_record_per_consent_flipacceptance test).mypy apps/customers/signals.py apps/notifications/services.py— clean.ruff check— clean.tests/customers/are unrelated (django_fsmDirect status modification, Romanian IBAN) — same failures on master.AuditEventrows formarketing_consent_*actions on Customer (User.accepts_marketing path is unaffected — separate signal inapps/audit/signals.py).🤖 Generated with Claude Code