Collection Rework (#2830)
This commit is contained in:
parent
0dacc061f1
commit
deaaccb96a
93 changed files with 5413 additions and 1120 deletions
|
@ -38,7 +38,8 @@ public enum AppUserIncludes
|
|||
SmartFilters = 1024,
|
||||
DashboardStreams = 2048,
|
||||
SideNavStreams = 4096,
|
||||
ExternalSources = 8192 // 2^13
|
||||
ExternalSources = 8192,
|
||||
Collections = 16384 // 2^14
|
||||
}
|
||||
|
||||
public interface IUserRepository
|
||||
|
@ -57,6 +58,7 @@ public interface IUserRepository
|
|||
Task<IEnumerable<MemberDto>> GetEmailConfirmedMemberDtosAsync(bool emailConfirmed = true);
|
||||
Task<IEnumerable<AppUser>> GetAdminUsersAsync();
|
||||
Task<bool> IsUserAdminAsync(AppUser? user);
|
||||
Task<IList<string>> GetRoles(int userId);
|
||||
Task<AppUserRating?> GetUserRatingAsync(int seriesId, int userId);
|
||||
Task<IList<UserReviewDto>> GetUserRatingDtosForSeriesAsync(int seriesId, int userId);
|
||||
Task<AppUserPreferences?> GetPreferencesAsync(string username);
|
||||
|
@ -78,7 +80,7 @@ public interface IUserRepository
|
|||
Task<bool> HasAccessToSeries(int userId, int seriesId);
|
||||
Task<IEnumerable<AppUser>> GetAllUsersAsync(AppUserIncludes includeFlags = AppUserIncludes.None);
|
||||
Task<AppUser?> GetUserByConfirmationToken(string token);
|
||||
Task<AppUser> GetDefaultAdminUser();
|
||||
Task<AppUser> GetDefaultAdminUser(AppUserIncludes includes = AppUserIncludes.None);
|
||||
Task<IEnumerable<AppUserRating>> GetSeriesWithRatings(int userId);
|
||||
Task<IEnumerable<AppUserRating>> GetSeriesWithReviews(int userId);
|
||||
Task<bool> HasHoldOnSeries(int userId, int seriesId);
|
||||
|
@ -298,11 +300,13 @@ public class UserRepository : IUserRepository
|
|||
/// Returns the first admin account created
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public async Task<AppUser> GetDefaultAdminUser()
|
||||
public async Task<AppUser> GetDefaultAdminUser(AppUserIncludes includes = AppUserIncludes.None)
|
||||
{
|
||||
return (await _userManager.GetUsersInRoleAsync(PolicyConstants.AdminRole))
|
||||
return await _context.AppUser
|
||||
.Includes(includes)
|
||||
.Where(u => u.UserRoles.Any(r => r.Role.Name == PolicyConstants.AdminRole))
|
||||
.OrderBy(u => u.Created)
|
||||
.First();
|
||||
.FirstAsync();
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<AppUserRating>> GetSeriesWithRatings(int userId)
|
||||
|
@ -482,7 +486,7 @@ public class UserRepository : IUserRepository
|
|||
|
||||
public async Task<IEnumerable<AppUser>> GetAdminUsersAsync()
|
||||
{
|
||||
return await _userManager.GetUsersInRoleAsync(PolicyConstants.AdminRole);
|
||||
return (await _userManager.GetUsersInRoleAsync(PolicyConstants.AdminRole)).OrderBy(u => u.CreatedUtc);
|
||||
}
|
||||
|
||||
public async Task<bool> IsUserAdminAsync(AppUser? user)
|
||||
|
@ -491,6 +495,14 @@ public class UserRepository : IUserRepository
|
|||
return await _userManager.IsInRoleAsync(user, PolicyConstants.AdminRole);
|
||||
}
|
||||
|
||||
public async Task<IList<string>> GetRoles(int userId)
|
||||
{
|
||||
var user = await _context.Users.FirstOrDefaultAsync(u => u.Id == userId);
|
||||
if (user == null || _userManager == null) return ArraySegment<string>.Empty; // userManager is null on Unit Tests only
|
||||
|
||||
return await _userManager.GetRolesAsync(user);
|
||||
}
|
||||
|
||||
public async Task<AppUserRating?> GetUserRatingAsync(int seriesId, int userId)
|
||||
{
|
||||
return await _context.AppUserRating
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue