Fix: restrict book query to assigned library IDs for non-admin users
This commit is contained in:
committed by
Aditya Chandel
parent
1f3e77f775
commit
852373711e
@@ -36,6 +36,10 @@ public interface BookRepository extends JpaRepository<BookEntity, Long>, JpaSpec
|
|||||||
@Query("SELECT b FROM BookEntity b")
|
@Query("SELECT b FROM BookEntity b")
|
||||||
List<BookEntity> findAllWithMetadata();
|
List<BookEntity> findAllWithMetadata();
|
||||||
|
|
||||||
|
@EntityGraph(attributePaths = {"metadata", "shelves"})
|
||||||
|
@Query("SELECT b FROM BookEntity b WHERE b.library.id IN :libraryIds")
|
||||||
|
List<BookEntity> findAllWithMetadataByLibraryIds(@Param("libraryIds") Collection<Long> libraryIds);
|
||||||
|
|
||||||
@EntityGraph(attributePaths = {"metadata", "shelves"})
|
@EntityGraph(attributePaths = {"metadata", "shelves"})
|
||||||
@Query("SELECT b FROM BookEntity b WHERE b.id IN :bookIds")
|
@Query("SELECT b FROM BookEntity b WHERE b.id IN :bookIds")
|
||||||
List<BookEntity> findAllWithMetadataByIds(@Param("bookIds") Set<Long> bookIds);
|
List<BookEntity> findAllWithMetadataByIds(@Param("bookIds") Set<Long> bookIds);
|
||||||
|
|||||||
@@ -31,6 +31,19 @@ public class BookQueryService {
|
|||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<Book> getAllBooksByLibraryIds(Set<Long> libraryIds, boolean includeDescription) {
|
||||||
|
List<BookEntity> books = bookRepository.findAllWithMetadataByLibraryIds(libraryIds);
|
||||||
|
return books.stream()
|
||||||
|
.map(book -> {
|
||||||
|
Book dto = bookMapperV2.toDTO(book);
|
||||||
|
if (!includeDescription && dto.getMetadata() != null) {
|
||||||
|
dto.getMetadata().setDescription(null);
|
||||||
|
}
|
||||||
|
return dto;
|
||||||
|
})
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
public List<BookEntity> findAllWithMetadataByIds(Set<Long> bookIds) {
|
public List<BookEntity> findAllWithMetadataByIds(Set<Long> bookIds) {
|
||||||
return bookRepository.findAllWithMetadataByIds(bookIds);
|
return bookRepository.findAllWithMetadataByIds(bookIds);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -53,7 +53,16 @@ public class BookService {
|
|||||||
|
|
||||||
public List<Book> getBookDTOs(boolean includeDescription) {
|
public List<Book> getBookDTOs(boolean includeDescription) {
|
||||||
BookLoreUser user = authenticationService.getAuthenticatedUser();
|
BookLoreUser user = authenticationService.getAuthenticatedUser();
|
||||||
List<Book> books = bookQueryService.getAllBooks(includeDescription);
|
boolean isAdmin = user.getPermissions().isAdmin();
|
||||||
|
List<Book> books;
|
||||||
|
if(isAdmin) {
|
||||||
|
books = bookQueryService.getAllBooks(includeDescription);
|
||||||
|
} else{
|
||||||
|
Set<Long> libraryIds = user.getAssignedLibraries().stream()
|
||||||
|
.map(Library::getId)
|
||||||
|
.collect(Collectors.toSet());
|
||||||
|
books = bookQueryService.getAllBooksByLibraryIds(libraryIds, includeDescription);
|
||||||
|
}
|
||||||
Map<Long, UserBookProgressEntity> progressMap = userProgressService.fetchUserProgress(user.getId(), books.stream().map(Book::getId).collect(Collectors.toSet()));
|
Map<Long, UserBookProgressEntity> progressMap = userProgressService.fetchUserProgress(user.getId(), books.stream().map(Book::getId).collect(Collectors.toSet()));
|
||||||
books.forEach(book -> {
|
books.forEach(book -> {
|
||||||
UserBookProgressEntity progress = progressMap.get(book.getId());
|
UserBookProgressEntity progress = progressMap.get(book.getId());
|
||||||
|
|||||||
+1
-1
@@ -178,7 +178,7 @@
|
|||||||
<p class="whitespace-nowrap"><span class="font-bold">Language:</span> {{ metadata.language || '-' }}</p>
|
<p class="whitespace-nowrap"><span class="font-bold">Language:</span> {{ metadata.language || '-' }}</p>
|
||||||
<p class="whitespace-nowrap"><span class="font-bold">ISBN 10:</span> {{ metadata.isbn10 || '-' }}</p>
|
<p class="whitespace-nowrap"><span class="font-bold">ISBN 10:</span> {{ metadata.isbn10 || '-' }}</p>
|
||||||
<p class="whitespace-nowrap flex items-center gap-2">
|
<p class="whitespace-nowrap flex items-center gap-2">
|
||||||
<span class="font-bold">Match Score:</span>
|
<span class="font-bold">Metadata Score:</span>
|
||||||
@if (book?.metadataMatchScore != null) {
|
@if (book?.metadataMatchScore != null) {
|
||||||
<span
|
<span
|
||||||
class="inline-block px-2 py-0.5 rounded-full text-xs font-bold text-white border"
|
class="inline-block px-2 py-0.5 rounded-full text-xs font-bold text-white border"
|
||||||
|
|||||||
+9
-7
@@ -288,12 +288,14 @@ export class MetadataViewerComponent implements OnInit, OnChanges {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getMatchScoreColorClass(score: number): string {
|
getMatchScoreColorClass(score: number): string {
|
||||||
if (score >= 0.95) return 'bg-green-600 border-green-700';
|
if (score >= 0.95) return 'bg-green-900 border-green-950';
|
||||||
if (score >= 0.90) return 'bg-green-500 border-green-600';
|
if (score >= 0.90) return 'bg-green-800 border-green-900';
|
||||||
if (score >= 0.80) return 'bg-green-400 border-green-500';
|
if (score >= 0.80) return 'bg-green-700 border-green-800';
|
||||||
if (score >= 0.70) return 'bg-yellow-500 border-yellow-600';
|
if (score >= 0.70) return 'bg-yellow-700 border-yellow-800';
|
||||||
if (score >= 0.50) return 'bg-yellow-400 border-yellow-500';
|
if (score >= 0.60) return 'bg-yellow-600 border-yellow-700';
|
||||||
if (score >= 0.30) return 'bg-red-500 border-red-600';
|
if (score >= 0.50) return 'bg-yellow-500 border-yellow-600';
|
||||||
return 'bg-red-600 border-red-700';
|
if (score >= 0.40) return 'bg-red-500 border-red-600';
|
||||||
|
if (score >= 0.30) return 'bg-red-600 border-red-700';
|
||||||
|
return 'bg-red-700 border-red-800';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -186,7 +186,7 @@ export class ThemeConfiguratorComponent implements OnInit {
|
|||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
if (isPlatformBrowser(this.platformId)) {
|
if (isPlatformBrowser(this.platformId)) {
|
||||||
this.onPresetChange(); // Ensures both primary and surface colors apply
|
this.onPresetChange();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user