Merge branch 'main' of https://github.com/Kareadita/Kavita into feature/scan-library
This commit is contained in:
commit
e1c1719b6a
13 changed files with 499 additions and 48 deletions
|
@ -1,5 +1,6 @@
|
|||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using API.Constants;
|
||||
using API.DTOs;
|
||||
using API.Entities;
|
||||
using API.Interfaces;
|
||||
|
@ -50,7 +51,7 @@ namespace API.Controllers
|
|||
|
||||
|
||||
// TODO: Need a way to store Roles in enum and configure from there
|
||||
var role = registerDto.IsAdmin ? "Admin" : "Pleb";
|
||||
var role = registerDto.IsAdmin ? PolicyConstants.AdminRole : PolicyConstants.PlebRole;
|
||||
var roleResult = await _userManager.AddToRoleAsync(user, role);
|
||||
|
||||
if (!roleResult.Succeeded) return BadRequest(result.Errors);
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
using System.Threading.Tasks;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using API.DTOs;
|
||||
using API.Entities;
|
||||
using API.Interfaces;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
|
@ -25,20 +27,7 @@ namespace API.Controllers
|
|||
return users.Count > 0;
|
||||
}
|
||||
|
||||
[Authorize(Policy = "RequireAdminRole")]
|
||||
[HttpDelete("delete-user")]
|
||||
public async Task<ActionResult> DeleteUser(string username)
|
||||
{
|
||||
var user = await _userRepository.GetUserByUsernameAsync(username);
|
||||
_userRepository.Delete(user);
|
||||
|
||||
if (await _userRepository.SaveAllAsync())
|
||||
{
|
||||
return Ok();
|
||||
}
|
||||
|
||||
return BadRequest("Could not delete the user.");
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -42,12 +42,10 @@ namespace API.Controllers
|
|||
/// </summary>
|
||||
/// <param name="path"></param>
|
||||
/// <returns></returns>
|
||||
[Authorize(Policy = "RequireAdminRole")]
|
||||
[HttpGet("list")]
|
||||
public ActionResult<IEnumerable<string>> GetDirectories(string path)
|
||||
{
|
||||
// TODO: We need some sort of validation other than our auth layer
|
||||
_logger.Log(LogLevel.Debug, "Listing Directories for " + path);
|
||||
|
||||
if (string.IsNullOrEmpty(path))
|
||||
{
|
||||
return Ok(Directory.GetLogicalDrives());
|
||||
|
@ -57,26 +55,13 @@ namespace API.Controllers
|
|||
|
||||
return Ok(_directoryService.ListDirectory(path));
|
||||
}
|
||||
|
||||
|
||||
[HttpGet]
|
||||
public async Task<ActionResult<IEnumerable<LibraryDto>>> GetLibraries()
|
||||
{
|
||||
return Ok(await _libraryRepository.GetLibrariesAsync());
|
||||
}
|
||||
|
||||
|
||||
// Do I need this method?
|
||||
// [HttpGet("library/{username}")]
|
||||
// public async Task<ActionResult<IEnumerable<LibraryDto>>> GetLibrariesForUser(string username)
|
||||
// {
|
||||
// _logger.LogDebug("Method hit");
|
||||
// var user = await _userRepository.GetUserByUsernameAsync(User.GetUsername());
|
||||
//
|
||||
// if (user == null) return BadRequest("Could not validate user");
|
||||
//
|
||||
// return Ok(await _libraryRepository.GetLibrariesForUserAsync(user));
|
||||
// }
|
||||
|
||||
|
||||
[Authorize(Policy = "RequireAdminRole")]
|
||||
[HttpPut("update-for")]
|
||||
public async Task<ActionResult<MemberDto>> UpdateLibrary(UpdateLibraryDto updateLibraryDto)
|
||||
|
|
|
@ -24,19 +24,12 @@ namespace API.Controllers
|
|||
_userRepository = userRepository;
|
||||
_libraryRepository = libraryRepository;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public async Task<ActionResult<IEnumerable<MemberDto>>> GetUsers()
|
||||
{
|
||||
return Ok(await _userRepository.GetMembersAsync());
|
||||
}
|
||||
|
||||
[HttpPost("add-library")]
|
||||
public async Task<ActionResult> AddLibrary(CreateLibraryDto createLibraryDto)
|
||||
{
|
||||
// NOTE: I think we should move this into library controller because it gets added to all admins
|
||||
|
||||
//_logger.Log(LogLevel.Debug, "Creating a new " + createLibraryDto.Type + " library");
|
||||
var user = await _userRepository.GetUserByUsernameAsync(User.GetUsername());
|
||||
|
||||
if (user == null) return BadRequest("Could not validate user");
|
||||
|
@ -72,7 +65,27 @@ namespace API.Controllers
|
|||
|
||||
return BadRequest("Not implemented");
|
||||
}
|
||||
|
||||
|
||||
[Authorize(Policy = "RequireAdminRole")]
|
||||
[HttpDelete("delete-user")]
|
||||
public async Task<ActionResult> DeleteUser(string username)
|
||||
{
|
||||
var user = await _userRepository.GetUserByUsernameAsync(username);
|
||||
_userRepository.Delete(user);
|
||||
|
||||
if (await _userRepository.SaveAllAsync())
|
||||
{
|
||||
return Ok();
|
||||
}
|
||||
|
||||
return BadRequest("Could not delete the user.");
|
||||
}
|
||||
|
||||
[Authorize(Policy = "RequireAdminRole")]
|
||||
[HttpGet]
|
||||
public async Task<ActionResult<IEnumerable<MemberDto>>> GetUsers()
|
||||
{
|
||||
return Ok(await _userRepository.GetMembersAsync());
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue