-
Notifications
You must be signed in to change notification settings - Fork 0
Feature/synchronize UI design #52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
82fb91a
Feature:
Martin-E-Karlsson f53f04c
Fix:
Martin-E-Karlsson 9b55521
Feature: Refactored all common style elements to a CSS stylesheet
Martin-E-Karlsson 2ac51f5
Feature:
Martin-E-Karlsson 401cd8b
Feature: Added new LogViewControllerTest
Martin-E-Karlsson c999386
Feature: Tests for the new case filtering methods in VisaService
Martin-E-Karlsson 201ac0c
Feature: Added tests for findFiltered methods in VisaLogService and U…
Martin-E-Karlsson 2d174c8
Merge branch 'main' into feature/synchronize-ui-design
Martin-E-Karlsson c8d7ca3
Fix: Solved multiple CodeRabbit nitpicks regarding SecurityConfig, Lo…
Martin-E-Karlsson 55beb1a
Fix: Solved multiple CodeRabbit nitpicks regarding tests and then fix…
Martin-E-Karlsson e1260ad
Fix: CodeRabbit nitpick regarding dead status fields.
Martin-E-Karlsson 505ece3
Fix: Changed component for cross browser compatability.
Martin-E-Karlsson 18c34c0
Fix: Created a functional interface to make the LogViewController eas…
Martin-E-Karlsson 0974a57
Fix: CodeRabbit issues regarding Error message in Error.html and a st…
Martin-E-Karlsson 1f9492b
Fix: Analysis chain issue for thymeleaf events in log templates
Martin-E-Karlsson 0273adb
Fix: Analysis chain issue for thymeleaf events in my-applications.html
Martin-E-Karlsson 1ea4de5
Fix: Applied spotless check for found issues
Martin-E-Karlsson db4bf3b
Fix: Issues raised by CodeRabbit in templates
Martin-E-Karlsson 21ad19a
Address CodeRabbit review: CSRF hardening, WCAG fixes, refactors
Martin-E-Karlsson 711feb4
Fix:
Martin-E-Karlsson 414e883
Merge remote-tracking branch 'origin/main' into feature/synchronize-u…
Martin-E-Karlsson 322d6e1
Fix:
Martin-E-Karlsson 2728aec
Fix:
Martin-E-Karlsson 11c702f
Fix:
Martin-E-Karlsson debbb31
Fix: Added access for authenticated users to all visa pages with the …
Martin-E-Karlsson File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 38 additions & 10 deletions
48
src/main/java/org/example/visacasemanagementsystem/ApplicationViewController.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,31 +1,59 @@ | ||
| package org.example.visacasemanagementsystem; | ||
|
|
||
| import jakarta.servlet.http.HttpServletResponse; | ||
| import org.example.visacasemanagementsystem.user.security.UserPrincipal; | ||
| import org.springframework.security.core.annotation.AuthenticationPrincipal; | ||
| import org.springframework.stereotype.Controller; | ||
| import org.springframework.ui.Model; | ||
| import org.springframework.web.bind.annotation.GetMapping; | ||
| import java.util.Objects; | ||
|
|
||
| /** | ||
| * Entry-point controller: maps the site root to the role-based router and | ||
| * hosts that router at /home. | ||
| */ | ||
| @Controller | ||
| public class ApplicationViewController { | ||
|
|
||
| @GetMapping("/") | ||
| public String index() { | ||
| return "redirect:/dashboard"; | ||
| return "redirect:/home"; | ||
| } | ||
|
|
||
| @GetMapping("/dashboard") | ||
| public String dashboard(@AuthenticationPrincipal UserPrincipal principal) { | ||
| /** | ||
| * Role-based landing-page router. Each role has a distinct primary page: | ||
| * SYSADMIN -> /log/visa | ||
| * ADMIN -> /visa/cases | ||
| * USER -> /visa/my-applications. | ||
| */ | ||
| @GetMapping("/home") | ||
| public String home(@AuthenticationPrincipal UserPrincipal principal) { | ||
| if (principal == null) { | ||
| return "redirect:/user/login"; | ||
| } | ||
| boolean isSysAdmin = principal.getAuthorities().stream() | ||
| .anyMatch(a -> Objects.equals(a.getAuthority(), "ROLE_SYSADMIN")); | ||
| boolean isAdmin = principal.getAuthorities().stream() | ||
| .anyMatch(a -> Objects.equals(a.getAuthority(), "ROLE_ADMIN")); | ||
|
|
||
| if (isSysAdmin) return "redirect:/dashboard/sysadmin"; | ||
| if (isAdmin) return "redirect:/dashboard/admin"; | ||
| return "redirect:/dashboard/applicant"; | ||
| boolean isSysAdmin = false; | ||
| boolean isAdmin = false; | ||
| for (var authority : principal.getAuthorities()) { | ||
| String role = authority.getAuthority(); | ||
| if (Objects.equals(role, "ROLE_SYSADMIN")) isSysAdmin = true; | ||
| else if (Objects.equals(role, "ROLE_ADMIN")) isAdmin = true; | ||
| } | ||
|
|
||
| if (isSysAdmin) return "redirect:/log/visa"; | ||
| if (isAdmin) return "redirect:/visa/cases"; | ||
| return "redirect:/visa/my-applications"; | ||
| } | ||
|
|
||
| /** | ||
| * Target of {@code SecurityConfig.exceptionHandling().accessDeniedPage(...)}. | ||
| */ | ||
| @GetMapping("/access-denied") | ||
| public String accessDenied(Model model, HttpServletResponse response) { | ||
| response.setStatus(HttpServletResponse.SC_FORBIDDEN); | ||
| model.addAttribute("errorTitle", "⚠️Access Denied."); | ||
| model.addAttribute("errorMessage", | ||
| "You do not have permission to perform this action."); | ||
| return "error/error"; | ||
| } | ||
| } |
119 changes: 119 additions & 0 deletions
119
src/main/java/org/example/visacasemanagementsystem/audit/controller/LogViewController.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,119 @@ | ||
| package org.example.visacasemanagementsystem.audit.controller; | ||
|
|
||
| import org.example.visacasemanagementsystem.audit.UserEventType; | ||
| import org.example.visacasemanagementsystem.audit.VisaEventType; | ||
| import org.example.visacasemanagementsystem.audit.service.UserLogService; | ||
| import org.example.visacasemanagementsystem.audit.service.VisaLogService; | ||
| import org.springframework.data.domain.Page; | ||
| import org.springframework.data.domain.PageRequest; | ||
| import org.springframework.data.domain.Pageable; | ||
| import org.springframework.data.domain.Sort; | ||
| import org.springframework.format.annotation.DateTimeFormat; | ||
| import org.springframework.security.access.prepost.PreAuthorize; | ||
| import org.springframework.stereotype.Controller; | ||
| import org.springframework.ui.Model; | ||
| import org.springframework.web.bind.annotation.GetMapping; | ||
| import org.springframework.web.bind.annotation.RequestMapping; | ||
| import org.springframework.web.bind.annotation.RequestParam; | ||
|
|
||
| import java.time.LocalDate; | ||
| import java.time.LocalDateTime; | ||
| import java.time.LocalTime; | ||
|
|
||
| /** | ||
| * SYSADMIN-only audit-log pages. | ||
| */ | ||
| @PreAuthorize("hasRole('SYSADMIN')") | ||
| @Controller | ||
| @RequestMapping("/log") | ||
| public class LogViewController { | ||
|
|
||
| // Hard cap on page size for pagination. | ||
| private static final int MAX_PAGE_SIZE = 100; | ||
| private static final String DEFAULT_PAGE_SIZE_STR = "20"; | ||
|
|
||
| private final VisaLogService visaLogService; | ||
| private final UserLogService userLogService; | ||
|
|
||
| public LogViewController(VisaLogService visaLogService, UserLogService userLogService) { | ||
| this.visaLogService = visaLogService; | ||
| this.userLogService = userLogService; | ||
| } | ||
|
|
||
| @GetMapping("/visa") | ||
| public String visaLog( | ||
| @RequestParam(value = "eventType", required = false) VisaEventType eventType, | ||
| @RequestParam(value = "from", required = false) | ||
| @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate from, | ||
| @RequestParam(value = "to", required = false) | ||
| @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate to, | ||
| @RequestParam(value = "page", defaultValue = "0") int page, | ||
| @RequestParam(value = "size", defaultValue = DEFAULT_PAGE_SIZE_STR) int size, | ||
| Model model) { | ||
| return renderLogPage(eventType, from, to, page, size, | ||
| visaLogService::findFiltered, | ||
| VisaEventType.values(), "Visa Log", "log/visa", model); | ||
| } | ||
|
|
||
| @GetMapping("/user") | ||
| public String userLog( | ||
| @RequestParam(value = "eventType", required = false) UserEventType eventType, | ||
| @RequestParam(value = "from", required = false) | ||
| @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate from, | ||
| @RequestParam(value = "to", required = false) | ||
| @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate to, | ||
| @RequestParam(value = "page", defaultValue = "0") int page, | ||
| @RequestParam(value = "size", defaultValue = DEFAULT_PAGE_SIZE_STR) int size, | ||
| Model model) { | ||
| return renderLogPage(eventType, from, to, page, size, | ||
| userLogService::findFiltered, | ||
| UserEventType.values(), "User Log", "log/user", model); | ||
| } | ||
|
|
||
| // ─── Helpers ────────────────────────────────────────────────────────── | ||
|
|
||
| /** Four-arity fetch function: (eventType, from, to, pageable) → Page. */ | ||
| @FunctionalInterface | ||
| private interface LogFetcher<E extends Enum<E>, D> { | ||
| Page<D> fetch(E eventType, LocalDateTime from, LocalDateTime to, Pageable pageable); | ||
| } | ||
|
|
||
| /** | ||
| * Populates the model and returns the view name for any log page. | ||
| * Date-to-LocalDateTime conversion and pagination clamping are applied here | ||
| * so each handler only needs to supply its service reference and enum type. | ||
| */ | ||
| private <E extends Enum<E>, D> String renderLogPage( | ||
| E eventType, LocalDate from, LocalDate to, int page, int size, | ||
| LogFetcher<E, D> fetchFn, | ||
| E[] allEventTypes, String pageTitle, String view, Model model) { | ||
|
|
||
| Page<D> logs = fetchFn.fetch( | ||
| eventType, | ||
| startOfDayOrNull(from), | ||
| endOfDayOrNull(to), | ||
| buildPageable(page, size)); | ||
|
|
||
| model.addAttribute("logs", logs); | ||
| model.addAttribute("eventTypes", allEventTypes); | ||
| model.addAttribute("selectedEventType", eventType); | ||
| model.addAttribute("from", from); | ||
| model.addAttribute("to", to); | ||
| model.addAttribute("pageTitle", pageTitle); | ||
| return view; | ||
| } | ||
|
|
||
| private static LocalDateTime startOfDayOrNull(LocalDate d) { | ||
| return d == null ? null : d.atStartOfDay(); | ||
| } | ||
|
|
||
| private static LocalDateTime endOfDayOrNull(LocalDate d) { | ||
| return d == null ? null : d.atTime(LocalTime.MAX); | ||
| } | ||
|
|
||
| private static PageRequest buildPageable(int page, int size) { | ||
| int safePage = Math.max(page, 0); | ||
| int safeSize = Math.clamp(size, 1, MAX_PAGE_SIZE); | ||
| return PageRequest.of(safePage, safeSize, Sort.by(Sort.Direction.DESC, "timeStamp")); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.