Restrict Person by library & Age rating

This commit is contained in:
Amelia 2025-06-20 17:28:47 +02:00
parent d261eaa98f
commit b03b5bfdfc
4 changed files with 116 additions and 14 deletions

View file

@ -27,6 +27,19 @@ public static class RestrictByAgeExtensions
return q;
}
public static IQueryable<SeriesMetadataPeople> RestrictAgainstAgeRestriction(this IQueryable<SeriesMetadataPeople> queryable, AgeRestriction restriction)
{
if (restriction.AgeRating == AgeRating.NotApplicable) return queryable;
var q = queryable.Where(s => s.SeriesMetadata.AgeRating <= restriction.AgeRating);
if (!restriction.IncludeUnknowns)
{
return q.Where(s => s.SeriesMetadata.AgeRating != AgeRating.Unknown);
}
return q;
}
public static IQueryable<Chapter> RestrictAgainstAgeRestriction(this IQueryable<Chapter> queryable, AgeRestriction restriction)
{
@ -41,6 +54,19 @@ public static class RestrictByAgeExtensions
return q;
}
public static IQueryable<ChapterPeople> RestrictAgainstAgeRestriction(this IQueryable<ChapterPeople> queryable, AgeRestriction restriction)
{
if (restriction.AgeRating == AgeRating.NotApplicable) return queryable;
var q = queryable.Where(cp => cp.Chapter.Volume.Series.Metadata.AgeRating <= restriction.AgeRating);
if (!restriction.IncludeUnknowns)
{
return q.Where(cp => cp.Chapter.Volume.Series.Metadata.AgeRating != AgeRating.Unknown);
}
return q;
}
public static IQueryable<AppUserCollection> RestrictAgainstAgeRestriction(this IQueryable<AppUserCollection> queryable, AgeRestriction restriction)
{

View file

@ -0,0 +1,44 @@
using System.Collections.Generic;
using System.Linq;
using API.Entities;
using API.Entities.Person;
namespace API.Extensions.QueryExtensions;
// TODO: Refactor with IQueryable userLibs? But then I can't do the allLibs check?
/// <summary>
/// Optionally pass ids of all libraries, will then be smart and not restrict if the person has access to all
/// </summary>
public static class RestrictByLibraryExtensions
{
public static IQueryable<Person> RestrictByLibrary(this IQueryable<Person> query, IList<int> userLibs, IList<int> allLibs = null)
{
if (allLibs != null && allLibs.Count == userLibs.Count) return query;
return query.Where(p =>
p.ChapterPeople.Any(cp => userLibs.Contains(cp.Chapter.Volume.Series.LibraryId)) ||
p.SeriesMetadataPeople.Any(sm => userLibs.Contains(sm.SeriesMetadata.Series.LibraryId)));
}
public static IQueryable<Chapter> RestrictByLibrary(this IQueryable<Chapter> query, IList<int> userLibs, IList<int> allLibs = null)
{
if (allLibs != null && allLibs.Count == userLibs.Count) return query;
return query.Where(cp => userLibs.Contains(cp.Volume.Series.LibraryId));
}
public static IQueryable<SeriesMetadataPeople> RestrictByLibrary(this IQueryable<SeriesMetadataPeople> query, IList<int> userLibs, IList<int> allLibs = null)
{
if (allLibs != null && allLibs.Count == userLibs.Count) return query;
return query.Where(sm => userLibs.Contains(sm.SeriesMetadata.Series.LibraryId));
}
public static IQueryable<ChapterPeople> RestrictByLibrary(this IQueryable<ChapterPeople> query, IList<int> userLibs, IList<int> allLibs = null)
{
if (allLibs != null && allLibs.Count == userLibs.Count) return query;
return query.Where(cp => userLibs.Contains(cp.Chapter.Volume.Series.LibraryId));
}
}