chore: remove AuthorizeReuseTabsRouteView component and library (#3437)

This commit is contained in:
James Yeung 2023-09-22 00:36:01 +08:00 committed by GitHub
parent d924e1c981
commit 686ab39c86
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 9 additions and 313 deletions

View File

@ -39,8 +39,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AntDesign.Tests.Js", "tests
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AntDesign.Docs.Build", "site\AntDesign.Docs.Build\AntDesign.Docs.Build.csproj", "{67E9D6C5-106F-412C-B43C-F096145FD8A9}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AntDesign.Components.Authentication", "src\AntDesign.Components.Authentication\AntDesign.Components.Authentication.csproj", "{88E00D83-912A-4AC4-9A6D-34F87DC3A675}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "AntDesign.TestApp", "AntDesign.TestApp", "{606789E3-AFE9-4489-9963-2B06A701D6B6}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AntDesign.TestApp.Server", "tests\AntDesign.TestApp\Server\AntDesign.TestApp.Server.csproj", "{32A251DB-FF95-4325-B80F-0E3B0FA5CBC5}"
@ -93,10 +91,6 @@ Global
{67E9D6C5-106F-412C-B43C-F096145FD8A9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{67E9D6C5-106F-412C-B43C-F096145FD8A9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{67E9D6C5-106F-412C-B43C-F096145FD8A9}.Release|Any CPU.Build.0 = Release|Any CPU
{88E00D83-912A-4AC4-9A6D-34F87DC3A675}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{88E00D83-912A-4AC4-9A6D-34F87DC3A675}.Debug|Any CPU.Build.0 = Debug|Any CPU
{88E00D83-912A-4AC4-9A6D-34F87DC3A675}.Release|Any CPU.ActiveCfg = Release|Any CPU
{88E00D83-912A-4AC4-9A6D-34F87DC3A675}.Release|Any CPU.Build.0 = Release|Any CPU
{32A251DB-FF95-4325-B80F-0E3B0FA5CBC5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{32A251DB-FF95-4325-B80F-0E3B0FA5CBC5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{32A251DB-FF95-4325-B80F-0E3B0FA5CBC5}.Release|Any CPU.ActiveCfg = Release|Any CPU
@ -120,7 +114,6 @@ Global
{51D7507D-48BA-43BB-8223-CE35A2D7D0D8} = {DFD13180-D1BF-44DA-BEBE-4A54EFDEFFE2}
{3C4ADCD5-6879-4478-9BA5-28C894AD52F3} = {DFD13180-D1BF-44DA-BEBE-4A54EFDEFFE2}
{67E9D6C5-106F-412C-B43C-F096145FD8A9} = {D34F1DE5-ECF7-4CF0-8325-B7A38F41D376}
{88E00D83-912A-4AC4-9A6D-34F87DC3A675} = {C60BCE84-4AF4-4393-8D3E-1B69E29549C1}
{606789E3-AFE9-4489-9963-2B06A701D6B6} = {DFD13180-D1BF-44DA-BEBE-4A54EFDEFFE2}
{32A251DB-FF95-4325-B80F-0E3B0FA5CBC5} = {606789E3-AFE9-4489-9963-2B06A701D6B6}
{5ADDB648-9417-4FE9-8A7D-0D4BF2DD3EC5} = {606789E3-AFE9-4489-9963-2B06A701D6B6}

View File

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFrameworks>net7</TargetFrameworks>
<TargetFrameworks>net8</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
@ -35,6 +35,12 @@
</PackageReference>
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net8'">
<PackageReference Include="BlazorPolyfill.Server">
<Version>6.0.100.1</Version>
</PackageReference>
</ItemGroup>
<Target Name="CopyDocs" BeforeTargets="Build">
<Copy SourceFiles="@(DocFiles)" DestinationFolder="$(ProjectDir)\wwwroot\docs\%(RecursiveDir)" ContinueOnError="true" />
</Target>

View File

@ -2,6 +2,7 @@
<PropertyGroup>
<TargetFrameworks>net6;net7;net8</TargetFrameworks>
<LangVersion>latest</LangVersion>
</PropertyGroup>
<ItemGroup>

View File

@ -1,48 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netstandard2.1;net5;net6</TargetFrameworks>
<LangVersion>10.0</LangVersion>
<OutputType>Library</OutputType>
<IsPackable>true</IsPackable>
<RazorLangVersion>3.0</RazorLangVersion>
<Description>🌈 An authentication extensions components for Ant Design Blazor library. </Description>
<PackageProjectUrl>https://github.com/ant-design-blazor/ant-design-blazor</PackageProjectUrl>
<RepositoryUrl>https://github.com/ant-design-blazor/ant-design-blazor</RepositoryUrl>
<PackageTags>blazor,ant-design,antd,design,razor,components</PackageTags>
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
<RepositoryType>git</RepositoryType>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<Copyright>.NET Foundation and Contributors</Copyright>
<Authors>James Yeung</Authors>
<PackageIcon>logo.png</PackageIcon>
<NoWarn>CA2007</NoWarn>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<EmbedUntrackedSources>true</EmbedUntrackedSources>
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<PackageReadmeFile>README.md</PackageReadmeFile>
</PropertyGroup>
<ItemGroup Condition="$(TargetFramework) == 'netstandard2.1'">
<PackageReference Include="Microsoft.AspNetCore.Components.Authorization" Version="3.1.0" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net5'">
<PackageReference Include="Microsoft.AspNetCore.Components.Authorization" Version="5.0.0" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net6'">
<PackageReference Include="Microsoft.AspNetCore.Components.Authorization" Version="6.0.0" />
</ItemGroup>
<ItemGroup>
<None Include="..\..\components\logo.png" Pack="true" PackagePath="" />
<None Include="..\..\README.md" Pack="true" PackagePath="" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\components\AntDesign.csproj" />
</ItemGroup>
</Project>

View File

@ -1,54 +0,0 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Text;
using Microsoft.AspNetCore.Authorization;
namespace AntDesign.Components.Authentication
{
/// <summary>
/// This class is copy from the official repo.
/// source: https://github.com/dotnet/aspnetcore/blob/main/src/Components/Authorization/src/AttributeAuthorizeDataCache.cs
/// </summary>
internal static class AttributeAuthorizeDataCache
{
private static readonly ConcurrentDictionary<Type, IAuthorizeData[]?> _cache = new ConcurrentDictionary<Type, IAuthorizeData[]?>();
public static IAuthorizeData[]? GetAuthorizeDataForType(Type type)
{
if (!_cache.TryGetValue(type, out var result))
{
result = ComputeAuthorizeDataForType(type);
_cache[type] = result; // Safe race - doesn't matter if it overwrites
}
return result;
}
private static IAuthorizeData[]? ComputeAuthorizeDataForType(Type type)
{
// Allow Anonymous skips all authorization
var allAttributes = type.GetCustomAttributes(inherit: true);
List<IAuthorizeData>? authorizeDatas = null;
for (var i = 0; i < allAttributes.Length; i++)
{
if (allAttributes[i] is IAllowAnonymous)
{
return null;
}
if (allAttributes[i] is IAuthorizeData authorizeData)
{
authorizeDatas ??= new List<IAuthorizeData>();
authorizeDatas.Add(authorizeData);
}
}
return authorizeDatas?.ToArray();
}
}
}

View File

@ -1,138 +0,0 @@
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Authorization;
using Microsoft.AspNetCore.Components.Rendering;
namespace AntDesign.Components.Authentication
{
/// <summary>
/// This class is modify from the official AuthorizeRouteView.cs
/// source: https://github.com/dotnet/aspnetcore/blob/main/src/Components/Authorization/src/AuthorizeRouteView.cs
///
/// Combines the behaviors of <see cref="AuthorizeView"/> and <see cref="RouteView"/>,
/// so that it displays the page matching the specified route but only if the user
/// is authorized to see it.
///
/// Additionally, this component supplies a cascading parameter of type <see cref="Task{AuthenticationState}"/>,
/// which makes the user's current authentication state available to descendants.
/// </summary>
[Obsolete("Pleaes use <CascadingValue Value=\"RouteData\"> to warp the AuthorizeRouteView.")]
public sealed class AuthorizeReuseTabsRouteView : ReuseTabsRouteView
{
// We expect applications to supply their own authorizing/not-authorized content, but
// it's better to have defaults than to make the parameters mandatory because in some
// cases they will never be used (e.g., "authorizing" in out-of-box server-side Blazor)
private static readonly RenderFragment<AuthenticationState> _defaultNotAuthorizedContent
= state => builder => builder.AddContent(0, "Not authorized");
private static readonly RenderFragment _defaultAuthorizingContent
= builder => builder.AddContent(0, "Authorizing...");
private readonly RenderFragment _renderAuthorizeRouteViewCoreDelegate;
private readonly RenderFragment<AuthenticationState> _renderAuthorizedDelegate;
private readonly RenderFragment<AuthenticationState> _renderNotAuthorizedDelegate;
private readonly RenderFragment _renderAuthorizingDelegate;
/// <summary>
/// Initialize a new instance of a <see cref="AuthorizeRouteView"/>.
/// </summary>
public AuthorizeReuseTabsRouteView()
{
// Cache the rendering delegates so that we only construct new closure instances
// when they are actually used (e.g., we never prepare a RenderFragment bound to
// the NotAuthorized content except when you are displaying that particular state)
RenderFragment renderBaseRouteViewDelegate = builder => base.Render(builder);
_renderAuthorizedDelegate = authenticateState => renderBaseRouteViewDelegate;
_renderNotAuthorizedDelegate = authenticationState => builder => RenderNotAuthorizedInDefaultLayout(builder, authenticationState);
_renderAuthorizingDelegate = RenderAuthorizingInDefaultLayout;
_renderAuthorizeRouteViewCoreDelegate = RenderAuthorizeRouteViewCore;
}
/// <summary>
/// The content that will be displayed if the user is not authorized.
/// </summary>
[Parameter]
public RenderFragment<AuthenticationState>? NotAuthorized { get; set; }
/// <summary>
/// The content that will be displayed while asynchronous authorization is in progress.
/// </summary>
[Parameter]
public RenderFragment? Authorizing { get; set; }
/// <summary>
/// The resource to which access is being controlled.
/// </summary>
[Parameter]
public object? Resource { get; set; }
[CascadingParameter]
private Task<AuthenticationState>? ExistingCascadedAuthenticationState { get; set; }
/// <inheritdoc />
protected override void Render(RenderTreeBuilder builder)
{
if (ExistingCascadedAuthenticationState != null)
{
// If this component is already wrapped in a <CascadingAuthenticationState> (or another
// compatible provider), then don't interfere with the cascaded authentication state.
_renderAuthorizeRouteViewCoreDelegate(builder);
}
else
{
// Otherwise, implicitly wrap the output in a <CascadingAuthenticationState>
builder.OpenComponent<CascadingAuthenticationState>(0);
builder.AddAttribute(1, nameof(CascadingAuthenticationState.ChildContent), _renderAuthorizeRouteViewCoreDelegate);
builder.CloseComponent();
}
}
private void RenderAuthorizeRouteViewCore(RenderTreeBuilder builder)
{
builder.OpenComponent<AuthorizeRouteViewCore>(0);
builder.AddAttribute(1, nameof(AuthorizeRouteViewCore.RouteData), RouteData);
builder.AddAttribute(2, nameof(AuthorizeRouteViewCore.Authorized), _renderAuthorizedDelegate);
builder.AddAttribute(3, nameof(AuthorizeRouteViewCore.Authorizing), _renderAuthorizingDelegate);
builder.AddAttribute(4, nameof(AuthorizeRouteViewCore.NotAuthorized), _renderNotAuthorizedDelegate);
builder.AddAttribute(5, nameof(AuthorizeRouteViewCore.Resource), Resource);
builder.CloseComponent();
}
//[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2111:RequiresUnreferencedCode",
// Justification = "OpenComponent already has the right set of attributes")]
//[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2110:RequiresUnreferencedCode",
// Justification = "OpenComponent already has the right set of attributes")]
private void RenderContentInDefaultLayout(RenderTreeBuilder builder, RenderFragment content)
{
builder.OpenComponent<LayoutView>(0);
builder.AddAttribute(1, nameof(LayoutView.Layout), DefaultLayout);
builder.AddAttribute(2, nameof(LayoutView.ChildContent), content);
builder.CloseComponent();
}
private void RenderNotAuthorizedInDefaultLayout(RenderTreeBuilder builder, AuthenticationState authenticationState)
{
var content = NotAuthorized ?? _defaultNotAuthorizedContent;
RenderContentInDefaultLayout(builder, content(authenticationState));
}
private void RenderAuthorizingInDefaultLayout(RenderTreeBuilder builder)
{
var content = Authorizing ?? _defaultAuthorizingContent;
RenderContentInDefaultLayout(builder, content);
}
private sealed class AuthorizeRouteViewCore : AuthorizeViewCore
{
[Parameter]
public RouteData RouteData { get; set; } = default!;
protected override IAuthorizeData[]? GetAuthorizeData()
=> AttributeAuthorizeDataCache.GetAuthorizeDataForType(RouteData.PageType);
}
}
}

View File

@ -1,63 +0,0 @@
# AuthorizeReuseTabsRouteView
A combination of `ReuseTabsRouteView` and `AuthorizeRouteView`.
# How to use
Almost the same as `AuthorizeRouteView`.
1. Modify the `App.razor` file, replace the `RouteView` or `ReuseTabsRouteView` with `AuthorizeReuseTabsRouteView`.
```diff
+<CascadingAuthenticationState>
<Router AppAssembly="@typeof(Program).Assembly" PreferExactMatches="@true">
<Found Context="routeData">
- <RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" />
+ <AuthorizeReuseTabsRouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)">
+ <NotAuthorized>
+ <RedirectToLogin />
+ </NotAuthorized>
+ <Authorizing>
+ <p>Authorizing............</p>
+ </Authorizing>
+ </AuthorizeReuseTabsRouteView>
</Found>
<NotFound>
<LayoutView Layout="@typeof(MainLayout)">
<p>Sorry, there's nothing at this address.</p>
</LayoutView>
</NotFound>
</Router>
+</CascadingAuthenticationState>
```
2. Then modify the `MainLayout.razor` file, add the `ReuseTabs` component. Note that `@Body` is **required** at this case, so you can perform redirect and other actions.
```diff
@inherits LayoutComponentBase
<div class="page">
<div class="sidebar">
<NavMenu />
</div>
<div class="main">
- <div class="top-row px-4">
- <a href="http://blazor.net" target="_blank" class="ml-md-auto">About</a>
- </div>
<div class="content px-4">
@Body
</div>
+ <ReuseTabs Class="top-row px-4" TabPaneClass="content px-4" / >
</div>
</div>
```
# Customize tab title
Same as `ReuseTabsRouteView`

View File

@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk.BlazorWebAssembly">
<Project Sdk="Microsoft.NET.Sdk.BlazorWebAssembly">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
@ -14,7 +14,6 @@
<ItemGroup>
<ProjectReference Include="..\..\..\components\AntDesign.csproj" />
<ProjectReference Include="..\..\..\src\AntDesign.Components.Authentication\AntDesign.Components.Authentication.csproj" />
</ItemGroup>
</Project>