mirror of
https://github.com/Kareadita/Kavita.git
synced 2025-06-23 15:30:34 -04:00
Fix reading lists not respecting age ratings (#3590)
This commit is contained in:
parent
5aa9699a99
commit
1244e4263e
@ -2,6 +2,7 @@ using System;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using API.Data.Misc;
|
||||||
using API.DTOs;
|
using API.DTOs;
|
||||||
using API.DTOs.ReadingLists;
|
using API.DTOs.ReadingLists;
|
||||||
using API.Entities;
|
using API.Entities;
|
||||||
@ -185,10 +186,11 @@ public class ReadingListRepository : IReadingListRepository
|
|||||||
|
|
||||||
public async Task<PagedList<ReadingListDto>> GetReadingListDtosForUserAsync(int userId, bool includePromoted, UserParams userParams, bool sortByLastModified = true)
|
public async Task<PagedList<ReadingListDto>> GetReadingListDtosForUserAsync(int userId, bool includePromoted, UserParams userParams, bool sortByLastModified = true)
|
||||||
{
|
{
|
||||||
var userAgeRating = (await _context.AppUser.SingleAsync(u => u.Id == userId)).AgeRestriction;
|
var user = await _context.AppUser.FirstAsync(u => u.Id == userId);
|
||||||
var query = _context.ReadingList
|
var query = _context.ReadingList
|
||||||
.Where(l => l.AppUserId == userId || (includePromoted && l.Promoted ))
|
.Where(l => l.AppUserId == userId || (includePromoted && l.Promoted ))
|
||||||
.Where(l => l.AgeRating >= userAgeRating);
|
.RestrictAgainstAgeRestriction(user.GetAgeRestriction());
|
||||||
|
|
||||||
query = sortByLastModified ? query.OrderByDescending(l => l.LastModified) : query.OrderBy(l => l.NormalizedTitle);
|
query = sortByLastModified ? query.OrderByDescending(l => l.LastModified) : query.OrderBy(l => l.NormalizedTitle);
|
||||||
|
|
||||||
var finalQuery = query.ProjectTo<ReadingListDto>(_mapper.ConfigurationProvider)
|
var finalQuery = query.ProjectTo<ReadingListDto>(_mapper.ConfigurationProvider)
|
||||||
@ -199,8 +201,10 @@ public class ReadingListRepository : IReadingListRepository
|
|||||||
|
|
||||||
public async Task<IEnumerable<ReadingListDto>> GetReadingListDtosForSeriesAndUserAsync(int userId, int seriesId, bool includePromoted)
|
public async Task<IEnumerable<ReadingListDto>> GetReadingListDtosForSeriesAndUserAsync(int userId, int seriesId, bool includePromoted)
|
||||||
{
|
{
|
||||||
|
var user = await _context.AppUser.FirstAsync(u => u.Id == userId);
|
||||||
var query = _context.ReadingList
|
var query = _context.ReadingList
|
||||||
.Where(l => l.AppUserId == userId || (includePromoted && l.Promoted ))
|
.Where(l => l.AppUserId == userId || (includePromoted && l.Promoted ))
|
||||||
|
.RestrictAgainstAgeRestriction(user.GetAgeRestriction())
|
||||||
.Where(l => l.Items.Any(i => i.SeriesId == seriesId))
|
.Where(l => l.Items.Any(i => i.SeriesId == seriesId))
|
||||||
.AsSplitQuery()
|
.AsSplitQuery()
|
||||||
.OrderBy(l => l.Title)
|
.OrderBy(l => l.Title)
|
||||||
@ -212,8 +216,10 @@ public class ReadingListRepository : IReadingListRepository
|
|||||||
|
|
||||||
public async Task<IEnumerable<ReadingListDto>> GetReadingListDtosForChapterAndUserAsync(int userId, int chapterId, bool includePromoted)
|
public async Task<IEnumerable<ReadingListDto>> GetReadingListDtosForChapterAndUserAsync(int userId, int chapterId, bool includePromoted)
|
||||||
{
|
{
|
||||||
|
var user = await _context.AppUser.FirstAsync(u => u.Id == userId);
|
||||||
var query = _context.ReadingList
|
var query = _context.ReadingList
|
||||||
.Where(l => l.AppUserId == userId || (includePromoted && l.Promoted ))
|
.Where(l => l.AppUserId == userId || (includePromoted && l.Promoted ))
|
||||||
|
.RestrictAgainstAgeRestriction(user.GetAgeRestriction())
|
||||||
.Where(l => l.Items.Any(i => i.ChapterId == chapterId))
|
.Where(l => l.Items.Any(i => i.ChapterId == chapterId))
|
||||||
.AsSplitQuery()
|
.AsSplitQuery()
|
||||||
.OrderBy(l => l.Title)
|
.OrderBy(l => l.Title)
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using API.Data.Misc;
|
||||||
using API.Entities;
|
using API.Entities;
|
||||||
using API.Helpers;
|
using API.Helpers;
|
||||||
|
|
||||||
@ -44,4 +45,13 @@ public static class AppUserExtensions
|
|||||||
OrderableHelper.ReorderItems(user.SideNavStreams);
|
OrderableHelper.ReorderItems(user.SideNavStreams);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static AgeRestriction GetAgeRestriction(this AppUser user)
|
||||||
|
{
|
||||||
|
return new AgeRestriction()
|
||||||
|
{
|
||||||
|
AgeRating = user.AgeRestriction,
|
||||||
|
IncludeUnknowns = user.AgeRestrictionIncludeUnknowns,
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user