Create new layout for pages with authorization checks

This commit is contained in:
2025-10-15 11:48:57 +09:00
parent d95589ae58
commit 8e1d313483
3 changed files with 62 additions and 34 deletions

View File

@ -0,0 +1,22 @@
@inherits LayoutComponentBase
@using Microsoft.AspNetCore.Authorization
@layout MainLayout
<AuthorizeView Roles="@Roles">
<Authorized>
<CascadingValue Value="this">
@Body
</CascadingValue>
</Authorized>
<NotAuthorized>
<RadzenAlert AllowClose="false" AlertStyle="AlertStyle.Danger" Variant="Variant.Flat" Shade="Shade.Lighter">
У вас нет прав для доступа к этой странице
</RadzenAlert>
</NotAuthorized>
</AuthorizeView>
@code {
public string Roles { get; set; }
}

View File

@ -9,17 +9,18 @@
@using Hcs.WebApp.Utils @using Hcs.WebApp.Utils
@using Microsoft.AspNetCore.Authorization @using Microsoft.AspNetCore.Authorization
@implements IDisposable
@attribute [Authorize] @attribute [Authorize]
@layout AuthorizedLayout
@implements IDisposable
@inject NavigationManager NavigationManager @inject NavigationManager NavigationManager
@inject IConfiguration Configuration @inject IConfiguration Configuration
@inject IClientProvider ClientProvider @inject IClientProvider ClientProvider
<PageTitle>Тестирование экспорта</PageTitle> <PageTitle>Тестирование экспорта</PageTitle>
<AuthorizeView Roles="@AppRole.ADMINISTRATOR_TYPE">
<RadzenSplitter Orientation="Orientation.Vertical" Style="height: 100%; border: 1px solid rgba(0,0,0,.08);"> <RadzenSplitter Orientation="Orientation.Vertical" Style="height: 100%; border: 1px solid rgba(0,0,0,.08);">
<RadzenSplitterPane Size="200px"> <RadzenSplitterPane Size="200px">
<div style="height: 100%;overflow: auto;"> <div style="height: 100%;overflow: auto;">
@ -51,7 +52,6 @@
<EventConsole @ref=@console /> <EventConsole @ref=@console />
</RadzenSplitterPane> </RadzenSplitterPane>
</RadzenSplitter> </RadzenSplitter>
</AuthorizeView>
@code { @code {
EventConsole console = default!; EventConsole console = default!;
@ -66,10 +66,15 @@
FileMessageCapturer messageCapturer; FileMessageCapturer messageCapturer;
bool catchMessageBody; bool catchMessageBody;
[CascadingParameter]
public AuthorizedLayout Layout { get; set; }
protected override void OnInitialized() protected override void OnInitialized()
{ {
base.OnInitialized(); base.OnInitialized();
Layout.Roles = AppRole.ADMINISTRATOR_TYPE;
logger.OnWriteLine += OnLog; logger.OnWriteLine += OnLog;
messageCapturer = new FileMessageCapturer("test/export", logger); messageCapturer = new FileMessageCapturer("test/export", logger);

View File

@ -2,6 +2,7 @@
@using System.Net.Http.Json @using System.Net.Http.Json
@using Hcs.WebApp @using Hcs.WebApp
@using Hcs.WebApp.Components @using Hcs.WebApp.Components
@using Hcs.WebApp.Components.Layout
@using Hcs.WebApp.Components.Shared @using Hcs.WebApp.Components.Shared
@using Hcs.WebApp.Data @using Hcs.WebApp.Data
@using Microsoft.AspNetCore.Components.Authorization @using Microsoft.AspNetCore.Components.Authorization