Skip to content

Feature/visa comment integration#33

Merged
Martin-E-Karlsson merged 9 commits into
mainfrom
feature/visa-comment-integration
Apr 20, 2026
Merged

Feature/visa comment integration#33
Martin-E-Karlsson merged 9 commits into
mainfrom
feature/visa-comment-integration

Conversation

@eeebbaandersson

@eeebbaandersson eeebbaandersson commented Apr 18, 2026

Copy link
Copy Markdown
Contributor

Summary by CodeRabbit

  • New Features

    • Comments section now submits dynamically without requiring page reload.
  • Improvements

    • Enhanced visual styling on the visa details page with improved typography, spacing, button and form layouts.
    • Comment creation now also records an audit entry for tracking.
  • Security

    • CSRF protection enabled for request handling.
  • Tests

    • Added controller, mapper unit tests and integration tests covering comment creation, retrieval, and validations.
  • Chores

    • Removed an obsolete TODO comment.

@coderabbitai

coderabbitai Bot commented Apr 18, 2026

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

Removed 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

Cohort / File(s) Summary
Security & Mapper
src/main/java/org/example/visacasemanagementsystem/config/SecurityConfig.java, src/main/java/org/example/visacasemanagementsystem/comment/mapper/CommentMapper.java
Removed explicit .csrf(...disable()) from security filter chain; deleted a non-functional TODO inside CommentMapper.toEntity(...).
Template UI & Client-side Comments
src/main/resources/templates/visa/details.html
UI/CSS and layout tweaks; reordered info blocks; replaced server-posted comment form with client-side JS that reads hidden CSRF token, sends JSON POST to /api/comments, handles empty-state and prepends rendered comment card.
Service Logic
src/main/java/org/example/visacasemanagementsystem/comment/service/CommentService.java
Constructor updated to accept AuditService; after saving a comment the service now calls auditService.createAuditLog(...) with authorId, visaId, event type, and message.
Controller Tests (Web-layer)
src/test/java/org/example/visacasemanagementsystem/comment/CommentControllerTest.java
New @WebMvcTest with MockMvc: tests POST /api/comments returns 201 and expected JSON; tests GET /api/comments/visa/{id} returns 200 and expected list.
Mapper Unit Tests
src/test/java/org/example/visacasemanagementsystem/comment/CommentMapperTest.java
New unit tests verifying DTO→Entity mapping (null id), Entity→DTO mapping with null author/visa fallback to "System", and full mapping including createdAt.
Service Integration Tests
src/test/java/org/example/visacasemanagementsystem/comment/CommentServiceIntegrationTest.java
New Spring Boot integration tests (transactional, test profile) covering create/retrieve flows, missing user/visa exceptions, validation for blank text and negative visa IDs, not-found retrieval, and empty-result scenarios.

Sequence Diagram

sequenceDiagram
    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
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • Feature/comment logic #16: Modifies CommentService implementation — directly related to this PR’s changes to CommentService behavior.
  • Feature/visa view controller #27: Changes SecurityConfig CSRF handling and updates details.html comment flow — overlaps with security and template edits here.
  • Feature/visa tests #32: Updates visa/details.html comment rendering/field naming — overlaps with client-side comment form and rendering changes.

Poem

🐇 I nibble at a comment seed,
JS hops swift to plant the feed,
CSRF a careful sentry near,
Audit logs record the cheer,
Tests and styles make the meadow bright.

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Feature/visa comment integration' accurately describes the main objective of the PR, which comprehensively adds comment functionality to the visa case management system across multiple layers (service, controller, mapper, tests, UI, and security config).

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/visa-comment-integration

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai 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.

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 // Arrange on line 35 labels what is actually the Act step (the call to commentMapper.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

📥 Commits

Reviewing files that changed from the base of the PR and between 6d575bb and da130cd.

📒 Files selected for processing (6)
  • src/main/java/org/example/visacasemanagementsystem/comment/mapper/CommentMapper.java
  • src/main/java/org/example/visacasemanagementsystem/config/SecurityConfig.java
  • src/main/resources/templates/visa/details.html
  • src/test/java/org/example/visacasemanagementsystem/comment/CommentControllerTest.java
  • src/test/java/org/example/visacasemanagementsystem/comment/CommentMapperTest.java
  • src/test/java/org/example/visacasemanagementsystem/comment/CommentServiceIntegrationTest.java
💤 Files with no reviewable changes (1)
  • src/main/java/org/example/visacasemanagementsystem/comment/mapper/CommentMapper.java

Comment thread src/main/java/org/example/visacasemanagementsystem/config/SecurityConfig.java Outdated
Comment thread src/main/resources/templates/visa/details.html Outdated

const container = document.getElementById('commentContainer');
const newCommentHtml = `
<div class="comment-card" style="animation: fadeIn 0.5s;">

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

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 EdvinSandgren left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Verkar fungera bra!

@Martin-E-Karlsson Martin-E-Karlsson left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Ser bra ut!
Om det inte finns konflikter är vi nog redo för merge.

@coderabbitai coderabbitai 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.

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

📥 Commits

Reviewing files that changed from the base of the PR and between fd0851e and 54810d8.

📒 Files selected for processing (1)
  • src/main/java/org/example/visacasemanagementsystem/comment/service/CommentService.java

Comment on lines +69 to +73
auditService.createAuditLog(
author.getId (),
visa.getId (),
AuditEventType.UPDATED,
"Comment added by " + author.getFullName()

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

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.

@Martin-E-Karlsson
Martin-E-Karlsson merged commit f83aa2d into main Apr 20, 2026
2 checks passed
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.

Add tests for Comment package Connect comment logic to section in Visa form

3 participants