diff --git a/komga/src/main/kotlin/org/gotson/komga/interfaces/web/rest/SeriesController.kt b/komga/src/main/kotlin/org/gotson/komga/interfaces/web/rest/SeriesController.kt index 2334f77bd..f3575c81d 100644 --- a/komga/src/main/kotlin/org/gotson/komga/interfaces/web/rest/SeriesController.kt +++ b/komga/src/main/kotlin/org/gotson/komga/interfaces/web/rest/SeriesController.kt @@ -53,19 +53,25 @@ class SeriesController( ) return mutableListOf>().let { specs -> + when { + !principal.user.sharedAllLibraries && !libraryIds.isNullOrEmpty() -> { + val authorizedLibraryIDs = libraryIds.intersect(principal.user.sharedLibraries.map { it.id }) + if (authorizedLibraryIDs.isEmpty()) return@let Page.empty(pageRequest) + else specs.add(Series::library.`in`(libraryRepository.findAllById(authorizedLibraryIDs))) + } + + !principal.user.sharedAllLibraries -> specs.add(Series::library.`in`(principal.user.sharedLibraries)) + + !libraryIds.isNullOrEmpty() -> { + val values = libraryRepository.findAllById(libraryIds) + specs.add(Series::library.`in`(values)) + } + } + if (!searchTerm.isNullOrEmpty()) { specs.add(Series::name.likeLower("%$searchTerm%")) } - if (!principal.user.sharedAllLibraries) { - specs.add(Series::library.`in`(principal.user.sharedLibraries)) - } - - if (!libraryIds.isNullOrEmpty()) { - val libraries = libraryRepository.findAllById(libraryIds) - specs.add(Series::library.`in`(libraries)) - } - if (specs.isNotEmpty()) { seriesRepository.findAll(specs.reduce { acc, spec -> acc.and(spec)!! }, pageRequest) } else {