Skip to content

Commit

Permalink
Fix:Only show authors with books for users #2250
Browse files Browse the repository at this point in the history
  • Loading branch information
advplyr committed Oct 24, 2023
1 parent 0ee6336 commit ef1cdf6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion server/controllers/LibraryController.js
Original file line number Diff line number Diff line change
Expand Up @@ -621,7 +621,7 @@ class LibraryController {
model: Database.bookModel,
attributes: ['id', 'tags', 'explicit'],
where: bookWhere,
required: false,
required: !req.user.isAdminOrUp, // Only show authors with 0 books for admin users or up
through: {
attributes: []
}
Expand Down
14 changes: 11 additions & 3 deletions server/utils/queries/libraryFilters.js
Original file line number Diff line number Diff line change
Expand Up @@ -308,16 +308,24 @@ module.exports = {
async getNewestAuthors(library, user, limit) {
if (library.mediaType !== 'book') return { authors: [], count: 0 }

const { bookWhere, replacements } = libraryItemsBookFilters.getUserPermissionBookWhereQuery(user)

const { rows: authors, count } = await Database.authorModel.findAndCountAll({
where: {
libraryId: library.id,
createdAt: {
[Sequelize.Op.gte]: new Date(new Date() - (60 * 24 * 60 * 60 * 1000)) // 60 days ago
}
},
replacements,
include: {
model: Database.bookAuthorModel,
required: true // Must belong to a book
model: Database.bookModel,
attributes: ['id', 'tags', 'explicit'],
where: bookWhere,
required: true, // Must belong to a book
through: {
attributes: []
}
},
limit,
distinct: true,
Expand All @@ -328,7 +336,7 @@ module.exports = {

return {
authors: authors.map((au) => {
const numBooks = au.bookAuthors?.length || 0
const numBooks = au.books.length || 0
return au.getOldAuthor().toJSONExpanded(numBooks)
}),
count
Expand Down

0 comments on commit ef1cdf6

Please sign in to comment.