Skip to content

Make Audit only show up for Manager role#52

Merged
OskarLundqvist33 merged 3 commits into
mainfrom
TestWorkingBranch
Apr 15, 2026
Merged

Make Audit only show up for Manager role#52
OskarLundqvist33 merged 3 commits into
mainfrom
TestWorkingBranch

Conversation

@OskarLundqvist33

@OskarLundqvist33 OskarLundqvist33 commented Apr 13, 2026

Copy link
Copy Markdown
Collaborator

And Update role checks in header to use toString() instead of name()

Summary by CodeRabbit

  • Bug Fixes
    • Fixed role-based navigation access control. The "Audit" link now correctly displays only for users with manager permissions, consistent with other manager-only navigation options ("Manage Patients" and "Manage Users"). This ensures proper permission-based visibility across navigation elements.

…and make Audit only show up for Manager role
@coderabbitai

coderabbitai Bot commented Apr 13, 2026

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

Updated Thymeleaf conditional logic in the header template to change role verification from role().name() to role().toString() and made the "Audit" navigation link conditionally render only for manager roles instead of always displaying.

Changes

Cohort / File(s) Summary
Header Template Conditional Logic
src/main/resources/templates/fragments/header.html
Modified role-based access control check from role().name() to role().toString() and made "Audit" link render conditionally for managers only; previously it was always visible. Added spacing before auth bar.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

🐰 A hop through the header we go,
Where manager links now steal the show,
Role checking's sleeker, toString's the way,
Audit hides when you're not here to stay,
Cleaner and tighter, our template's replay! ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly matches the main change: making the Audit link visible only for Manager role, which is the primary objective of this pull request.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch TestWorkingBranch

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.

@OskarLundqvist33 OskarLundqvist33 linked an issue Apr 13, 2026 that may be closed by this pull request

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

🧹 Nitpick comments (1)
src/main/resources/templates/fragments/header.html (1)

14-21: Reduce duplicated role checks and prefer enum-stable comparison.

Lines 14, 17, and 20 repeat the same condition. Replace role().toString() with role().name() for enum comparison—name() returns the stable enum constant name and cannot be overridden, whereas toString() can be customized and may cause issues if changed. Additionally, wrap these three links in a single th:block to avoid repeating the entire condition:

♻️ Suggested refactor
-            <a class="nav-link"
-               th:if="${currentActor != null && currentActor.role() != null && currentActor.role().toString() == 'MANAGER'}"
-               href="/ui/audit">Audit</a>
-            <a class="nav-link"
-               th:if="${currentActor != null && currentActor.role() != null && currentActor.role().toString() == 'MANAGER'}"
-               href="/ui/patients">Manage Patients</a>
-            <a class="nav-link"
-               th:if="${currentActor != null && currentActor.role() != null && currentActor.role().toString() == 'MANAGER'}"
-               href="/ui/employees">Manage Users</a></nav>
+            <th:block th:if="${currentActor != null && currentActor.role() != null && currentActor.role().name() == 'MANAGER'}">
+                <a class="nav-link" href="/ui/audit">Audit</a>
+                <a class="nav-link" href="/ui/patients">Manage Patients</a>
+                <a class="nav-link" href="/ui/employees">Manage Users</a>
+            </th:block>
+        </nav>
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/main/resources/templates/fragments/header.html` around lines 14 - 21, The
three nav links repeat the same null-and-role check using role().toString(), so
replace the repeated checks by wrapping the three <a> links in a single th:block
with the consolidated condition (currentActor != null && currentActor.role() !=
null && currentActor.role().name() == 'MANAGER'), change each per-link th:if to
no condition (remove per-link checks), and use role().name() instead of
role().toString() to ensure stable enum comparison for currentActor.role().
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@src/main/resources/templates/fragments/header.html`:
- Around line 14-21: The three nav links repeat the same null-and-role check
using role().toString(), so replace the repeated checks by wrapping the three
<a> links in a single th:block with the consolidated condition (currentActor !=
null && currentActor.role() != null && currentActor.role().name() == 'MANAGER'),
change each per-link th:if to no condition (remove per-link checks), and use
role().name() instead of role().toString() to ensure stable enum comparison for
currentActor.role().

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: a4276778-1452-4494-99b8-dd68570ada58

📥 Commits

Reviewing files that changed from the base of the PR and between 192f3d9 and 82ecb9d.

📒 Files selected for processing (1)
  • src/main/resources/templates/fragments/header.html

@OskarLundqvist33
OskarLundqvist33 merged commit 656eda3 into main Apr 15, 2026
2 checks passed
@OskarLundqvist33
OskarLundqvist33 deleted the TestWorkingBranch branch April 15, 2026 11:13
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.

Audit tab should only be visible to admin/manager

1 participant