Open
Conversation
Enable audit tracking for mod-users changes so that administrators can review user record history. - Events from the users.users Kafka topic are consumed and stored in a new user_audit table - Field-level diffs are computed for updates - Deleting a user cascades to remove their audit history - Processing is gated by the USER_RECORDS_ENABLED setting
|
…s diffing Extend DiffCalculator to handle Javers MapChange events, suppressed by default to filter noise from jsonschema2pojo additionalProperties maps. UserDiffCalculator overrides this to process customFields, which uses additionalProperties to carry tenant-defined custom field data.
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.



Issue
MODAUD-297
Purpose
Implement a Kafka consumer for user domain events from mod-users to capture audit history for user record changes.
When user records are created, updated, or deleted in mod-users, change events are published to the
users.usersKafka topic. This PR adds the ability for mod-audit to consume those events, compute field-level diffs for updates, and persist audit records to a new user_audit table. This enables user change tracking alongside the existing inventory and acquisition audit capabilities.Approach
Follows the inventory audit consumer pattern (
AbstractConsumersVerticle>EventHandler>EventService>EventDao):UserConsumersVerticlesubscribes to theusers.usersKafka topic via pattern matchingUserEventHandlerdeserializes events, extracts tenant from Kafka headers, and delegates to the service layer.UNKNOWNevent types are skipped; duplicate events (PK constraint violation) are handled idempotentlyUserEventServiceImplchecks theUSER_RECORDS_ENABLEDsetting before processing. ForCREATEDevents it saves the audit record; forUPDATEDevents it computes a diff and only saves if fields actually changed; forDELETEDevents it cascade-deletes all audit history for that userUserDiffCalculatorextendsDiffCalculator<User>to handle nested objects (personal info, metadata, tags, custom fields)UserEventToEntityMappermaps the Kafka event to aUserAuditEntity, extractingperformedByfrom metadata (nullable for anonymized users)data.old/data.new(vs inventory's top-level structure), handled by a@JsonSetter("data")method onUserEventuser_audittable with index onuser_id, added via DB migration scriptPre-Merge Checklist:
Before merging this PR, please go through the following list and take appropriate actions.