Inherit web links for Series and bug fixes (#4152)

This commit is contained in:
Fesaa
2025-10-25 21:35:53 +02:00
committed by GitHub
parent 935ed96416
commit 76f9e085eb
31 changed files with 4284 additions and 119 deletions
+1
View File
@@ -657,6 +657,7 @@ public class LibraryController : BaseApiController
library.AllowMetadataMatching = dto.AllowMetadataMatching;
library.EnableMetadata = dto.EnableMetadata;
library.RemovePrefixForSortName = dto.RemovePrefixForSortName;
library.InheritWebLinksFromFirstChapter = dto.InheritWebLinksFromFirstChapter;
library.LibraryFileTypes = dto.FileGroupTypes
.Select(t => new LibraryFileTypeGroup() {FileTypeGroup = t, LibraryId = library.Id})
+16 -3
View File
@@ -1,4 +1,6 @@
using System.Threading.Tasks;
#nullable enable
using System;
using System.Threading.Tasks;
using API.Extensions;
using API.Services;
using Kavita.Common;
@@ -6,11 +8,14 @@ using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Authentication.Cookies;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using Microsoft.IdentityModel.Protocols;
using Microsoft.IdentityModel.Protocols.OpenIdConnect;
namespace API.Controllers;
[Route("[controller]")]
public class OidcController: ControllerBase
public class OidcController(ILogger<OidcController> logger, [FromServices] ConfigurationManager<OpenIdConnectConfiguration>? configurationManager = null): ControllerBase
{
[AllowAnonymous]
@@ -36,7 +41,15 @@ public class OidcController: ControllerBase
}
var res = await Request.HttpContext.AuthenticateAsync(CookieAuthenticationDefaults.AuthenticationScheme);
if (!res.Succeeded || res.Properties == null || string.IsNullOrEmpty(res.Properties.GetTokenValue(OidcService.IdToken)))
if (configurationManager == null || !res.Succeeded || res.Properties == null || string.IsNullOrEmpty(res.Properties.GetTokenValue(OidcService.IdToken)))
{
HttpContext.Response.Cookies.Delete(OidcService.CookieName);
return Redirect(Configuration.BaseUrl);
}
// Authelia is dysfunctional and doesn't support logging out like this
var config = await configurationManager.GetConfigurationAsync();
if (config == null || string.IsNullOrEmpty(config.EndSessionEndpoint))
{
HttpContext.Response.Cookies.Delete(OidcService.CookieName);
return Redirect(Configuration.BaseUrl);
+53 -10
View File
@@ -12,11 +12,13 @@ using API.Entities.Enums;
using API.Extensions;
using API.Helpers;
using API.Services;
using API.Services.Plus;
using API.Services.Tasks.Metadata;
using API.SignalR;
using AutoMapper;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using Nager.ArticleNumber;
namespace API.Controllers;
@@ -48,7 +50,45 @@ public class PersonController : BaseApiController
[HttpGet]
public async Task<ActionResult<PersonDto>> GetPersonByName(string name)
{
return Ok(await _unitOfWork.PersonRepository.GetPersonDtoByName(name, User.GetUserId()));
var person = await _unitOfWork.PersonRepository.GetPersonDtoByName(name, User.GetUserId());
if (person == null) return NotFound();
person.Roles = (await _unitOfWork.PersonRepository.GetRolesForPersonByName(person.Id, User.GetUserId())).ToList();
EnrichWithWebLinks(person);
return Ok(person);
}
/// <summary>
/// Populate <see cref="PersonDto.WebLinks"/> from set ids
/// </summary>
/// <param name="personDto"></param>
/// <remarks><see cref="PersonDto.Roles"/> must be set for this to work</remarks>
private static void EnrichWithWebLinks(PersonDto personDto)
{
if (personDto.Roles == null) return;
var isCharacter = personDto.Roles.Count == 1 && personDto.Roles.Contains(PersonRole.Character);
personDto.WebLinks = [];
if (personDto.AniListId != 0)
{
var urlPrefix = isCharacter ? ScrobblingService.AniListCharacterWebsite : ScrobblingService.AniListStaffWebsite;
personDto.WebLinks.Add($"{urlPrefix}{personDto.AniListId}");
}
if (personDto.MalId != 0)
{
var urlPrefix = isCharacter ? ScrobblingService.MalCharacterWebsite : ScrobblingService.MalStaffWebsite;
personDto.WebLinks.Add($"{urlPrefix}{personDto.MalId}");
}
// Hardcover currently does not seem to have characters
if (!string.IsNullOrEmpty(personDto.HardcoverId) && !isCharacter)
{
personDto.WebLinks.Add($"{ScrobblingService.HardcoverStaffWebsite}{personDto.HardcoverId}");
}
}
/// <summary>
@@ -112,12 +152,14 @@ public class PersonController : BaseApiController
return BadRequest(await _localizationService.Translate(User.GetUserId(), "person-name-unique"));
}
// Update name first, in case it got moved to aliases
person.Name = dto.Name.Trim();
person.NormalizedName = person.Name.ToNormalized();
var success = await _personService.UpdatePersonAliasesAsync(person, dto.Aliases);
if (!success) return BadRequest(await _localizationService.Translate(User.GetUserId(), "aliases-have-overlap"));
person.Name = dto.Name?.Trim();
person.NormalizedName = person.Name.ToNormalized();
person.Description = dto.Description ?? string.Empty;
person.CoverImageLocked = dto.CoverImageLocked;
@@ -236,17 +278,18 @@ public class PersonController : BaseApiController
/// <summary>
/// Ensure the alias is valid to be added. For example, the alias cannot be on another person or be the same as the current person name/alias.
/// </summary>
/// <param name="personId"></param>
/// <param name="alias"></param>
/// <param name="dto">alias check request</param>
/// <returns></returns>
[HttpGet("valid-alias")]
public async Task<ActionResult<bool>> IsValidAlias(int personId, string alias)
[HttpPost("valid-alias")]
public async Task<ActionResult<bool>> IsValidAlias(PersonAliasCheckDto dto)
{
var person = await _unitOfWork.PersonRepository.GetPersonById(personId, PersonIncludes.Aliases);
var person = await _unitOfWork.PersonRepository.GetPersonById(dto.PersonId, PersonIncludes.Aliases);
if (person == null) return NotFound();
var existingAlias = await _unitOfWork.PersonRepository.AnyAliasExist(alias);
return Ok(!existingAlias && person.NormalizedName != alias.ToNormalized());
var aliasIsName = dto.Name.ToNormalized() == dto.Alias.ToNormalized();
var existingAlias = await _unitOfWork.PersonRepository.AnyAliasExist(dto.Alias);
return Ok(!existingAlias && !aliasIsName);
}