refacto publication

This commit is contained in:
Paul Schneider 2026-09-19 21:46:08 +01:00
commit 1773c5aaea
Signed by: notazof
GPG key ID: 1DD5D838E5343B06
4 changed files with 16 additions and 43 deletions

20
.vscode/tasks.json vendored
View file

@ -1,27 +1,13 @@
{
"version": "2.0.0",
"isRoot": true,
"problemMatcher": [
{
"owner": "dotnet",
"fileLocation": ["relative", "${workspaceFolder}"],
"source": "dotnet",
"pattern": {
"regexp": "^\\s*(.*)\\((\\d+),(\\d+)\\):\\s+(error|warning) (.*)$",
"file": 1,
"line": 2,
"column": 3,
"severity": 4,
"code": 5,
"message": 6
}
}
],
"tasks": [
{
"label": "run-debug-android",
"command": "dotnet",
"type": "shell",
"problemMatcher": ["$msCompile"],
"options": {
"cwd": "${workspaceFolder}/src/PostIt/PostIt.Android",
"env": {
@ -43,6 +29,7 @@
"label": "build",
"command": "dotnet",
"type": "process",
"problemMatcher": ["$msCompile"],
"args": ["build", "/property:GenerateFullPaths=true"],
"group": "build",
"isBuildCommand": true,
@ -109,6 +96,7 @@
"isTestCommand": false,
"isBackground": true,
"command": "dotnet",
"problemMatcher": ["$msCompile"],
"args": ["build", "/property:GenerateFullPaths=true"],
"options": {
"cwd": "src/PostIt/PostIt.Desktop"

View file

@ -13,7 +13,7 @@ using static Yavsc.Constants;
namespace Yavsc.Blogs.Tests;
/// <summary>
/// Behavioural tests for <c>BlogAclApiController.PostCircleAuthorizationToBlogPost</c>:
/// Behavioral tests for <c>BlogAclApiController.PostCircleAuthorizationToBlogPost</c>:
/// <c>POST /api/v1/blogacl</c> with a JSON body of
/// <c>CircleAuthorizationToBlogPost</c> (CircleId + BlogPostId).
///
@ -84,7 +84,7 @@ public sealed class BlogAclApiTests : IClassFixture<BlogsWebServerFixture>
// rather than being rewritten to ClaimTypes.NameIdentifier.
// The controller, however, reads the user id via
// User.FindFirstValue(ClaimTypes.NameIdentifier), so we add
// an explicit nameid claim to keep the legacy lookup happy.
// an explicit NameIdentifier claim to keep the legacy lookup happy.
http.DefaultRequestHeaders.Authorization =
new System.Net.Http.Headers.AuthenticationHeaderValue(
"Bearer",
@ -106,7 +106,7 @@ public sealed class BlogAclApiTests : IClassFixture<BlogsWebServerFixture>
/// when <see cref="PostAclDialogViewModel.AddAsync"/> POSTs the
/// shape <c>{ "circleId": &lt;id&gt; }</c> — the exact body the
/// PostIt client builds from <see cref="CircleAuthorization"/>
/// (which only carries <c>CircleId</c>). The server deserialises
/// (which only carries <c>CircleId</c>). The server deserializes
/// it into <see cref="CircleAuthorizationToBlogPost"/>, leaves
/// <c>BlogPostId</c> at its <c>default(long) = 0</c>, attaches
/// no <c>Target</c> navigation, and EF Core refuses to INSERT

View file

@ -57,7 +57,7 @@ namespace Yavsc.Models.Blog
get; set;
}
[Display(Name = "Utilisateur ayant modifé le dernier")]
[Display(Name = "Utilisateur ayant modifié le dernier")]
public string? UserModified
{
get; set;
@ -106,10 +106,10 @@ namespace Yavsc.Models.Blog
/// <c>[NotMapped]</c> so no migration is needed. The
/// service hydrates it after each fetch (single bulk
/// lookup, not N+1) and it surfaces through the wire
/// as part of the JSON-serialised <c>BlogPost</c>.
/// as part of the JSON-serialized <c>BlogPost</c>.
/// </summary>
[NotMapped]
public bool IsPublished { get; set; }
public bool IsPublished { get => Publication != null; }
[JsonIgnore]
/// <summary>

View file

@ -108,7 +108,7 @@ public class BlogSpotService
public BlogPost Create(string userId, BlogPost post )
{
// Sauvegarder le post d'abord pour obtenir son ID
// Le createur vient de l'authentification, donc on ne le prend pas du post
// Le créateur vient de l'authentification, donc on ne le prend pas du post
post.AuthorId = userId;
_context.BlogSpot.Add(post);
_context.SaveChanges(userId);
@ -139,15 +139,12 @@ public class BlogSpotService
.Include(p => p.Tags)
.Include(p => p.Comments)
.Include(p => p.ACL)
.Include(p => p.Publication)
.SingleAsync(m => m.Id == blogPostId);
if (blog == null)
return null;
// Hydrate le flag [NotMapped] depuis la table de publication.
blog.IsPublished = await _context.blogSpotPublications
.AnyAsync(pub => pub.PostId == blogPostId);
var auth = await _authorizationService.AuthorizeAsync(user, blog, new ReadPermission());
if (!auth.Succeeded)
throw new AuthorizationFailureException(auth);
@ -233,6 +230,7 @@ public class BlogSpotService
.Include(p => p.Comments)
.Include(p => p.Publication)
.Where(p => p.Publication != null
|| p.AuthorId == viewerId
|| (userCircles != null && p.ACL.Any(a => userCircles.Contains(a.CircleId))));
}
else
@ -247,25 +245,12 @@ public class BlogSpotService
.ToArray();
}
var materialised = posts.ToList();
var materialized = posts.ToList();
var postIds = materialised.Select(p => p.Id).ToList();
if (postIds.Count > 0)
{
var publishedIds = await _context.blogSpotPublications
.Where(pub => postIds.Contains(pub.PostId))
.Select(pub => pub.PostId)
.ToListAsync();
var publishedSet = publishedIds.ToHashSet();
foreach (var post in materialised.OfType<BlogPost>())
post.IsPublished = publishedSet.Contains(post.Id);
}
foreach (var post in materialised.OfType<BlogPost>())
foreach (var post in materialized.OfType<BlogPost>())
ScrubAclForViewer(post, user);
return materialised
return materialized
.OrderByDescending(p => p.DateModified)
.Skip(skip)
.Take(take);