fix AuthState
This commit is contained in:
parent
08b4edd1a5
commit
bb00aa8a11
|
|
@ -22,21 +22,23 @@
|
||||||
Spieltage
|
Spieltage
|
||||||
</MudNavLink>
|
</MudNavLink>
|
||||||
|
|
||||||
<MudNavLink Href="/persons"
|
|
||||||
Match="NavLinkMatch.Prefix"
|
|
||||||
Icon="@Icons.Material.Filled.Groups">
|
|
||||||
Personen
|
|
||||||
</MudNavLink>
|
|
||||||
|
|
||||||
@if (AuthState.Value.IsClubEditor || AuthState.Value.IsSuperAdmin)
|
@if (AuthState.Value.IsClubEditor || AuthState.Value.IsSuperAdmin)
|
||||||
{
|
{
|
||||||
<MudNavGroup Title="Stammdaten"
|
<MudNavGroup Title="Stammdaten"
|
||||||
Icon="@Icons.Material.Filled.Settings"
|
Icon="@Icons.Material.Filled.Settings"
|
||||||
Expanded="false">
|
Expanded="false">
|
||||||
|
<MudNavLink Href="/persons"
|
||||||
|
Match="NavLinkMatch.Prefix"
|
||||||
|
Icon="@Icons.Material.Filled.Groups">
|
||||||
|
Personen
|
||||||
|
</MudNavLink>
|
||||||
|
|
||||||
<MudNavLink Href="/expenses"
|
<MudNavLink Href="/expenses"
|
||||||
Match="NavLinkMatch.Prefix"
|
Match="NavLinkMatch.Prefix"
|
||||||
Icon="@Icons.Material.Filled.Receipt">
|
Icon="@Icons.Material.Filled.Receipt">
|
||||||
Kostenvorlagen
|
Strafen
|
||||||
</MudNavLink>
|
</MudNavLink>
|
||||||
</MudNavGroup>
|
</MudNavGroup>
|
||||||
}
|
}
|
||||||
|
|
@ -70,7 +72,7 @@
|
||||||
@* Profile - visible to all authenticated users *@
|
@* Profile - visible to all authenticated users *@
|
||||||
@if (AuthState.Value.IsAuthenticated)
|
@if (AuthState.Value.IsAuthenticated)
|
||||||
{
|
{
|
||||||
<MudNavLink Href="/profile"
|
<MudNavLink Href="/account/profile"
|
||||||
Match="NavLinkMatch.Prefix"
|
Match="NavLinkMatch.Prefix"
|
||||||
Icon="@Icons.Material.Filled.Person">
|
Icon="@Icons.Material.Filled.Person">
|
||||||
Profil
|
Profil
|
||||||
|
|
@ -79,6 +81,5 @@
|
||||||
</MudNavMenu>
|
</MudNavMenu>
|
||||||
|
|
||||||
@code {
|
@code {
|
||||||
private bool HasSelectedClub => ClubState.Value.SelectedClub != null ||
|
private bool HasSelectedClub => AuthState.Value.CurrentClub != null;
|
||||||
AuthState.Value.CurrentUser?.ClubMemberships?.Any(c => c.IsDefault) == true;
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -14,9 +14,9 @@
|
||||||
@inject ISnackbar Snackbar
|
@inject ISnackbar Snackbar
|
||||||
@inject IDialogService DialogService
|
@inject IDialogService DialogService
|
||||||
|
|
||||||
<PageTitle>Kosten-Vorlagen</PageTitle>
|
<PageTitle>Strafen-Vorlagen</PageTitle>
|
||||||
|
|
||||||
<MudText Typo="Typo.h4" Class="mb-4">Kosten-Vorlagen</MudText>
|
<MudText Typo="Typo.h4" Class="mb-4">Strafen-Vorlagen</MudText>
|
||||||
|
|
||||||
@if (ExpenseState.Value.Error is not null)
|
@if (ExpenseState.Value.Error is not null)
|
||||||
{
|
{
|
||||||
|
|
@ -145,7 +145,7 @@
|
||||||
|
|
||||||
private async Task OpenCreateDialog()
|
private async Task OpenCreateDialog()
|
||||||
{
|
{
|
||||||
var dialog = await DialogService.ShowAsync<ExpenseEditDialog>("Neue Kosten-Vorlage");
|
var dialog = await DialogService.ShowAsync<ExpenseEditDialog>("Neue Strafen-Vorlage");
|
||||||
var result = await dialog.Result;
|
var result = await dialog.Result;
|
||||||
|
|
||||||
if (result != null && !result.Canceled && result.Data is CreateExpenseDto dto)
|
if (result != null && !result.Canceled && result.Data is CreateExpenseDto dto)
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ using Koogle.Application;
|
||||||
using Koogle.Infrastructure;
|
using Koogle.Infrastructure;
|
||||||
using Koogle.Infrastructure.Security;
|
using Koogle.Infrastructure.Security;
|
||||||
using Koogle.Web.Components;
|
using Koogle.Web.Components;
|
||||||
|
using Koogle.Web.Store.AuthState;
|
||||||
using Microsoft.AspNetCore.Components.Authorization;
|
using Microsoft.AspNetCore.Components.Authorization;
|
||||||
using Microsoft.AspNetCore.Components.Server;
|
using Microsoft.AspNetCore.Components.Server;
|
||||||
using MudBlazor.Services;
|
using MudBlazor.Services;
|
||||||
|
|
@ -32,6 +33,7 @@ builder.Services.AddFluxor(options =>
|
||||||
options.UseReduxDevTools();
|
options.UseReduxDevTools();
|
||||||
#endif
|
#endif
|
||||||
});
|
});
|
||||||
|
builder.Services.AddScoped<AuthEffects>();
|
||||||
|
|
||||||
builder.Services.AddHttpContextAccessor();
|
builder.Services.AddHttpContextAccessor();
|
||||||
builder.Services.AddControllersWithViews();
|
builder.Services.AddControllersWithViews();
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
using Fluxor;
|
using Fluxor;
|
||||||
|
using Koogle.Application.DTOs;
|
||||||
using Koogle.Application.Interfaces;
|
using Koogle.Application.Interfaces;
|
||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
|
||||||
|
|
@ -53,10 +54,10 @@ namespace Koogle.Web.Store.AuthState
|
||||||
// Merge Identity roles with club-specific roles for current club
|
// Merge Identity roles with club-specific roles for current club
|
||||||
var roles = currentUser.Identity.Roles.ToList();
|
var roles = currentUser.Identity.Roles.ToList();
|
||||||
var currentClubId = _currentClubContext.ClubId;
|
var currentClubId = _currentClubContext.ClubId;
|
||||||
|
UserClubMembershipDto ? clubMembership = null;
|
||||||
if (currentClubId != Guid.Empty)
|
if (currentClubId != Guid.Empty)
|
||||||
{
|
{
|
||||||
var clubMembership = currentUser.ClubMemberships
|
clubMembership = currentUser.ClubMemberships
|
||||||
.FirstOrDefault(m => m.ClubId == currentClubId);
|
.FirstOrDefault(m => m.ClubId == currentClubId);
|
||||||
|
|
||||||
if (clubMembership != null)
|
if (clubMembership != null)
|
||||||
|
|
@ -72,7 +73,7 @@ namespace Koogle.Web.Store.AuthState
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dispatcher.Dispatch(new AuthState.InitializeAuthSuccessAction(currentUser, roles));
|
dispatcher.Dispatch(new AuthState.InitializeAuthSuccessAction(currentUser, clubMembership, roles));
|
||||||
|
|
||||||
_logger.LogInformation("Auth initialized for user {DisplayName} with roles {Roles}",
|
_logger.LogInformation("Auth initialized for user {DisplayName} with roles {Roles}",
|
||||||
currentUser.DisplayName, string.Join(", ", roles));
|
currentUser.DisplayName, string.Join(", ", roles));
|
||||||
|
|
|
||||||
|
|
@ -52,7 +52,8 @@ public static class AuthReducers
|
||||||
{
|
{
|
||||||
IsLoading = false,
|
IsLoading = false,
|
||||||
IsAuthenticated = true,
|
IsAuthenticated = true,
|
||||||
CurrentUser = action.User
|
CurrentUser = action.User,
|
||||||
|
CurrentClub = action.CurrentClub
|
||||||
},
|
},
|
||||||
action.Roles);
|
action.Roles);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,11 @@ public record AuthState
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public UserDto? CurrentUser { get; init; }
|
public UserDto? CurrentUser { get; init; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The current user's at login selected club membership.
|
||||||
|
/// </summary>
|
||||||
|
public UserClubMembershipDto? CurrentClub { get; init; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The current user's roles.
|
/// The current user's roles.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
@ -73,6 +78,7 @@ public record AuthState
|
||||||
public static AuthState Initial => new()
|
public static AuthState Initial => new()
|
||||||
{
|
{
|
||||||
CurrentUser = null,
|
CurrentUser = null,
|
||||||
|
CurrentClub = null,
|
||||||
IsSuperAdmin = false,
|
IsSuperAdmin = false,
|
||||||
IsClubAdmin = false,
|
IsClubAdmin = false,
|
||||||
IsClubEditor = false,
|
IsClubEditor = false,
|
||||||
|
|
@ -119,6 +125,7 @@ public record AuthState
|
||||||
/// <param name="CompanyIds">IDs of accessible companies.</param>
|
/// <param name="CompanyIds">IDs of accessible companies.</param>
|
||||||
public record InitializeAuthSuccessAction(
|
public record InitializeAuthSuccessAction(
|
||||||
UserDto User,
|
UserDto User,
|
||||||
|
UserClubMembershipDto? CurrentClub,
|
||||||
IReadOnlyList<string> Roles);
|
IReadOnlyList<string> Roles);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue