mirror of
https://github.com/Kareadita/Kavita.git
synced 2026-06-05 22:35:17 -04:00
Progress Overhaul + Profile Page and a LOT more! (#4262)
Co-authored-by: Amelia <77553571+Fesaa@users.noreply.github.com> Co-authored-by: Robbie Davis <robbie@therobbiedavis.com>
This commit is contained in:
@@ -1,12 +1,14 @@
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using API.Constants;
|
||||
using API.Data;
|
||||
using API.Data.Repositories;
|
||||
using API.DTOs;
|
||||
using API.DTOs.Account;
|
||||
using API.DTOs.KavitaPlus.Account;
|
||||
using API.Extensions;
|
||||
using API.Middleware;
|
||||
using API.Services;
|
||||
using API.Services.Plus;
|
||||
using API.SignalR;
|
||||
@@ -37,7 +39,7 @@ public class UsersController : BaseApiController
|
||||
_licenseService = licenseService;
|
||||
}
|
||||
|
||||
[Authorize(Policy = "RequireAdminRole")]
|
||||
[Authorize(Policy = PolicyGroups.AdminPolicy)]
|
||||
[HttpDelete("delete-user")]
|
||||
public async Task<ActionResult> DeleteUser(string username)
|
||||
{
|
||||
@@ -59,7 +61,7 @@ public class UsersController : BaseApiController
|
||||
|
||||
if (await _unitOfWork.CommitAsync()) return Ok();
|
||||
|
||||
return BadRequest(await _localizationService.Translate(User.GetUserId(), "generic-user-delete"));
|
||||
return BadRequest(await _localizationService.Translate(UserId, "generic-user-delete"));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -67,7 +69,7 @@ public class UsersController : BaseApiController
|
||||
/// </summary>
|
||||
/// <param name="includePending">This will include pending members</param>
|
||||
/// <returns></returns>
|
||||
[Authorize(Policy = "RequireAdminRole")]
|
||||
[Authorize(Policy = PolicyGroups.AdminPolicy)]
|
||||
[HttpGet]
|
||||
public async Task<ActionResult<IEnumerable<MemberDto>>> GetUsers(bool includePending = false)
|
||||
{
|
||||
@@ -78,7 +80,24 @@ public class UsersController : BaseApiController
|
||||
public async Task<ActionResult<IEnumerable<MemberDto>>> GetMyself()
|
||||
{
|
||||
var users = await _unitOfWork.UserRepository.GetAllUsersAsync();
|
||||
return Ok(users.Where(u => u.UserName == User.GetUsername()).DefaultIfEmpty().Select(u => _mapper.Map<MemberDto>(u)).SingleOrDefault());
|
||||
return Ok(users.Where(u => u.UserName == Username!).DefaultIfEmpty().Select(u => _mapper.Map<MemberDto>(u)).SingleOrDefault());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get Information about a given user
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet("profile-info")]
|
||||
[Authorize]
|
||||
[ProfilePrivacy]
|
||||
public async Task<ActionResult<MemberInfoDto>> GetProfileInfo(int userId)
|
||||
{
|
||||
// Validate that the user has sharing enabled
|
||||
var user = await _unitOfWork.UserRepository.GetUserByIdAsync(userId);
|
||||
if (user == null) return BadRequest();
|
||||
|
||||
return Ok(_mapper.Map<MemberInfoDto>(user));
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -86,14 +105,14 @@ public class UsersController : BaseApiController
|
||||
public async Task<ActionResult<bool>> HasReadingProgress(int libraryId)
|
||||
{
|
||||
var library = await _unitOfWork.LibraryRepository.GetLibraryForIdAsync(libraryId);
|
||||
if (library == null) return BadRequest(await _localizationService.Translate(User.GetUserId(), "library-doesnt-exist"));
|
||||
return Ok(await _unitOfWork.AppUserProgressRepository.UserHasProgress(library.Type, User.GetUserId()));
|
||||
if (library == null) return BadRequest(await _localizationService.Translate(UserId, "library-doesnt-exist"));
|
||||
return Ok(await _unitOfWork.AppUserProgressRepository.UserHasProgress(library.Type, UserId));
|
||||
}
|
||||
|
||||
[HttpGet("has-library-access")]
|
||||
public ActionResult<bool> HasLibraryAccess(int libraryId)
|
||||
public async Task< ActionResult<bool>> HasLibraryAccess(int libraryId)
|
||||
{
|
||||
var libs = _unitOfWork.LibraryRepository.GetLibraryDtosForUsernameAsync(User.GetUsername());
|
||||
var libs = await _unitOfWork.LibraryRepository.GetLibraryDtosForUsernameAsync(Username!);
|
||||
return Ok(libs.Any(x => x.Id == libraryId));
|
||||
}
|
||||
|
||||
@@ -104,14 +123,14 @@ public class UsersController : BaseApiController
|
||||
/// <param name="preferencesDto"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost("update-preferences")]
|
||||
[DisallowRole(PolicyConstants.ReadOnlyRole)]
|
||||
public async Task<ActionResult<UserPreferencesDto>> UpdatePreferences(UserPreferencesDto preferencesDto)
|
||||
{
|
||||
var user = await _unitOfWork.UserRepository.GetUserByUsernameAsync(User.GetUsername(),
|
||||
var user = await _unitOfWork.UserRepository.GetUserByUsernameAsync(Username!,
|
||||
AppUserIncludes.UserPreferences);
|
||||
if (user == null) return Unauthorized();
|
||||
if (User.IsInRole(PolicyConstants.ReadOnlyRole)) return BadRequest(await _localizationService.Translate(User.GetUserId(), "permission-denied"));
|
||||
|
||||
var existingPreferences = user!.UserPreferences;
|
||||
var existingPreferences = user.UserPreferences;
|
||||
|
||||
existingPreferences.GlobalPageLayoutMode = preferencesDto.GlobalPageLayoutMode;
|
||||
existingPreferences.BlurUnreadSummaries = preferencesDto.BlurUnreadSummaries;
|
||||
@@ -121,6 +140,7 @@ public class UsersController : BaseApiController
|
||||
existingPreferences.ColorScapeEnabled = preferencesDto.ColorScapeEnabled;
|
||||
existingPreferences.BookReaderHighlightSlots = preferencesDto.BookReaderHighlightSlots;
|
||||
existingPreferences.DataSaver = preferencesDto.DataSaver;
|
||||
existingPreferences.PromptForRereadsAfter = Math.Max(preferencesDto.PromptForRereadsAfter, 0);
|
||||
existingPreferences.CustomKeyBinds = preferencesDto.CustomKeyBinds;
|
||||
|
||||
var allLibs = (await _unitOfWork.LibraryRepository.GetLibrariesForUserIdAsync(user.Id))
|
||||
@@ -155,7 +175,7 @@ public class UsersController : BaseApiController
|
||||
|
||||
_unitOfWork.UserRepository.Update(existingPreferences);
|
||||
|
||||
if (!await _unitOfWork.CommitAsync()) return BadRequest(await _localizationService.Translate(User.GetUserId(), "generic-user-pref"));
|
||||
if (!await _unitOfWork.CommitAsync()) return BadRequest(await _localizationService.Translate(UserId, "generic-user-pref"));
|
||||
|
||||
await _eventHub.SendMessageToAsync(MessageFactory.UserUpdate, MessageFactory.UserUpdateEvent(user.Id, user.UserName!), user.Id);
|
||||
return Ok(preferencesDto);
|
||||
@@ -169,7 +189,7 @@ public class UsersController : BaseApiController
|
||||
public async Task<ActionResult<UserPreferencesDto>> GetPreferences()
|
||||
{
|
||||
return _mapper.Map<UserPreferencesDto>(
|
||||
await _unitOfWork.UserRepository.GetPreferencesAsync(User.GetUsername()));
|
||||
await _unitOfWork.UserRepository.GetPreferencesAsync(Username!));
|
||||
|
||||
}
|
||||
|
||||
@@ -177,7 +197,7 @@ public class UsersController : BaseApiController
|
||||
/// Returns a list of the user names within the system
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[Authorize(Policy = "RequireAdminRole")]
|
||||
[Authorize(Policy = PolicyGroups.AdminPolicy)]
|
||||
[HttpGet("names")]
|
||||
public async Task<ActionResult<IEnumerable<string>>> GetUserNames()
|
||||
{
|
||||
@@ -189,11 +209,11 @@ public class UsersController : BaseApiController
|
||||
/// </summary>
|
||||
/// <remarks>Kavita+ only</remarks>
|
||||
/// <returns></returns>
|
||||
[Authorize(Policy = "RequireAdminRole")]
|
||||
[Authorize(Policy = PolicyGroups.AdminPolicy)]
|
||||
[HttpGet("tokens")]
|
||||
public async Task<ActionResult<IEnumerable<UserTokenInfo>>> GetUserTokens()
|
||||
{
|
||||
if (!await _licenseService.HasActiveLicense()) return BadRequest(_localizationService.Translate(User.GetUserId(), "kavitaplus-restricted"));
|
||||
if (!await _licenseService.HasActiveLicense()) return BadRequest(_localizationService.Translate(UserId, "kavitaplus-restricted"));
|
||||
|
||||
return Ok((await _unitOfWork.UserRepository.GetUserTokenInfo()));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user