refactor(ui): new standard and accessible UI font (#1777)
This commit is contained in:
@@ -36,6 +36,7 @@ public class BookLoreUserTransformer {
|
||||
bookLoreUser.setTheme(userEntity.getTheme());
|
||||
bookLoreUser.setThemeAccent(userEntity.getThemeAccent());
|
||||
bookLoreUser.setThemeSyncEnabled(userEntity.isThemeSyncEnabled());
|
||||
bookLoreUser.setUiFont(userEntity.getUiFont());
|
||||
bookLoreUser.setDefaultPassword(userEntity.isDefaultPassword());
|
||||
bookLoreUser.setPermissions(permissions);
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@ public class BookLoreUser {
|
||||
private String theme;
|
||||
private String themeAccent;
|
||||
private boolean themeSyncEnabled;
|
||||
private String uiFont;
|
||||
private ProvisioningMethod provisioningMethod;
|
||||
private List<Library> assignedLibraries;
|
||||
private UserPermissions permissions;
|
||||
|
||||
@@ -10,4 +10,5 @@ public class UserProfileUpdateRequest {
|
||||
private String theme;
|
||||
private String themeAccent;
|
||||
private Boolean themeSyncEnabled;
|
||||
private String uiFont;
|
||||
}
|
||||
|
||||
@@ -54,6 +54,10 @@ public class BookLoreUserEntity {
|
||||
@Column(name = "theme_sync_enabled", nullable = false)
|
||||
private boolean themeSyncEnabled = true;
|
||||
|
||||
@Builder.Default
|
||||
@Column(name = "ui_font", nullable = false, length = 32)
|
||||
private String uiFont = "default";
|
||||
|
||||
@Column(name = "provisioning_method")
|
||||
@Enumerated(EnumType.STRING)
|
||||
private ProvisioningMethod provisioningMethod;
|
||||
|
||||
@@ -43,6 +43,7 @@ public class UserService {
|
||||
"red", "orange", "amber", "yellow", "lime", "green", "emerald", "teal",
|
||||
"cyan", "sky", "blue", "indigo", "violet", "purple", "fuchsia", "pink", "rose"
|
||||
);
|
||||
private static final Set<String> SUPPORTED_UI_FONTS = Set.of("default", "atkinson");
|
||||
|
||||
private final UserRepository userRepository;
|
||||
private final LibraryRepository libraryRepository;
|
||||
@@ -124,6 +125,11 @@ public class UserService {
|
||||
user.setThemeSyncEnabled(updateRequest.getThemeSyncEnabled());
|
||||
}
|
||||
|
||||
if (updateRequest.getUiFont() != null) {
|
||||
validateUiFont(updateRequest.getUiFont());
|
||||
user.setUiFont(updateRequest.getUiFont());
|
||||
}
|
||||
|
||||
userRepository.save(user);
|
||||
auditService.log(AuditAction.USER_UPDATED, "User", id, "Updated user profile: " + user.getUsername());
|
||||
return bookLoreUserTransformer.toDTO(user);
|
||||
@@ -282,4 +288,10 @@ public class UserService {
|
||||
throw ApiError.INVALID_INPUT.createException("Unsupported theme accent: " + themeAccent);
|
||||
}
|
||||
}
|
||||
|
||||
private void validateUiFont(String uiFont) {
|
||||
if (!SUPPORTED_UI_FONTS.contains(uiFont)) {
|
||||
throw ApiError.INVALID_INPUT.createException("Unsupported UI font: " + uiFont);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
ALTER TABLE users
|
||||
ADD COLUMN ui_font VARCHAR(32) NOT NULL DEFAULT 'default';
|
||||
@@ -114,6 +114,23 @@ class UserServiceTest {
|
||||
verify(userRepository).save(user);
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateUserProfile_updatesUiFont() {
|
||||
BookLoreUserEntity user = userEntity(1L);
|
||||
UserProfileUpdateRequest request = new UserProfileUpdateRequest();
|
||||
request.setUiFont("atkinson");
|
||||
|
||||
when(userRepository.findByIdWithDetails(1L)).thenReturn(Optional.of(user));
|
||||
when(authenticationService.getAuthenticatedUser()).thenReturn(currentUser(1L, false));
|
||||
when(userRepository.save(user)).thenReturn(user);
|
||||
when(bookLoreUserTransformer.toDTO(user)).thenAnswer(invocation -> currentUser(1L, false));
|
||||
|
||||
userService.updateUserProfile(1L, request);
|
||||
|
||||
assertThat(user.getUiFont()).isEqualTo("atkinson");
|
||||
verify(userRepository).save(user);
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateUserProfile_rejectsUnsupportedLocale() {
|
||||
BookLoreUserEntity user = userEntity(1L);
|
||||
@@ -130,6 +147,22 @@ class UserServiceTest {
|
||||
verify(userRepository, never()).save(any());
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateUserProfile_rejectsUnsupportedUiFont() {
|
||||
BookLoreUserEntity user = userEntity(1L);
|
||||
UserProfileUpdateRequest request = new UserProfileUpdateRequest();
|
||||
request.setUiFont("papyrus");
|
||||
|
||||
when(userRepository.findByIdWithDetails(1L)).thenReturn(Optional.of(user));
|
||||
when(authenticationService.getAuthenticatedUser()).thenReturn(currentUser(1L, false));
|
||||
|
||||
assertThatThrownBy(() -> userService.updateUserProfile(1L, request))
|
||||
.isInstanceOf(APIException.class)
|
||||
.hasMessageContaining("Unsupported UI font");
|
||||
|
||||
verify(userRepository, never()).save(any());
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateUserProfile_rejectsUnsupportedTheme() {
|
||||
BookLoreUserEntity user = userEntity(1L);
|
||||
|
||||
Reference in New Issue
Block a user