Enhance AuditView and NavMenu: restrict access for non-admin users in InitializeDataAsync and OnReadData methods, and refactor NavMenu structure for better readability
Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
using Blazorise.DataGrid;
|
||||
using FoodsharingSiegen.Contracts.Entity;
|
||||
using FoodsharingSiegen.Contracts.Helper;
|
||||
using FoodsharingSiegen.Server.Data.Service;
|
||||
using Microsoft.AspNetCore.Components;
|
||||
|
||||
@@ -39,6 +40,7 @@ namespace FoodsharingSiegen.Server.Pages
|
||||
/// <inheritdoc />
|
||||
protected override Task InitializeDataAsync()
|
||||
{
|
||||
if (!CurrentUser.IsAdmin()) NavigationManager.NavigateTo("/");
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
@@ -52,6 +54,8 @@ namespace FoodsharingSiegen.Server.Pages
|
||||
/// <param name="e">The params</param>
|
||||
private async Task OnReadData(DataGridReadDataEventArgs<Audit> e)
|
||||
{
|
||||
if (!CurrentUser.IsAdmin()) return;
|
||||
|
||||
var countLoad = await AuditService?.GetCount()!;
|
||||
if (countLoad.Success)
|
||||
TotalAudits = countLoad.Data;
|
||||
|
||||
@@ -64,7 +64,6 @@
|
||||
</NavLink>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
|
||||
<div class="nav-item px-3">
|
||||
<div @onclick="NavLinkClickedAsync">
|
||||
@@ -73,6 +72,7 @@
|
||||
</NavLink>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
|
||||
<div class="flex-grow-1"></div>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user