Replaces the previous 'Visibility enum' approach (commit44dcbdd8, reverted in252327d8) with the existing BlogSpotPublication mechanism. Paul pointed out that the system already had a publication table and a Publish field on BlogPostEditViewModel; we just didn't expose it through the API. The toggle is its own action on the API surface — a dedicated endpoint rather than a field on the existing BlogPost wire DTO. This keeps the BlogPostDto contract unchanged and avoids shoe-horning 'Publish' into the entity model alongside Title/Article (where the existing BlogSpotService.Modify already takes two overloads and a third felt like drift). Server (Yavsc.Blogs / Yavsc.Server) - PUT /api/BlogApi/{id}/publish body { publish: bool } Returns 204 on success, 404 when the post doesn't exist, Challenge() (401) when the caller is not the author (EditPermission gate). Idempotent: PUT because the resulting state matches the body, not the request. - BlogSpotService.SetPublishAsync(user, postId, publish) factored out of the existing Modify(BlogPostEditViewModel) inline toggle, so the new endpoint reuses the same BlogSpotPublication row logic (add row if missing on publish=true, remove row if present on publish=false). - BlogPost.IsPublished (NotMapped) is now hydrated by the service after each Index/Details fetch — a single bulk lookup, not N+1 — and surfaces through the wire JSON so PostIt can show the current state without a follow-up request. - ApplicationUser nav properties (Posts, Book, DeviceDeclaration, Connections, Circles, BlackList, Rooms, RoomAccess, Membership, BlogComments) now carry BOTH [JsonIgnore] (Newtonsoft) and [System.Text.Json.Serialization.JsonIgnore] so the Yavsc.Blogs test fixture (System.Text.Json) stops exploding on object cycles when serialising BlogPost.Author.Posts.Author.Posts. Production (Yavsc.Org, NewtonsoftJson) was already safe via the Newtonsoft-only attribute; this commit just makes the Yavsc.Blogs side consistent. Client (Yavsc.Api.Client) - BlogApiClient.SetPublishAsync(id, publish) → PUT to the new endpoint. DTO wire (Yavsc.Abstract.Blogspot.BlogPost) - BlogPostDto.IsPublished added. Same shape as the entity field; serialised as a plain bool in JSON. UI (PostIt) - MainPageViewModel.DraftIsPublished (ObservableProperty) mirrors the existing DraftTitle/DraftArticle pattern; hydrated from SelectedPost.IsPublished on selection change. TogglePublish command pushes the new state to SetPublishAsync and updates both the buffer and the selected post locally so the UI reflects the change without a full Refresh. - MainPage.axaml: a CheckBox 'Publié' in the toolbar, bound to DraftIsPublished TwoWay and wired to TogglePublishCommand. The toggle is its own action (not part of Save), matching the wire contract. Tests (Yavsc.Blogs.Tests) - PublishEndpointTests (4 [Fact]): * PUT publish=true returns 204 and IsPublished is true in the next GET * PUT publish=false clears IsPublished * PUT on an unknown post returns 404 * PUT by a non-author does not return 204 (Challenge) - BlogsWebServerFixture now wires app.UseDeveloperExceptionPage() so 500s in tests surface a real stack trace instead of an empty InternalServerError body — much easier to diagnose future regressions. Test totals: 24/24 Yavsc.Blogs.Tests (was 20, +4 PublishEndpoint), 51/51 PostIt.Tests (no change), 44/44 Yavsc.Org.Tests (no change). Out of scope (tracked in MEMORY.md, 2026-08-18): - i18n: only the new 'Publié' label is localised; the rest of MainPage.axaml is still hard-coded French. - BlogPostEditViewModel.Publish ↔ IsPublished reconciliation in the admin web Yavsc (the Org UI already edits Publish inline; no work needed there).
128 lines
4.4 KiB
C#
128 lines
4.4 KiB
C#
using System.ComponentModel.DataAnnotations;
|
|
using System.ComponentModel.DataAnnotations.Schema;
|
|
using Newtonsoft.Json;
|
|
using Microsoft.AspNetCore.Identity;
|
|
using Yavsc.Models.Relationship;
|
|
using Yavsc.Models.Identity;
|
|
using Yavsc.Models.Chat;
|
|
using Yavsc.Models.Bank;
|
|
using Yavsc.Models.Access;
|
|
using Yavsc.Abstract.Identity;
|
|
|
|
namespace Yavsc.Models
|
|
{
|
|
[Table("AspNetUsers")]
|
|
public class ApplicationUser : IdentityUser, IApplicationUser
|
|
{
|
|
/// <summary>
|
|
/// Another me, as a byte array.TG7@Eu%80rufzkhbb
|
|
/// This value points a picture that may be used
|
|
/// to present the user
|
|
/// </summary>
|
|
/// <returns>the path to an user's image, relative to it's user dir<summary>
|
|
/// <see>Startup.UserFilesOptions</see>
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[MaxLength(512)]
|
|
public string? Avatar { get; set; }
|
|
|
|
[MaxLength(512)]
|
|
public string? FullName { get; set; }
|
|
|
|
|
|
/// <summary>
|
|
/// WIP Paypal
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[Display(Name = "Account balance")]
|
|
public virtual AccountBalance? AccountBalance { get; set; }
|
|
|
|
/// <summary>
|
|
/// User's posts
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[InverseProperty("Author"), JsonIgnore, System.Text.Json.Serialization.JsonIgnore]
|
|
public virtual List<Blog.BlogPost>? Posts { get; set; }
|
|
|
|
/// <summary>
|
|
/// User's contact list
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[InverseProperty("Owner"), JsonIgnore, System.Text.Json.Serialization.JsonIgnore]
|
|
public virtual List<Contact>? Book { get; set; }
|
|
|
|
/// <summary>
|
|
/// External devices using the API
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[InverseProperty("DeviceOwner"), JsonIgnore, System.Text.Json.Serialization.JsonIgnore]
|
|
public virtual List<DeviceDeclaration>? DeviceDeclaration { get; set; }
|
|
|
|
[InverseProperty("Owner"), JsonIgnore, System.Text.Json.Serialization.JsonIgnore]
|
|
public virtual List<ChatConnection>? Connections { get; set; }
|
|
|
|
/// <summary>
|
|
/// User's circles
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[InverseProperty("Owner"), JsonIgnore, System.Text.Json.Serialization.JsonIgnore]
|
|
|
|
public virtual List<Circle>? Circles { get; set; }
|
|
|
|
/// <summary>
|
|
/// Billing postal address
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[ForeignKey("PostalAddressId")]
|
|
public virtual Location? PostalAddress { get; set; }
|
|
public long? PostalAddressId { get; set; }
|
|
|
|
/// <summary>
|
|
/// User's Google calendar
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[MaxLength(512)]
|
|
public string? DedicatedGoogleCalendar { get; set; }
|
|
|
|
public override string ToString()
|
|
{
|
|
return this.Id + " " + this.AccountBalance?.Credits.ToString() + this.Email + " " + this.UserName + " $" + this.AccountBalance?.Credits.ToString();
|
|
}
|
|
|
|
public virtual List<BankIdentity>? BankInfo { get; set; }
|
|
|
|
public long DiskQuota { get; set; } = 512 * 1024 * 1024;
|
|
public long DiskUsage { get; set; } = 0;
|
|
|
|
public long MaxFileSize { get; set; } = 512 * 1024 * 1024;
|
|
|
|
[JsonIgnore, System.Text.Json.Serialization.JsonIgnore]
|
|
[InverseProperty("Owner")]
|
|
public virtual List<BlackListed>? BlackList { get; set; }
|
|
|
|
public bool AllowMonthlyEmail { get; set; } = false;
|
|
|
|
[JsonIgnore, System.Text.Json.Serialization.JsonIgnore]
|
|
[InverseProperty("Owner")]
|
|
public virtual List<ChatRoom>? Rooms { get; set; }
|
|
|
|
[JsonIgnore, System.Text.Json.Serialization.JsonIgnore]
|
|
[InverseProperty("User")]
|
|
public virtual List<ChatRoomAccess>? RoomAccess { get; set; }
|
|
|
|
[JsonIgnore, System.Text.Json.Serialization.JsonIgnore]
|
|
[InverseProperty("Member")]
|
|
public virtual List<CircleMember>? Membership { get; set; }
|
|
|
|
/// <summary>
|
|
/// User's blog comments
|
|
/// </summary>
|
|
[JsonIgnore, System.Text.Json.Serialization.JsonIgnore]
|
|
[InverseProperty("Author")]
|
|
public virtual List<Blog.Comment>? BlogComments { get; set; }
|
|
|
|
IAccountBalance? IApplicationUser.AccountBalance => AccountBalance;
|
|
|
|
ILocation? IApplicationUser.PostalAddress { get => PostalAddress; }
|
|
}
|
|
}
|