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 Blazorise.DataGrid;
|
||||||
using FoodsharingSiegen.Contracts.Entity;
|
using FoodsharingSiegen.Contracts.Entity;
|
||||||
|
using FoodsharingSiegen.Contracts.Helper;
|
||||||
using FoodsharingSiegen.Server.Data.Service;
|
using FoodsharingSiegen.Server.Data.Service;
|
||||||
using Microsoft.AspNetCore.Components;
|
using Microsoft.AspNetCore.Components;
|
||||||
|
|
||||||
@@ -39,6 +40,7 @@ namespace FoodsharingSiegen.Server.Pages
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
protected override Task InitializeDataAsync()
|
protected override Task InitializeDataAsync()
|
||||||
{
|
{
|
||||||
|
if (!CurrentUser.IsAdmin()) NavigationManager.NavigateTo("/");
|
||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -52,6 +54,8 @@ namespace FoodsharingSiegen.Server.Pages
|
|||||||
/// <param name="e">The params</param>
|
/// <param name="e">The params</param>
|
||||||
private async Task OnReadData(DataGridReadDataEventArgs<Audit> e)
|
private async Task OnReadData(DataGridReadDataEventArgs<Audit> e)
|
||||||
{
|
{
|
||||||
|
if (!CurrentUser.IsAdmin()) return;
|
||||||
|
|
||||||
var countLoad = await AuditService?.GetCount()!;
|
var countLoad = await AuditService?.GetCount()!;
|
||||||
if (countLoad.Success)
|
if (countLoad.Success)
|
||||||
TotalAudits = countLoad.Data;
|
TotalAudits = countLoad.Data;
|
||||||
|
|||||||
@@ -64,15 +64,15 @@
|
|||||||
</NavLink>
|
</NavLink>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
}
|
|
||||||
|
|
||||||
<div class="nav-item px-3">
|
<div class="nav-item px-3">
|
||||||
<div @onclick="NavLinkClickedAsync">
|
<div @onclick="NavLinkClickedAsync">
|
||||||
<NavLink class="nav-link" href="audit" Match="NavLinkMatch.All">
|
<NavLink class="nav-link" href="audit" Match="NavLinkMatch.All">
|
||||||
<span class="fa-solid fa-clock-rotate-left mr-2" aria-hidden="true" style="font-size: 1.4em;"></span> Aktivitäten
|
<span class="fa-solid fa-clock-rotate-left mr-2" aria-hidden="true" style="font-size: 1.4em;"></span> Aktivitäten
|
||||||
</NavLink>
|
</NavLink>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
}
|
||||||
|
|
||||||
<div class="flex-grow-1"></div>
|
<div class="flex-grow-1"></div>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user