Skip to content

[MODAUD-297] Implement user event consumer#240

Open
slaemmer wants to merge 3 commits intomasterfrom
MODAUD-297
Open

[MODAUD-297] Implement user event consumer#240
slaemmer wants to merge 3 commits intomasterfrom
MODAUD-297

Conversation

@slaemmer
Copy link
Contributor

@slaemmer slaemmer commented Feb 12, 2026

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.users Kafka 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):

  • UserConsumersVerticle subscribes to the users.users Kafka topic via pattern matching
  • UserEventHandler deserializes events, extracts tenant from Kafka headers, and delegates to the service layer. UNKNOWN event types are skipped; duplicate events (PK constraint violation) are handled idempotently
  • UserEventServiceImpl checks the USER_RECORDS_ENABLED setting before processing. For CREATED events it saves the audit record; for UPDATED events it computes a diff and only saves if fields actually changed; for DELETED events it cascade-deletes all audit history for that user
  • UserDiffCalculator extends DiffCalculator<User> to handle nested objects (personal info, metadata, tags, custom fields)
  • UserEventToEntityMapper maps the Kafka event to a UserAuditEntity, extracting performedBy from metadata (nullable for anonymized users)
  • User events wrap old/new data under data.old/data.new (vs inventory's top-level structure), handled by a @JsonSetter("data") method on UserEvent
  • New user_audit table with index on user_id, added via DB migration script

Pre-Merge Checklist:

Before merging this PR, please go through the following list and take appropriate actions.

  • Does this PR meet or exceed the expected quality standards?
    • Code coverage on new code is 80% or greater
    • Duplications on new code is 3% or less
    • There are no major code smells or security issues
  • Does this introduce breaking changes?
    • Were any API paths or methods changed, added or removed?
    • Were there any schema changes?
    • Did any of the interface versions change?
    • Were permissions changed, added, or removed?
    • Are there new interface dependencies?
    • There are no breaking changes in this PR.
    • Check logging

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
@sonarqubecloud
Copy link

@slaemmer slaemmer marked this pull request as ready for review February 13, 2026 07:07
@slaemmer slaemmer requested a review from a team February 13, 2026 07:07
@slaemmer slaemmer marked this pull request as draft February 13, 2026 12:34
@slaemmer slaemmer removed the request for review from a team February 13, 2026 12:45
…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.
@slaemmer slaemmer marked this pull request as ready for review February 13, 2026 14:04
@slaemmer slaemmer requested a review from a team February 13, 2026 14:05
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