diff --git a/src/Koogle.Web/Components/Layout/NavMenu.razor b/src/Koogle.Web/Components/Layout/NavMenu.razor index 4f43215..03f5881 100644 --- a/src/Koogle.Web/Components/Layout/NavMenu.razor +++ b/src/Koogle.Web/Components/Layout/NavMenu.razor @@ -22,21 +22,23 @@ Spieltage - - Personen - + @if (AuthState.Value.IsClubEditor || AuthState.Value.IsSuperAdmin) { + + Personen + + - Kostenvorlagen + Strafen } @@ -70,7 +72,7 @@ @* Profile - visible to all authenticated users *@ @if (AuthState.Value.IsAuthenticated) { - Profil @@ -79,6 +81,5 @@ @code { - private bool HasSelectedClub => ClubState.Value.SelectedClub != null || - AuthState.Value.CurrentUser?.ClubMemberships?.Any(c => c.IsDefault) == true; + private bool HasSelectedClub => AuthState.Value.CurrentClub != null; } diff --git a/src/Koogle.Web/Components/Pages/Expenses/Expenses.razor b/src/Koogle.Web/Components/Pages/Expenses/Expenses.razor index ac37822..782f1d5 100644 --- a/src/Koogle.Web/Components/Pages/Expenses/Expenses.razor +++ b/src/Koogle.Web/Components/Pages/Expenses/Expenses.razor @@ -14,9 +14,9 @@ @inject ISnackbar Snackbar @inject IDialogService DialogService -Kosten-Vorlagen +Strafen-Vorlagen -Kosten-Vorlagen +Strafen-Vorlagen @if (ExpenseState.Value.Error is not null) { @@ -145,7 +145,7 @@ private async Task OpenCreateDialog() { - var dialog = await DialogService.ShowAsync("Neue Kosten-Vorlage"); + var dialog = await DialogService.ShowAsync("Neue Strafen-Vorlage"); var result = await dialog.Result; if (result != null && !result.Canceled && result.Data is CreateExpenseDto dto) diff --git a/src/Koogle.Web/Program.cs b/src/Koogle.Web/Program.cs index 368c12a..2d41035 100644 --- a/src/Koogle.Web/Program.cs +++ b/src/Koogle.Web/Program.cs @@ -5,6 +5,7 @@ using Koogle.Application; using Koogle.Infrastructure; using Koogle.Infrastructure.Security; using Koogle.Web.Components; +using Koogle.Web.Store.AuthState; using Microsoft.AspNetCore.Components.Authorization; using Microsoft.AspNetCore.Components.Server; using MudBlazor.Services; @@ -32,6 +33,7 @@ builder.Services.AddFluxor(options => options.UseReduxDevTools(); #endif }); +builder.Services.AddScoped(); builder.Services.AddHttpContextAccessor(); builder.Services.AddControllersWithViews(); diff --git a/src/Koogle.Web/Store/AuthState/AuthEffects.cs b/src/Koogle.Web/Store/AuthState/AuthEffects.cs index da767c0..f5bd532 100644 --- a/src/Koogle.Web/Store/AuthState/AuthEffects.cs +++ b/src/Koogle.Web/Store/AuthState/AuthEffects.cs @@ -1,4 +1,5 @@ using Fluxor; +using Koogle.Application.DTOs; using Koogle.Application.Interfaces; using Microsoft.AspNetCore.Authorization; @@ -53,10 +54,10 @@ namespace Koogle.Web.Store.AuthState // Merge Identity roles with club-specific roles for current club var roles = currentUser.Identity.Roles.ToList(); var currentClubId = _currentClubContext.ClubId; - + UserClubMembershipDto ? clubMembership = null; if (currentClubId != Guid.Empty) { - var clubMembership = currentUser.ClubMemberships + clubMembership = currentUser.ClubMemberships .FirstOrDefault(m => m.ClubId == currentClubId); 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}", currentUser.DisplayName, string.Join(", ", roles)); diff --git a/src/Koogle.Web/Store/AuthState/AuthReducers.cs b/src/Koogle.Web/Store/AuthState/AuthReducers.cs index 14e8997..b44f2a4 100644 --- a/src/Koogle.Web/Store/AuthState/AuthReducers.cs +++ b/src/Koogle.Web/Store/AuthState/AuthReducers.cs @@ -52,7 +52,8 @@ public static class AuthReducers { IsLoading = false, IsAuthenticated = true, - CurrentUser = action.User + CurrentUser = action.User, + CurrentClub = action.CurrentClub }, action.Roles); diff --git a/src/Koogle.Web/Store/AuthState/AuthState.cs b/src/Koogle.Web/Store/AuthState/AuthState.cs index 2ea7b5a..092d6b6 100644 --- a/src/Koogle.Web/Store/AuthState/AuthState.cs +++ b/src/Koogle.Web/Store/AuthState/AuthState.cs @@ -25,6 +25,11 @@ public record AuthState /// public UserDto? CurrentUser { get; init; } + /// + /// The current user's at login selected club membership. + /// + public UserClubMembershipDto? CurrentClub { get; init; } + /// /// The current user's roles. /// @@ -73,6 +78,7 @@ public record AuthState public static AuthState Initial => new() { CurrentUser = null, + CurrentClub = null, IsSuperAdmin = false, IsClubAdmin = false, IsClubEditor = false, @@ -119,6 +125,7 @@ public record AuthState /// IDs of accessible companies. public record InitializeAuthSuccessAction( UserDto User, + UserClubMembershipDto? CurrentClub, IReadOnlyList Roles); ///