feat(audit): add COMMENT_ADDED and MENTION_CREATED audit events
Some checks failed
CI / Unit & Component Tests (pull_request) Failing after 2m35s
CI / OCR Service Tests (pull_request) Successful in 39s
CI / Backend Unit Tests (pull_request) Failing after 2m54s
CI / Unit & Component Tests (push) Failing after 2m38s
CI / OCR Service Tests (push) Successful in 35s
CI / Backend Unit Tests (push) Failing after 2m47s
Some checks failed
CI / Unit & Component Tests (pull_request) Failing after 2m35s
CI / OCR Service Tests (pull_request) Successful in 39s
CI / Backend Unit Tests (pull_request) Failing after 2m54s
CI / Unit & Component Tests (push) Failing after 2m38s
CI / OCR Service Tests (push) Successful in 35s
CI / Backend Unit Tests (push) Failing after 2m47s
Instruments CommentService.postComment(), postBlockComment(), and replyToComment() to fire COMMENT_ADDED after each successful save and MENTION_CREATED once per mentioned user. The shared logCommentPosted() helper avoids duplicating the two-call pattern across all three post methods. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit was merged in pull request #275.
This commit is contained in:
@@ -19,4 +19,10 @@ public enum AuditKind {
|
||||
|
||||
/** Payload: {@code {"pageNumber": 3}} */
|
||||
ANNOTATION_CREATED,
|
||||
|
||||
/** Payload: {@code {"commentId": "uuid"}} */
|
||||
COMMENT_ADDED,
|
||||
|
||||
/** Payload: {@code {"commentId": "uuid", "mentionedUserId": "uuid"}} */
|
||||
MENTION_CREATED,
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package org.raddatz.familienarchiv.service;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.raddatz.familienarchiv.audit.AuditKind;
|
||||
import org.raddatz.familienarchiv.audit.AuditService;
|
||||
import org.raddatz.familienarchiv.dto.MentionDTO;
|
||||
import org.raddatz.familienarchiv.exception.DomainException;
|
||||
import org.raddatz.familienarchiv.exception.ErrorCode;
|
||||
@@ -12,6 +14,7 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
@@ -22,6 +25,7 @@ public class CommentService {
|
||||
private final CommentRepository commentRepository;
|
||||
private final UserService userService;
|
||||
private final NotificationService notificationService;
|
||||
private final AuditService auditService;
|
||||
|
||||
public List<DocumentComment> getCommentsForDocument(UUID documentId) {
|
||||
List<DocumentComment> roots =
|
||||
@@ -53,6 +57,7 @@ public class CommentService {
|
||||
DocumentComment saved = commentRepository.save(comment);
|
||||
withMentionDTOs(saved);
|
||||
notificationService.notifyMentions(mentionedUserIds, saved);
|
||||
logCommentPosted(author, documentId, saved, mentionedUserIds);
|
||||
return saved;
|
||||
}
|
||||
|
||||
@@ -70,6 +75,7 @@ public class CommentService {
|
||||
DocumentComment saved = commentRepository.save(comment);
|
||||
withMentionDTOs(saved);
|
||||
notificationService.notifyMentions(mentionedUserIds, saved);
|
||||
logCommentPosted(author, documentId, saved, mentionedUserIds);
|
||||
return saved;
|
||||
}
|
||||
|
||||
@@ -101,6 +107,7 @@ public class CommentService {
|
||||
participantIds.remove(author.getId());
|
||||
notificationService.notifyReply(saved, participantIds);
|
||||
notificationService.notifyMentions(mentionedUserIds, saved);
|
||||
logCommentPosted(author, documentId, saved, mentionedUserIds);
|
||||
return saved;
|
||||
}
|
||||
|
||||
@@ -171,6 +178,17 @@ public class CommentService {
|
||||
ErrorCode.COMMENT_NOT_FOUND, "Comment not found: " + commentId));
|
||||
}
|
||||
|
||||
private void logCommentPosted(AppUser author, UUID documentId, DocumentComment saved, List<UUID> mentionedUserIds) {
|
||||
UUID actorId = author != null ? author.getId() : null;
|
||||
String commentId = saved.getId().toString();
|
||||
auditService.logAfterCommit(AuditKind.COMMENT_ADDED, actorId, documentId, Map.of("commentId", commentId));
|
||||
if (mentionedUserIds != null) {
|
||||
mentionedUserIds.forEach(mentionedUserId ->
|
||||
auditService.logAfterCommit(AuditKind.MENTION_CREATED, actorId, documentId,
|
||||
Map.of("commentId", commentId, "mentionedUserId", mentionedUserId.toString())));
|
||||
}
|
||||
}
|
||||
|
||||
private String resolveAuthorName(AppUser author) {
|
||||
String first = author.getFirstName();
|
||||
String last = author.getLastName();
|
||||
|
||||
Reference in New Issue
Block a user