diff --git a/API.Tests/Repository/PersonRepositoryTests.cs b/API.Tests/Repository/PersonRepositoryTests.cs index 74613df7e..8656c6d62 100644 --- a/API.Tests/Repository/PersonRepositoryTests.cs +++ b/API.Tests/Repository/PersonRepositoryTests.cs @@ -167,9 +167,14 @@ public class PersonRepositoryTests : AbstractDbTest foreach (var person in AllPeople) Assert.Contains(fullAccessPeople, ContainsPersonCheck(person)); + // 1 lib0, 2 Lib1 Assert.Equal(3, fullAccessPeople.First(dto => dto.Id == SharedSeriesChaptersPerson.Id).SeriesCount); + // 2* the above Assert.Equal(6, fullAccessPeople.First(dto => dto.Id == SharedSeriesChaptersPerson.Id).ChapterCount); + // 1 series in lib0 Assert.Equal(1, fullAccessPeople.First(dto => dto.Id == Lib0SeriesPerson.Id).SeriesCount); + // 2 series in lib1 + Assert.Equal(2, fullAccessPeople.First(dto => dto.Id == Lib1SeriesPerson.Id).SeriesCount); var restrictedAccessPeople = @@ -186,8 +191,11 @@ public class PersonRepositoryTests : AbstractDbTest Assert.Contains(restrictedAccessPeople, ContainsPersonCheck(Lib1ChaptersPerson)); Assert.Contains(restrictedAccessPeople, ContainsPersonCheck(Lib1ChapterAgePerson)); + // 2 series in lib1, 0 in lib0 Assert.Equal(2, restrictedAccessPeople.First(dto => dto.Id == SharedSeriesChaptersPerson.Id).SeriesCount); + // 2* the above Assert.Equal(4, restrictedAccessPeople.First(dto => dto.Id == SharedSeriesChaptersPerson.Id).ChapterCount); + // Access to both series Assert.Equal(2, restrictedAccessPeople.First(dto => dto.Id == Lib1SeriesPerson.Id).SeriesCount); diff --git a/API/Data/Repositories/PersonRepository.cs b/API/Data/Repositories/PersonRepository.cs index 1cc0a3a48..0e03d5b0b 100644 --- a/API/Data/Repositories/PersonRepository.cs +++ b/API/Data/Repositories/PersonRepository.cs @@ -179,7 +179,7 @@ public class PersonRepository : IPersonRepository public async Task> GetRolesForPersonByName(int personId, int userId) { var ageRating = await _context.AppUser.GetUserAgeRestriction(userId); - var userLibs = await _context.Library.GetUserLibraries(userId).ToListAsync(); + var userLibs = _context.Library.GetUserLibraries(userId); // Query roles from ChapterPeople var chapterRoles = await _context.Person @@ -332,7 +332,7 @@ public class PersonRepository : IPersonRepository { var normalized = name.ToNormalized(); var ageRating = await _context.AppUser.GetUserAgeRestriction(userId); - var userLibs = await _context.Library.GetUserLibraries(userId).ToListAsync(); + var userLibs = _context.Library.GetUserLibraries(userId); return await _context.Person .Where(p => p.NormalizedName == normalized) @@ -382,7 +382,7 @@ public class PersonRepository : IPersonRepository public async Task> GetChaptersForPersonByRole(int personId, int userId, PersonRole role) { var ageRating = await _context.AppUser.GetUserAgeRestriction(userId); - var userLibs = await _context.Library.GetUserLibraries(userId).ToListAsync(); + var userLibs = _context.Library.GetUserLibraries(userId); return await _context.ChapterPeople .Where(cp => cp.PersonId == personId && cp.Role == role) @@ -442,7 +442,7 @@ public class PersonRepository : IPersonRepository public async Task> GetAllPersonDtosAsync(int userId, PersonIncludes includes = PersonIncludes.None) { var ageRating = await _context.AppUser.GetUserAgeRestriction(userId); - var userLibs = await _context.Library.GetUserLibraries(userId).ToListAsync(); + var userLibs = _context.Library.GetUserLibraries(userId); return await _context.Person .Includes(includes) @@ -456,7 +456,7 @@ public class PersonRepository : IPersonRepository public async Task> GetAllPersonDtosByRoleAsync(int userId, PersonRole role, PersonIncludes includes = PersonIncludes.None) { var ageRating = await _context.AppUser.GetUserAgeRestriction(userId); - var userLibs = await _context.Library.GetUserLibraries(userId).ToListAsync(); + var userLibs = _context.Library.GetUserLibraries(userId); return await _context.Person .Where(p => p.SeriesMetadataPeople.Any(smp => smp.Role == role) || p.ChapterPeople.Any(cp => cp.Role == role)) // Filter by role in both series and chapters diff --git a/API/Extensions/QueryExtensions/RestrictByLibraryExtensions.cs b/API/Extensions/QueryExtensions/RestrictByLibraryExtensions.cs index c59ced5fc..83ada7892 100644 --- a/API/Extensions/QueryExtensions/RestrictByLibraryExtensions.cs +++ b/API/Extensions/QueryExtensions/RestrictByLibraryExtensions.cs @@ -12,33 +12,25 @@ namespace API.Extensions.QueryExtensions; public static class RestrictByLibraryExtensions { - public static IQueryable RestrictByLibrary(this IQueryable query, IList userLibs, IList allLibs = null) + public static IQueryable RestrictByLibrary(this IQueryable query, IQueryable userLibs) { - 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 RestrictByLibrary(this IQueryable query, IList userLibs, IList allLibs = null) + public static IQueryable RestrictByLibrary(this IQueryable query, IQueryable userLibs) { - if (allLibs != null && allLibs.Count == userLibs.Count) return query; - return query.Where(cp => userLibs.Contains(cp.Volume.Series.LibraryId)); } - public static IQueryable RestrictByLibrary(this IQueryable query, IList userLibs, IList allLibs = null) + public static IQueryable RestrictByLibrary(this IQueryable query, IQueryable userLibs) { - if (allLibs != null && allLibs.Count == userLibs.Count) return query; - return query.Where(sm => userLibs.Contains(sm.SeriesMetadata.Series.LibraryId)); } - public static IQueryable RestrictByLibrary(this IQueryable query, IList userLibs, IList allLibs = null) + public static IQueryable RestrictByLibrary(this IQueryable query, IQueryable userLibs) { - if (allLibs != null && allLibs.Count == userLibs.Count) return query; - return query.Where(cp => userLibs.Contains(cp.Chapter.Volume.Series.LibraryId)); } }