display the circle names
All checks were successful
Dotnet build and test / build (pull_request) Successful in 6m31s

This commit is contained in:
Paul Schneider 2026-08-30 19:44:25 +01:00
commit 34ea58182d
Signed by: notazof
GPG key ID: 1DD5D838E5343B06
2 changed files with 28 additions and 13 deletions

View file

@ -15,6 +15,12 @@ using System.Net.Http;
namespace PostIt.ViewModels; namespace PostIt.ViewModels;
public sealed class PostAclEntry
{
public long CircleId { get; init; }
public string CircleName { get; init; } = string.Empty;
}
/// <summary> /// <summary>
/// View model for the "Gérer l'ACL" modal of a single blog post. /// View model for the "Gérer l'ACL" modal of a single blog post.
/// ///
@ -45,7 +51,7 @@ public partial class PostAclDialogViewModel : ViewModelBase
MyCircles { get; set; } = new(); MyCircles { get; set; } = new();
[ObservableProperty] [ObservableProperty]
public partial ObservableCollection<CircleAuthorization> public partial ObservableCollection<PostAclEntry>
AclEntries { get; set; } = new(); AclEntries { get; set; } = new();
[ObservableProperty] [ObservableProperty]
@ -82,10 +88,7 @@ public partial class PostAclDialogViewModel : ViewModelBase
_aclClient = aclClient ?? throw new ArgumentNullException(nameof(aclClient)); _aclClient = aclClient ?? throw new ArgumentNullException(nameof(aclClient));
_circleClient = circleClient ?? throw new ArgumentNullException(nameof(circleClient)); _circleClient = circleClient ?? throw new ArgumentNullException(nameof(circleClient));
AclEntries = new ObservableCollection<CircleAuthorization>(post.GetACL().Select(a => new CircleAuthorization AclEntries = new ObservableCollection<PostAclEntry>(post.GetACL().Select(a => ToAclEntry(a.CircleId)));
{
CircleId = a.CircleId
}));
SelectedCircleToAdd = null; SelectedCircleToAdd = null;
} }
@ -108,6 +111,9 @@ public partial class PostAclDialogViewModel : ViewModelBase
var circles = circlesTask.Result ?? new List<CircleDto>(); var circles = circlesTask.Result ?? new List<CircleDto>();
MyCircles = new ObservableCollection<CircleDto>(circles); MyCircles = new ObservableCollection<CircleDto>(circles);
// Resolve labels now that circles are available.
AclEntries = new ObservableCollection<PostAclEntry>(AclEntries.Select(a => ToAclEntry(a.CircleId)));
StatusMessage = $"{AclEntries.Count} autorisation(s)"; StatusMessage = $"{AclEntries.Count} autorisation(s)";
_loaded = true; _loaded = true;
@ -147,7 +153,7 @@ public partial class PostAclDialogViewModel : ViewModelBase
}); });
if (created is not null) if (created is not null)
{ {
AclEntries.Add(new CircleAuthorization { CircleId = created.CircleId }); AclEntries.Add(ToAclEntry(created.CircleId));
StatusMessage = $"Cercle « {SelectedCircleToAdd.Name} » autorisé"; StatusMessage = $"Cercle « {SelectedCircleToAdd.Name} » autorisé";
} }
else else
@ -173,7 +179,7 @@ public partial class PostAclDialogViewModel : ViewModelBase
} }
[RelayCommand] [RelayCommand]
public async Task RevokeAsync(PostAccessControlRulePayload? acl) public async Task RevokeAsync(PostAclEntry? acl)
{ {
if (acl is null) return; if (acl is null) return;
IsBusy = true; IsBusy = true;
@ -200,10 +206,20 @@ public partial class PostAclDialogViewModel : ViewModelBase
var allAcl = await _aclClient.GetMyAclAsync(); var allAcl = await _aclClient.GetMyAclAsync();
var currentPostAcl = (allAcl ?? new List<PostAccessControlRulePayload>()) var currentPostAcl = (allAcl ?? new List<PostAccessControlRulePayload>())
.Where(a => a.BlogPostId == Post.Id) .Where(a => a.BlogPostId == Post.Id)
.Select(a => new CircleAuthorization { CircleId = a.CircleId }) .Select(a => ToAclEntry(a.CircleId))
.GroupBy(a => a.CircleId) .GroupBy(a => a.CircleId)
.Select(g => g.First()) .Select(g => g.First())
.ToList(); .ToList();
AclEntries = new ObservableCollection<CircleAuthorization>(currentPostAcl); AclEntries = new ObservableCollection<PostAclEntry>(currentPostAcl);
}
private PostAclEntry ToAclEntry(long circleId)
{
var circleName = MyCircles.FirstOrDefault(c => c.Id == circleId)?.Name;
return new PostAclEntry
{
CircleId = circleId,
CircleName = string.IsNullOrWhiteSpace(circleName) ? $"Cercle #{circleId}" : circleName
};
} }
} }

View file

@ -3,8 +3,7 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="PostIt.Views.PostAclDialog" x:Class="PostIt.Views.PostAclDialog"
xmlns:vm="using:PostIt.ViewModels" xmlns:vm="using:PostIt.ViewModels"
xmlns:dtos="using:Yavsc.Api.Client.Dtos" xmlns:dtos="using:Yavsc.Api.Client.Dtos"
xmlns:yabst="using:Yavsc.Abstract.Identity.Security"
x:DataType="vm:PostAclDialogViewModel" x:DataType="vm:PostAclDialogViewModel"
> >
<Grid RowDefinitions="Auto,*,Auto,Auto" Margin="12"> <Grid RowDefinitions="Auto,*,Auto,Auto" Margin="12">
@ -32,10 +31,10 @@
<ListBox Grid.Row="1" <ListBox Grid.Row="1"
ItemsSource="{Binding AclEntries}"> ItemsSource="{Binding AclEntries}">
<ListBox.ItemTemplate> <ListBox.ItemTemplate>
<DataTemplate x:DataType="yabst:CircleAuthorization"> <DataTemplate x:DataType="vm:PostAclEntry">
<Grid ColumnDefinitions="*,Auto"> <Grid ColumnDefinitions="*,Auto">
<StackPanel Grid.Column="0" Spacing="2"> <StackPanel Grid.Column="0" Spacing="2">
<TextBlock Text="{Binding CircleId, StringFormat='Cercle #{0}'}" <TextBlock Text="{Binding CircleName}"
FontWeight="Bold"/> FontWeight="Bold"/>
</StackPanel> </StackPanel>
<Button Grid.Column="1" Content="Révoquer" <Button Grid.Column="1" Content="Révoquer"