WIP audiences

This commit is contained in:
Paul Schneider 2026-07-12 01:17:52 +01:00
commit f3bb039d2f
15 changed files with 102 additions and 82 deletions

View file

@ -10,7 +10,7 @@ using Yavsc.Server.Helpers;
// For more information on enabling Web API for empty projects, visit http://go.microsoft.com/fwlink/?LinkID=397860
namespace Yavsc.Controllers
namespace Yavsc.Org.Controllers
{
public class BlogSpotController : Controller
{
@ -28,7 +28,7 @@ namespace Yavsc.Controllers
BlogSpotService blogSpotService)
{
_context = context;
_logger = loggerFactory.CreateLogger<AccountController>();
_logger = loggerFactory.CreateLogger<BlogSpotController>();
_authorizationService = authorizationService;
_localisationOptions = localisationOptions.Value;
this.blogSpotService = blogSpotService;
@ -76,7 +76,7 @@ namespace Yavsc.Controllers
return View(blog);
}
catch (AuthorizationFailureException ex)
catch (AuthorizationFailureException)
{
return Challenge();
}

View file

@ -157,8 +157,7 @@ public static class HostingExtensions
services.AddAuthentication("Bearer")
.AddYavscJwtBearer(builder.Configuration,
configure: o => o.Audience = builder.Configuration.GetSection("Site")["ExternalUrl"]);
.AddYavscJwtBearer(builder.Configuration);
services.AddTransient<RoleManager<IdentityRole>>();
services.AddTransient<IRoleStore<IdentityRole>, RoleStore<IdentityRole, ApplicationDbContext>>();

View file

@ -1,26 +1,24 @@
using System.Diagnostics;
using System.Security.Claims;
using Microsoft.AspNetCore.Authorization;
using Microsoft.DotNet.Scaffolding.Shared;
using Microsoft.EntityFrameworkCore;
using Yavsc;
using Yavsc.Helpers;
using Yavsc.Models;
using Yavsc.Models.Blog;
using Yavsc.Server.Exceptions;
using Yavsc.Server.Helpers;
using Yavsc.Services;
using Yavsc.ViewModels.Auth;
using Yavsc.Abstract.Helpers;
using Microsoft.AspNetCore.Http;
public class BlogSpotService
[Obsolete]
public class OldBlogSpotService
{
private readonly ApplicationDbContext _context;
private readonly IAuthorizationService _authorizationService;
private readonly IFileSystemAuthManager fileSystemAuthManager;
public BlogSpotService(ApplicationDbContext context,
public OldBlogSpotService(ApplicationDbContext context,
IAuthorizationService authorizationService,
IFileSystemAuthManager fileSystemAuthManager)
{
@ -93,13 +91,13 @@ public class BlogSpotService
public async Task<BlogPostEditViewModel> GetPostForEdition(ClaimsPrincipal user, long blogPostId)
{
var blog = await _context.BlogSpot.Include(x => x.Author).Include(x => x.ACL).SingleAsync(m => m.Id == blogPostId);
var auth = await _authorizationService.AuthorizeAsync(user, blog, new EditPermission());
var auth = await _authorizationService.AuthorizeAsync(user, blog, new EditPermission());
if (!auth.Succeeded)
{
throw new AuthorizationFailureException(auth);
}
}
var pub = await _context.blogSpotPublications.AnyAsync(x => x.BlogpostId == blog.Id);
return new BlogPostEditViewModel(blog, pub);
}

View file

@ -1,14 +1,19 @@
@using Yavsc.Abstract.Identity
@model ApplicationUser
@{
// Le helper défend contre Model null et contre UserName vide
// ou whitespace. Sans cette garde, Razor lève
// NullReferenceException ici, ce qui propage un 500 et
// masque aussi la page d'erreur.
var avuri = UserDisplayHelpers.AvatarSrc(Model);
}
<div class="userinfo">
<a title="Posts" asp-controller="Blogspot" asp-action="Index" asp-route-id="@Model.UserName" class="btn btn-primary">
@if (Model != null && !string.IsNullOrWhiteSpace(Model.UserName))
{
string avuri = UserDisplayHelpers.AvatarSrc(Model);
<a title="Posts" asp-controller="Blogspot" asp-action="Index" asp-route-id="@Model.UserName" class="btn btn-primary">
<img src="@avuri" asp-append-version="true" class="smalltofhol" alt="@Model.UserName" title="@Model.UserName" />
</a>
} else {
<div class="alert alert-warning">
<strong>Utilisateur inconnu</strong>
<img src="@YavscConstants.DefaultAvatar" class="smalltofhol" alt="Utilisateur inconnu" title="Utilisateur inconnu" />
</div>
}
</div>