mirror of
https://github.com/Kareadita/Kavita.git
synced 2026-05-31 03:45:20 -04:00
Added a new policy to require being an admin. Implemented ability to delete a user.
This commit is contained in:
@@ -6,6 +6,7 @@ using API.Entities;
|
||||
using API.Interfaces;
|
||||
using AutoMapper;
|
||||
using AutoMapper.QueryableExtensions;
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace API.Data
|
||||
@@ -14,11 +15,13 @@ namespace API.Data
|
||||
{
|
||||
private readonly DataContext _context;
|
||||
private readonly IMapper _mapper;
|
||||
private readonly UserManager<AppUser> _userManager;
|
||||
|
||||
public UserRepository(DataContext context, IMapper mapper)
|
||||
public UserRepository(DataContext context, IMapper mapper, UserManager<AppUser> userManager)
|
||||
{
|
||||
_context = context;
|
||||
_mapper = mapper;
|
||||
_userManager = userManager;
|
||||
}
|
||||
|
||||
public void Update(AppUser user)
|
||||
@@ -26,6 +29,11 @@ namespace API.Data
|
||||
_context.Entry(user).State = EntityState.Modified;
|
||||
}
|
||||
|
||||
public void Delete(AppUser user)
|
||||
{
|
||||
_context.Users.Remove(user);
|
||||
}
|
||||
|
||||
public async Task<bool> SaveAllAsync()
|
||||
{
|
||||
return await _context.SaveChangesAsync() > 0;
|
||||
@@ -49,6 +57,23 @@ namespace API.Data
|
||||
|
||||
public async Task<IEnumerable<MemberDto>> GetMembersAsync()
|
||||
{
|
||||
return await _userManager.Users
|
||||
.Include(x => x.Libraries)
|
||||
.Include(r => r.UserRoles)
|
||||
.ThenInclude(r => r.Role)
|
||||
.OrderBy(u => u.UserName)
|
||||
.Select(u => new MemberDto
|
||||
{
|
||||
Id = u.Id,
|
||||
Username = u.UserName,
|
||||
Created = u.Created,
|
||||
LastActive = u.LastActive,
|
||||
Roles = u.UserRoles.Select(r => r.Role.Name).ToList()
|
||||
})
|
||||
.ToListAsync();
|
||||
|
||||
//return await _context.Users.Include(x => x.Libraries)
|
||||
|
||||
return await _context.Users.Include(x => x.Libraries)
|
||||
.Include(x => x.Libraries)
|
||||
.ProjectTo<MemberDto>(_mapper.ConfigurationProvider)
|
||||
|
||||
Reference in New Issue
Block a user