fix empty desktop lists

This commit is contained in:
2026-04-08 08:18:01 -06:00
parent 9e83d7929b
commit 559f3bc343
2 changed files with 9 additions and 3 deletions

View File

@@ -50,7 +50,7 @@ public class AppointmentController {
.orElse(null);
Long effectiveCustomerId = customerId;
if (role != null && (role.equals("CUSTOMER") || role.equals("ADMIN"))) {
if ("CUSTOMER".equals(role)) {
User user = AuthenticationHelper.getAuthenticatedUser(userRepository);
effectiveCustomerId = user.getId();
}
@@ -88,7 +88,7 @@ public class AppointmentController {
.map(authority -> authority.getAuthority().replace("ROLE_", ""))
.orElse(null);
if (role != null && (role.equals("CUSTOMER") || role.equals("ADMIN"))) {
if ("CUSTOMER".equals(role)) {
User user = AuthenticationHelper.getAuthenticatedUser(userRepository);
if (!request.getCustomerId().equals(user.getId())) {
throw new org.springframework.security.access.AccessDeniedException("You can only create appointments for yourself");

View File

@@ -247,7 +247,13 @@ public class PetService {
if (principal instanceof AppPrincipal appPrincipal) {
return new CurrentViewer(appPrincipal.getUserId(), appPrincipal.getRole());
}
return null;
String username = authentication.getName();
if (username == null || username.isBlank() || "anonymousUser".equalsIgnoreCase(username)) {
return null;
}
return userRepository.findByUsername(username)
.map(user -> new CurrentViewer(user.getId(), user.getRole()))
.orElse(null);
}
private Pet findPet(Long id) {