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 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;"> <RadzenCardGroup Responsive="true">
<RadzenCardGroup Responsive="true"> <RadzenCard Variant="Variant.Filled">
<RadzenCard Variant="Variant.Filled"> <RadzenStack JustifyContent="JustifyContent.SpaceBetween" Gap="1rem">
<RadzenStack JustifyContent="JustifyContent.SpaceBetween" Gap="1rem"> <RadzenStack Orientation="Orientation.Vertical" AlignItems="AlignItems.Start" JustifyContent="JustifyContent.Normal">
<RadzenStack Orientation="Orientation.Vertical" AlignItems="AlignItems.Start" JustifyContent="JustifyContent.Normal"> <RadzenText TextStyle="TextStyle.H6">Сервис nsi</RadzenText>
<RadzenText TextStyle="TextStyle.H6">Сервис nsi</RadzenText> <RadzenButton Click=@(() => OnNsiExportItem1Click()) Disabled=@inputDisabled Text="Экспорт НСИ 1" ButtonStyle="ButtonStyle.Primary" />
<RadzenButton Click=@(() => OnNsiExportItem1Click()) Disabled=@inputDisabled Text="Экспорт НСИ 1" ButtonStyle="ButtonStyle.Primary" />
</RadzenStack>
</RadzenStack> </RadzenStack>
</RadzenCard> </RadzenStack>
</RadzenCardGroup> </RadzenCard>
</div> </RadzenCardGroup>
</RadzenSplitterPane> </div>
<RadzenSplitterPane> </RadzenSplitterPane>
<RadzenTabs RenderMode="TabRenderMode.Client" Style="height: 100%;"> <RadzenSplitterPane>
<Tabs> <RadzenTabs RenderMode="TabRenderMode.Client" Style="height: 100%;">
<RadzenTabsItem Text="Запрос"> <Tabs>
<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 Text="Запрос">
</RadzenTabsItem> <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 Text="Результат"> </RadzenTabsItem>
<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 Text="Результат">
</RadzenTabsItem> <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" />
</Tabs> </RadzenTabsItem>
</RadzenTabs> </Tabs>
</RadzenSplitterPane> </RadzenTabs>
<RadzenSplitterPane Size="auto" Resizable="false"> </RadzenSplitterPane>
<EventConsole @ref=@console /> <RadzenSplitterPane Size="auto" Resizable="false">
</RadzenSplitterPane> <EventConsole @ref=@console />
</RadzenSplitter> </RadzenSplitterPane>
</AuthorizeView> </RadzenSplitter>
@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