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,49 +9,49 @@
@using Hcs.WebApp.Utils
@using Microsoft.AspNetCore.Authorization
@implements IDisposable
@attribute [Authorize]
@layout AuthorizedLayout
@implements IDisposable
@inject NavigationManager NavigationManager
@inject IConfiguration Configuration
@inject IClientProvider ClientProvider
<PageTitle>Тестирование экспорта</PageTitle>
<AuthorizeView Roles="@AppRole.ADMINISTRATOR_TYPE">
<RadzenSplitter Orientation="Orientation.Vertical" Style="height: 100%; border: 1px solid rgba(0,0,0,.08);">
<RadzenSplitterPane Size="200px">
<div style="height: 100%;overflow: auto;">
<RadzenCardGroup Responsive="true">
<RadzenCard Variant="Variant.Filled">
<RadzenStack JustifyContent="JustifyContent.SpaceBetween" Gap="1rem">
<RadzenStack Orientation="Orientation.Vertical" AlignItems="AlignItems.Start" JustifyContent="JustifyContent.Normal">
<RadzenText TextStyle="TextStyle.H6">Сервис nsi</RadzenText>
<RadzenButton Click=@(() => OnNsiExportItem1Click()) Disabled=@inputDisabled Text="Экспорт НСИ 1" ButtonStyle="ButtonStyle.Primary" />
</RadzenStack>
<RadzenSplitter Orientation="Orientation.Vertical" Style="height: 100%; border: 1px solid rgba(0,0,0,.08);">
<RadzenSplitterPane Size="200px">
<div style="height: 100%;overflow: auto;">
<RadzenCardGroup Responsive="true">
<RadzenCard Variant="Variant.Filled">
<RadzenStack JustifyContent="JustifyContent.SpaceBetween" Gap="1rem">
<RadzenStack Orientation="Orientation.Vertical" AlignItems="AlignItems.Start" JustifyContent="JustifyContent.Normal">
<RadzenText TextStyle="TextStyle.H6">Сервис nsi</RadzenText>
<RadzenButton Click=@(() => OnNsiExportItem1Click()) Disabled=@inputDisabled Text="Экспорт НСИ 1" ButtonStyle="ButtonStyle.Primary" />
</RadzenStack>
</RadzenCard>
</RadzenCardGroup>
</div>
</RadzenSplitterPane>
<RadzenSplitterPane>
<RadzenTabs RenderMode="TabRenderMode.Client" Style="height: 100%;">
<Tabs>
<RadzenTabsItem Text="Запрос">
<RadzenTextArea @ref=@messageTextArea Value=@messageBody Disabled="true" ReadOnly="true" Style="resize: none; white-space: pre; overflow-wrap: normal; overflow-x: auto;" class="rz-w-stretch" />
</RadzenTabsItem>
<RadzenTabsItem Text="Результат">
<RadzenTextArea @ref=@responseTextArea Value=@responseBody Disabled="true" ReadOnly="true" Style="resize: none; white-space: pre; overflow-wrap: normal; overflow-x: auto;" class="rz-w-stretch" />
</RadzenTabsItem>
</Tabs>
</RadzenTabs>
</RadzenSplitterPane>
<RadzenSplitterPane Size="auto" Resizable="false">
<EventConsole @ref=@console />
</RadzenSplitterPane>
</RadzenSplitter>
</AuthorizeView>
</RadzenStack>
</RadzenCard>
</RadzenCardGroup>
</div>
</RadzenSplitterPane>
<RadzenSplitterPane>
<RadzenTabs RenderMode="TabRenderMode.Client" Style="height: 100%;">
<Tabs>
<RadzenTabsItem Text="Запрос">
<RadzenTextArea @ref=@messageTextArea Value=@messageBody Disabled="true" ReadOnly="true" Style="resize: none; white-space: pre; overflow-wrap: normal; overflow-x: auto;" class="rz-w-stretch" />
</RadzenTabsItem>
<RadzenTabsItem Text="Результат">
<RadzenTextArea @ref=@responseTextArea Value=@responseBody Disabled="true" ReadOnly="true" Style="resize: none; white-space: pre; overflow-wrap: normal; overflow-x: auto;" class="rz-w-stretch" />
</RadzenTabsItem>
</Tabs>
</RadzenTabs>
</RadzenSplitterPane>
<RadzenSplitterPane Size="auto" Resizable="false">
<EventConsole @ref=@console />
</RadzenSplitterPane>
</RadzenSplitter>
@code {
EventConsole console = default!;
@ -66,10 +66,15 @@
FileMessageCapturer messageCapturer;
bool catchMessageBody;
[CascadingParameter]
public AuthorizedLayout Layout { get; set; }
protected override void OnInitialized()
{
base.OnInitialized();
Layout.Roles = AppRole.ADMINISTRATOR_TYPE;
logger.OnWriteLine += OnLog;
messageCapturer = new FileMessageCapturer("test/export", logger);

View File

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