Feature/visa comment integration#33
Conversation
📝 WalkthroughWalkthroughRemoved a TODO from CommentMapper; restored default CSRF behavior in SecurityConfig; rewrote visa/details.html to adjust styling and switch comments to client-side JS POSTs with CSRF handling; added CommentController unit tests, CommentMapper unit tests, CommentService integration tests; CommentService now creates audit logs when comments are added. Changes
Sequence DiagramsequenceDiagram
participant Browser as Browser (Client)
participant JS as Comment Form JS
participant CSRF as CSRF Filter
participant Controller as CommentController
participant Service as CommentService
participant Audit as AuditService
participant DB as Database
Browser->>JS: User submits comment
JS->>JS: Read hidden CSRF token, build JSON body
JS->>Controller: POST /api/comments (JSON + CSRF header)
Controller->>CSRF: Validate token
CSRF-->>Controller: Token valid
Controller->>Service: createComment(CreateCommentDTO)
Service->>DB: Persist Comment entity (set visa, author)
DB-->>Service: Return persisted entity
Service->>Audit: createAuditLog(authorId, visaId, UPDATED, message)
Audit-->>Service: Audit record persisted
Service-->>Controller: CommentDTO
Controller-->>JS: HTTP 201 + CommentDTO
JS->>Browser: Prepend comment card, clear textarea, remove empty-state
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
🧹 Nitpick comments (1)
src/test/java/org/example/visacasemanagementsystem/comment/CommentMapperTest.java (1)
35-36: Comment label typo — should be// Act.The
// Arrangeon line 35 labels what is actually the Act step (the call tocommentMapper.toEntity(dto)). Minor consistency fix with the other tests in this file.✏️ Proposed fix
- // Arrange + // Act Comment result = commentMapper.toEntity(dto);🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/test/java/org/example/visacasemanagementsystem/comment/CommentMapperTest.java` around lines 35 - 36, The comment label in CommentMapperTest is incorrect: change the line comment before the call to commentMapper.toEntity(dto) from "// Arrange" to "// Act" so the test follows the Arrange-Act-Assert convention; update the comment adjacent to the call to CommentMapper#toEntity (the invocation comment in the test) to "// Act" for consistency with other tests.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In
`@src/main/java/org/example/visacasemanagementsystem/config/SecurityConfig.java`:
- Line 17: Remove the dead commented-out CSRF disable line in
SecurityConfig.java by deleting the commented fragment ".csrf(csrf ->
csrf.disable())" from the HttpSecurity configuration in the SecurityConfig class
so the file no longer contains the unused comment; keep CSRF enabled (no
behavior changes needed for Thymeleaf forms or tests like
VisaViewControllerTest.java).
In `@src/main/resources/templates/visa/details.html`:
- Line 305: The inline style on the element using style="animation: fadeIn
0.5s;" references an undefined animation name "fadeIn" on the .comment-card;
either add a corresponding `@keyframes` fadeIn rule to the template's <style>
block (defining from/to or 0%/100% opacity/transform for the desired effect) or
remove the inline animation attribute; locate the .comment-card element and
update the template's CSS to include `@keyframes` fadeIn with the chosen animation
steps so the animation actually runs.
- Around line 304-312: The injected HTML construction using newCommentHtml and
container.insertAdjacentHTML is vulnerable because comment.text and
comment.authorName are user-controlled; replace this pattern by building the
comment DOM with createElement (e.g., create a div.comment-card, child
div.comment-meta and div.comment-text), set authorName and text via textContent
(or use Node.textContent) instead of interpolating into a string, then insert
the constructed node with container.insertBefore/append or container.prepend;
alternatively ensure proper escaping of comment.text and comment.authorName
before calling insertAdjacentHTML if you must keep string insertion.
---
Nitpick comments:
In
`@src/test/java/org/example/visacasemanagementsystem/comment/CommentMapperTest.java`:
- Around line 35-36: The comment label in CommentMapperTest is incorrect: change
the line comment before the call to commentMapper.toEntity(dto) from "//
Arrange" to "// Act" so the test follows the Arrange-Act-Assert convention;
update the comment adjacent to the call to CommentMapper#toEntity (the
invocation comment in the test) to "// Act" for consistency with other tests.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 51419547-5454-4004-b598-165b031249db
📒 Files selected for processing (6)
src/main/java/org/example/visacasemanagementsystem/comment/mapper/CommentMapper.javasrc/main/java/org/example/visacasemanagementsystem/config/SecurityConfig.javasrc/main/resources/templates/visa/details.htmlsrc/test/java/org/example/visacasemanagementsystem/comment/CommentControllerTest.javasrc/test/java/org/example/visacasemanagementsystem/comment/CommentMapperTest.javasrc/test/java/org/example/visacasemanagementsystem/comment/CommentServiceIntegrationTest.java
💤 Files with no reviewable changes (1)
- src/main/java/org/example/visacasemanagementsystem/comment/mapper/CommentMapper.java
|
|
||
| const container = document.getElementById('commentContainer'); | ||
| const newCommentHtml = ` | ||
| <div class="comment-card" style="animation: fadeIn 0.5s;"> |
There was a problem hiding this comment.
fadeIn animation has no @keyframes rule.
style="animation: fadeIn 0.5s" references an animation that isn't defined anywhere in the inline stylesheet, so nothing visible will happen. Either add a @keyframes fadeIn rule to the <style> block or drop the inline animation.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@src/main/resources/templates/visa/details.html` at line 305, The inline style
on the element using style="animation: fadeIn 0.5s;" references an undefined
animation name "fadeIn" on the .comment-card; either add a corresponding
`@keyframes` fadeIn rule to the template's <style> block (defining from/to or
0%/100% opacity/transform for the desired effect) or remove the inline animation
attribute; locate the .comment-card element and update the template's CSS to
include `@keyframes` fadeIn with the chosen animation steps so the animation
actually runs.
EdvinSandgren
left a comment
There was a problem hiding this comment.
Verkar fungera bra!
Martin-E-Karlsson
left a comment
There was a problem hiding this comment.
Ser bra ut!
Om det inte finns konflikter är vi nog redo för merge.
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In
`@src/main/java/org/example/visacasemanagementsystem/comment/service/CommentService.java`:
- Around line 69-73: The audit entry is being attributed using the DTO-supplied
author id (author resolved from dto.authorId()), which allows forging; in
CommentService where you call auditService.createAuditLog(...) and build the
Comment author, stop trusting dto.authorId(): resolve the actor/user from the
authenticated principal (e.g., from SecurityContextHolder or your injected
AuthenticationService) once and use that same principal-derived User instance
for both the Comment author and the auditService.createAuditLog(...) call (pass
principal.getId() and principal.getFullName()), and ignore or validate
dto.authorId() against the authenticated user instead of using it directly.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 9ddf8f93-ceda-4548-b42b-fb012574dd7e
📒 Files selected for processing (1)
src/main/java/org/example/visacasemanagementsystem/comment/service/CommentService.java
| auditService.createAuditLog( | ||
| author.getId (), | ||
| visa.getId (), | ||
| AuditEventType.UPDATED, | ||
| "Comment added by " + author.getFullName() |
There was a problem hiding this comment.
Do not build audit attribution from the DTO-supplied author id.
author is resolved from dto.authorId(), so this new audit entry can be forged by posting another user’s id. Since the audit log is now security-sensitive, resolve the actor from the authenticated principal and use that same principal-derived user for both the comment author and createAuditLog.
Suggested direction
- auditService.createAuditLog(
- author.getId (),
+ auditService.createAuditLog(
+ authenticatedUser.getId(),
visa.getId (),
AuditEventType.UPDATED,
- "Comment added by " + author.getFullName()
+ "Comment added by " + authenticatedUser.getFullName()
);Based on learnings, once Spring Security is added, the author should be resolved from the authenticated principal rather than from dto.authorId().
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In
`@src/main/java/org/example/visacasemanagementsystem/comment/service/CommentService.java`
around lines 69 - 73, The audit entry is being attributed using the DTO-supplied
author id (author resolved from dto.authorId()), which allows forging; in
CommentService where you call auditService.createAuditLog(...) and build the
Comment author, stop trusting dto.authorId(): resolve the actor/user from the
authenticated principal (e.g., from SecurityContextHolder or your injected
AuthenticationService) once and use that same principal-derived User instance
for both the Comment author and the auditService.createAuditLog(...) call (pass
principal.getId() and principal.getFullName()), and ignore or validate
dto.authorId() against the authenticated user instead of using it directly.
Summary by CodeRabbit
New Features
Improvements
Security
Tests
Chores