Skip to content

feat: activate @Audited AOP for declarative audit logging - #44

Merged
DavidHLP merged 1 commit into
mainfrom
feat/activate-audited-aop
May 17, 2026
Merged

feat: activate @Audited AOP for declarative audit logging#44
DavidHLP merged 1 commit into
mainfrom
feat/activate-audited-aop

Conversation

@DavidHLP

Copy link
Copy Markdown
Owner

Summary

  • Replace ~40 manual auditHelper.log() / auditHelper.logForUser() calls with @Audited annotations across 8 admin services
  • Add AuditContext ThreadLocal for old/new value capture from method bodies
  • Enhance @Audited with userIdFrom / entityIdFrom param extraction
  • Rewrite AuditAspect with exception handling, firstNonNull() fallback chain
  • Deprecate AuditHelper (forRemoval=false) — still usable for edge cases like bulk operations

Test plan

  • ./mvnw compile passes
  • ./mvnw test -Dtest=AuditContextTest — 11 tests pass
  • ./mvnw test -Dtest=AdminSubmissionServiceImplTest — 8 tests pass
  • Manual ban test — old/new values correctly captured in audit_logs table

🤖 Generated with Claude Code

Replace ~40 manual auditHelper.log() calls with @Audited annotations
across 8 admin services. Add AuditContext ThreadLocal for old/new
value capture, enhance @Audited with userIdFrom/entityIdFrom param
extraction, and rewrite AuditAspect with exception handling.
@DavidHLP
DavidHLP merged commit 071f1ec into main May 17, 2026
6 of 7 checks passed

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8e08b8a521

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +193 to 194
@Audited(action = AuditActionUtil.PIN_POST, entityType = AuditActionUtil.ENTITY_FORUM_POST, entityIdFrom = "id")
public void pinPost(String id) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Keep explicit audit logging for bulk forum actions

After this change, pinPost/unpinPost/lockPost/unlockPost/deletePost rely only on @Audited, but bulkAction invokes these methods from inside the same class. In Spring proxy-based AOP, that self-invocation bypasses the proxy, so the audit aspect does not run for bulk operations and those admin actions stop producing audit records.

Useful? React with 👍 / 👎.

}

@Override
@Audited(action = AuditActionUtil.FLAG_COMMENT, entityType = AuditActionUtil.ENTITY_COMMENT, userIdFrom = "id")

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Extract affected user ID from comment instead of method id

Using userIdFrom = "id" here maps the comment ID into the audit user_id field. This method already sets AuditContext.setUserId(comment.getAuthorId()/getUserId()), but the aspect prefers the annotation parameter first, so comment moderation logs will point to comment IDs rather than affected users, breaking user-centric audit queries.

Useful? React with 👍 / 👎.

}

@Override
@Audited(action = AuditActionUtil.REQUEUE_SUBMISSION, entityType = AuditActionUtil.ENTITY_SUBMISSION, userIdFrom = "id")

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Record submission ID as entityId in rejudge audits

This annotation currently sets userIdFrom = "id", so a submission ID is written as user_id, while entity_id becomes "N/A" because RejudgeResult exposes getSubmissionId() (not getId() for the aspect's reflection fallback). That regresses audit fidelity for rejudge events and makes submission-level filtering unreliable.

Useful? React with 👍 / 👎.

@DavidHLP
DavidHLP deleted the feat/activate-audited-aop branch May 17, 2026 07:05
DavidHLP added a commit that referenced this pull request Jul 3, 2026
Replace ~40 manual auditHelper.log() calls with @Audited annotations
across 8 admin services. Add AuditContext ThreadLocal for old/new
value capture, enhance @Audited with userIdFrom/entityIdFrom param
extraction, and rewrite AuditAspect with exception handling.
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