mirror of https://github.com/abpframework/abp.git
81 changed files with 726 additions and 74 deletions
@ -0,0 +1,3 @@ |
|||||
|
# IdentityServer Module |
||||
|
|
||||
|
TODO |
||||
@ -0,0 +1,13 @@ |
|||||
|
using Volo.Abp.AspNetCore.Serilog; |
||||
|
|
||||
|
namespace Microsoft.AspNetCore.Builder |
||||
|
{ |
||||
|
public static class AbpAspNetCoreSerilogApplicationBuilderExtensions |
||||
|
{ |
||||
|
public static IApplicationBuilder UseAbpSerilogEnrichers(this IApplicationBuilder app) |
||||
|
{ |
||||
|
return app |
||||
|
.UseMiddleware<AbpSerilogMiddleware>(); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,27 @@ |
|||||
|
{ |
||||
|
"iisSettings": { |
||||
|
"windowsAuthentication": false, |
||||
|
"anonymousAuthentication": true, |
||||
|
"iisExpress": { |
||||
|
"applicationUrl": "http://localhost:61851/", |
||||
|
"sslPort": 44301 |
||||
|
} |
||||
|
}, |
||||
|
"profiles": { |
||||
|
"IIS Express": { |
||||
|
"commandName": "IISExpress", |
||||
|
"launchBrowser": true, |
||||
|
"environmentVariables": { |
||||
|
"ASPNETCORE_ENVIRONMENT": "Development" |
||||
|
} |
||||
|
}, |
||||
|
"Volo.Abp.AspNetCore.Serilog": { |
||||
|
"commandName": "Project", |
||||
|
"launchBrowser": true, |
||||
|
"environmentVariables": { |
||||
|
"ASPNETCORE_ENVIRONMENT": "Development" |
||||
|
}, |
||||
|
"applicationUrl": "https://localhost:5001;http://localhost:5000" |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,27 @@ |
|||||
|
<Project Sdk="Microsoft.NET.Sdk.Web"> |
||||
|
|
||||
|
<Import Project="..\..\..\common.props" /> |
||||
|
|
||||
|
<PropertyGroup> |
||||
|
<TargetFramework>netcoreapp3.1</TargetFramework> |
||||
|
<AssemblyName>Volo.Abp.AspNetCore.Serilog</AssemblyName> |
||||
|
<PackageId>Volo.Abp.AspNetCore.Serilog</PackageId> |
||||
|
<AssetTargetFallback>$(AssetTargetFallback);portable-net45+win8+wp8+wpa81;</AssetTargetFallback> |
||||
|
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute> |
||||
|
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute> |
||||
|
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute> |
||||
|
<IsPackable>true</IsPackable> |
||||
|
<OutputType>Library</OutputType> |
||||
|
<RootNamespace /> |
||||
|
</PropertyGroup> |
||||
|
|
||||
|
<ItemGroup> |
||||
|
<ProjectReference Include="..\Volo.Abp.AspNetCore\Volo.Abp.AspNetCore.csproj" /> |
||||
|
<ProjectReference Include="..\Volo.Abp.MultiTenancy\Volo.Abp.MultiTenancy.csproj" /> |
||||
|
</ItemGroup> |
||||
|
|
||||
|
<ItemGroup> |
||||
|
<PackageReference Include="Serilog" Version="2.8.0" /> |
||||
|
</ItemGroup> |
||||
|
|
||||
|
</Project> |
||||
@ -0,0 +1,13 @@ |
|||||
|
using Volo.Abp.Modularity; |
||||
|
using Volo.Abp.MultiTenancy; |
||||
|
|
||||
|
namespace Volo.Abp.AspNetCore.Serilog |
||||
|
{ |
||||
|
[DependsOn( |
||||
|
typeof(AbpMultiTenancyModule), |
||||
|
typeof(AbpAspNetCoreModule) |
||||
|
)] |
||||
|
public class AbpAspNetCoreSerilogModule : AbpModule |
||||
|
{ |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,30 @@ |
|||||
|
namespace Volo.Abp.AspNetCore.Serilog |
||||
|
{ |
||||
|
public class AbpAspNetCoreSerilogOptions |
||||
|
{ |
||||
|
public AllEnricherPropertyNames EnricherPropertyNames { get; } = new AllEnricherPropertyNames(); |
||||
|
|
||||
|
public class AllEnricherPropertyNames |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// Default value: "TenantId".
|
||||
|
/// </summary>
|
||||
|
public string TenantId { get; set; } = "TenantId"; |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Default value: "UserId".
|
||||
|
/// </summary>
|
||||
|
public string UserId { get; set; } = "UserId"; |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Default value: "ClientId".
|
||||
|
/// </summary>
|
||||
|
public string ClientId { get; set; } = "ClientId"; |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Default value: "CorrelationId".
|
||||
|
/// </summary>
|
||||
|
public string CorrelationId { get; set; } = "CorrelationId"; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,69 @@ |
|||||
|
using System.Collections.Generic; |
||||
|
using System.Threading.Tasks; |
||||
|
using Microsoft.AspNetCore.Http; |
||||
|
using Microsoft.Extensions.Options; |
||||
|
using Serilog.Context; |
||||
|
using Serilog.Core; |
||||
|
using Serilog.Core.Enrichers; |
||||
|
using Volo.Abp.Clients; |
||||
|
using Volo.Abp.DependencyInjection; |
||||
|
using Volo.Abp.MultiTenancy; |
||||
|
using Volo.Abp.Tracing; |
||||
|
using Volo.Abp.Users; |
||||
|
|
||||
|
namespace Volo.Abp.AspNetCore.Serilog |
||||
|
{ |
||||
|
public class AbpSerilogMiddleware : IMiddleware, ITransientDependency |
||||
|
{ |
||||
|
private readonly ICurrentClient _currentClient; |
||||
|
private readonly ICurrentTenant _currentTenant; |
||||
|
private readonly ICurrentUser _currentUser; |
||||
|
private readonly ICorrelationIdProvider _correlationIdProvider; |
||||
|
private readonly AbpAspNetCoreSerilogOptions _options; |
||||
|
|
||||
|
public AbpSerilogMiddleware( |
||||
|
ICurrentTenant currentTenant, |
||||
|
ICurrentUser currentUser, |
||||
|
ICurrentClient currentClient, |
||||
|
ICorrelationIdProvider correlationIdProvider, |
||||
|
IOptions<AbpAspNetCoreSerilogOptions> options) |
||||
|
{ |
||||
|
_currentTenant = currentTenant; |
||||
|
_currentUser = currentUser; |
||||
|
_currentClient = currentClient; |
||||
|
_correlationIdProvider = correlationIdProvider; |
||||
|
_options = options.Value; |
||||
|
} |
||||
|
|
||||
|
public async Task InvokeAsync(HttpContext context, RequestDelegate next) |
||||
|
{ |
||||
|
var enrichers = new List<ILogEventEnricher>(); |
||||
|
|
||||
|
if (_currentTenant?.Id != null) |
||||
|
{ |
||||
|
enrichers.Add(new PropertyEnricher(_options.EnricherPropertyNames.TenantId, _currentTenant.Id)); |
||||
|
} |
||||
|
|
||||
|
if (_currentUser?.Id != null) |
||||
|
{ |
||||
|
enrichers.Add(new PropertyEnricher(_options.EnricherPropertyNames.UserId, _currentUser.Id)); |
||||
|
} |
||||
|
|
||||
|
if (_currentClient?.Id != null) |
||||
|
{ |
||||
|
enrichers.Add(new PropertyEnricher(_options.EnricherPropertyNames.ClientId, _currentClient.Id)); |
||||
|
} |
||||
|
|
||||
|
var correlationId = _correlationIdProvider.Get(); |
||||
|
if (!string.IsNullOrEmpty(correlationId)) |
||||
|
{ |
||||
|
enrichers.Add(new PropertyEnricher(_options.EnricherPropertyNames.CorrelationId, correlationId)); |
||||
|
} |
||||
|
|
||||
|
using (LogContext.Push(enrichers.ToArray())) |
||||
|
{ |
||||
|
await next(context).ConfigureAwait(false); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,24 @@ |
|||||
|
<Project Sdk="Microsoft.NET.Sdk"> |
||||
|
|
||||
|
<Import Project="..\..\..\common.test.props" /> |
||||
|
|
||||
|
<PropertyGroup> |
||||
|
<TargetFramework>netcoreapp3.1</TargetFramework> |
||||
|
<AssemblyName>Volo.Abp.AspNetCore.Serilog.Tests</AssemblyName> |
||||
|
<PackageId>Volo.Abp.AspNetCore.Serilog.Tests</PackageId> |
||||
|
<RootNamespace /> |
||||
|
</PropertyGroup> |
||||
|
|
||||
|
<ItemGroup> |
||||
|
<PackageReference Include="Serilog.AspNetCore" Version="3.2.0" /> |
||||
|
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.4.0" /> |
||||
|
</ItemGroup> |
||||
|
|
||||
|
<ItemGroup> |
||||
|
<ProjectReference Include="..\..\src\Volo.Abp.AspNetCore.MultiTenancy\Volo.Abp.AspNetCore.MultiTenancy.csproj" /> |
||||
|
<ProjectReference Include="..\..\src\Volo.Abp.AspNetCore.Mvc\Volo.Abp.AspNetCore.Mvc.csproj" /> |
||||
|
<ProjectReference Include="..\..\src\Volo.Abp.AspNetCore.Serilog\Volo.Abp.AspNetCore.Serilog.csproj" /> |
||||
|
<ProjectReference Include="..\Volo.Abp.AspNetCore.Tests\Volo.Abp.AspNetCore.Tests.csproj" /> |
||||
|
</ItemGroup> |
||||
|
|
||||
|
</Project> |
||||
@ -0,0 +1,39 @@ |
|||||
|
using Microsoft.AspNetCore.Builder; |
||||
|
using Volo.Abp.AspNetCore.MultiTenancy; |
||||
|
using Volo.Abp.AspNetCore.Mvc; |
||||
|
using Volo.Abp.AspNetCore.Serilog; |
||||
|
using Volo.Abp.AspNetCore.TestBase; |
||||
|
using Volo.Abp.Autofac; |
||||
|
using Volo.Abp.Modularity; |
||||
|
using Volo.Abp.MultiTenancy; |
||||
|
|
||||
|
namespace Volo.Abp.AspNetCore.App |
||||
|
{ |
||||
|
[DependsOn( |
||||
|
typeof(AbpAspNetCoreTestBaseModule), |
||||
|
typeof(AbpAspNetCoreMvcModule), |
||||
|
typeof(AbpAspNetCoreMultiTenancyModule), |
||||
|
typeof(AbpAspNetCoreSerilogModule), |
||||
|
typeof(AbpAutofacModule) |
||||
|
)] |
||||
|
public class AbpSerilogTestModule : AbpModule |
||||
|
{ |
||||
|
public override void ConfigureServices(ServiceConfigurationContext context) |
||||
|
{ |
||||
|
Configure<AbpMultiTenancyOptions>(options => { options.IsEnabled = true; }); |
||||
|
} |
||||
|
|
||||
|
public override void OnApplicationInitialization(ApplicationInitializationContext context) |
||||
|
{ |
||||
|
var app = context.GetApplicationBuilder(); |
||||
|
|
||||
|
app.UseCorrelationId(); |
||||
|
app.UseRouting(); |
||||
|
app.UseAuthorization(); |
||||
|
app.UseMultiTenancy(); |
||||
|
app.UseAuditing(); |
||||
|
app.UseAbpSerilogEnrichers(); |
||||
|
app.UseMvcWithDefaultRouteAndArea(); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,19 @@ |
|||||
|
using System.Collections.Generic; |
||||
|
using System.Linq; |
||||
|
using Serilog.Core; |
||||
|
using Serilog.Events; |
||||
|
|
||||
|
namespace Volo.Abp.AspNetCore.App |
||||
|
{ |
||||
|
public class CollectingSink : ILogEventSink |
||||
|
{ |
||||
|
public List<LogEvent> Events { get; } = new List<LogEvent>(); |
||||
|
|
||||
|
public LogEvent SingleEvent => Events.Single(); |
||||
|
|
||||
|
public void Emit(LogEvent logEvent) |
||||
|
{ |
||||
|
Events.Add(logEvent); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,27 @@ |
|||||
|
using Microsoft.AspNetCore.Mvc; |
||||
|
using Microsoft.Extensions.Logging; |
||||
|
using Volo.Abp.AspNetCore.Mvc; |
||||
|
using Volo.Abp.Tracing; |
||||
|
|
||||
|
namespace Volo.Abp.AspNetCore.App |
||||
|
{ |
||||
|
public class SerilogTestController : AbpController |
||||
|
{ |
||||
|
private readonly ICorrelationIdProvider _correlationIdProvider; |
||||
|
|
||||
|
public SerilogTestController(ICorrelationIdProvider correlationIdProvider) |
||||
|
{ |
||||
|
_correlationIdProvider = correlationIdProvider; |
||||
|
} |
||||
|
|
||||
|
public ActionResult Index() |
||||
|
{ |
||||
|
return Content("Index-Result"); |
||||
|
} |
||||
|
|
||||
|
public ActionResult CorrelationId() |
||||
|
{ |
||||
|
return Content(_correlationIdProvider.Get()); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,20 @@ |
|||||
|
using Microsoft.AspNetCore.Builder; |
||||
|
using Microsoft.AspNetCore.Hosting; |
||||
|
using Microsoft.Extensions.DependencyInjection; |
||||
|
using Microsoft.Extensions.Logging; |
||||
|
|
||||
|
namespace Volo.Abp.AspNetCore.App |
||||
|
{ |
||||
|
public class Startup |
||||
|
{ |
||||
|
public void ConfigureServices(IServiceCollection services) |
||||
|
{ |
||||
|
services.AddApplication<AbpSerilogTestModule>(); |
||||
|
} |
||||
|
|
||||
|
public void Configure(IApplicationBuilder app, IWebHostEnvironment env,ILoggerFactory loggerFactory) |
||||
|
{ |
||||
|
app.InitializeApplication(); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,31 @@ |
|||||
|
using System.Linq; |
||||
|
using Microsoft.Extensions.Hosting; |
||||
|
using Serilog; |
||||
|
using Serilog.Events; |
||||
|
using Volo.Abp.AspNetCore.App; |
||||
|
|
||||
|
namespace Volo.Abp.AspNetCore.Serilog |
||||
|
{ |
||||
|
public class AbpSerilogTestBase : AbpAspNetCoreTestBase<App.Startup> |
||||
|
{ |
||||
|
protected readonly CollectingSink CollectingSink = new CollectingSink(); |
||||
|
|
||||
|
protected override IHostBuilder CreateHostBuilder() |
||||
|
{ |
||||
|
Log.Logger = new LoggerConfiguration() |
||||
|
.MinimumLevel.Information() |
||||
|
.MinimumLevel.Override("Microsoft", LogEventLevel.Information) |
||||
|
.Enrich.FromLogContext() |
||||
|
.WriteTo.Sink(CollectingSink) |
||||
|
.CreateLogger(); |
||||
|
|
||||
|
return base.CreateHostBuilder() |
||||
|
.UseSerilog(); |
||||
|
} |
||||
|
|
||||
|
protected LogEvent GetLogEvent(string text) |
||||
|
{ |
||||
|
return CollectingSink.Events.FirstOrDefault(m => m.MessageTemplate.Text == text); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,97 @@ |
|||||
|
using System; |
||||
|
using System.Threading.Tasks; |
||||
|
using Microsoft.Extensions.DependencyInjection; |
||||
|
using Microsoft.Extensions.Hosting; |
||||
|
using Microsoft.Extensions.Logging; |
||||
|
using Microsoft.Extensions.Options; |
||||
|
using Serilog.Events; |
||||
|
using Shouldly; |
||||
|
using Volo.Abp.AspNetCore.App; |
||||
|
using Volo.Abp.AspNetCore.MultiTenancy; |
||||
|
using Volo.Abp.MultiTenancy; |
||||
|
using Volo.Abp.MultiTenancy.ConfigurationStore; |
||||
|
using Xunit; |
||||
|
|
||||
|
namespace Volo.Abp.AspNetCore.Serilog |
||||
|
{ |
||||
|
public class Serilog_Enrichers_Tests : AbpSerilogTestBase |
||||
|
{ |
||||
|
private const string ExecutedEndpointLogEventText = "Executed endpoint '{EndpointName}'"; |
||||
|
|
||||
|
private readonly Guid _testTenantId = Guid.NewGuid(); |
||||
|
private readonly string _testTenantName = "acme"; |
||||
|
|
||||
|
private readonly AbpAspNetCoreMultiTenancyOptions _tenancyOptions; |
||||
|
private readonly AbpAspNetCoreSerilogOptions _serilogOptions; |
||||
|
private readonly ILogger<Serilog_Enrichers_Tests> _logger; |
||||
|
|
||||
|
public Serilog_Enrichers_Tests() |
||||
|
{ |
||||
|
_tenancyOptions = ServiceProvider.GetRequiredService<IOptions<AbpAspNetCoreMultiTenancyOptions>>().Value; |
||||
|
_serilogOptions = |
||||
|
ServiceProvider.GetRequiredService<IOptions<AbpAspNetCoreSerilogOptions>>().Value; |
||||
|
_logger = ServiceProvider.GetRequiredService<ILogger<Serilog_Enrichers_Tests>>(); |
||||
|
} |
||||
|
|
||||
|
protected override IHostBuilder CreateHostBuilder() |
||||
|
{ |
||||
|
return base.CreateHostBuilder().ConfigureServices(services => |
||||
|
{ |
||||
|
services.Configure<AbpDefaultTenantStoreOptions>(options => |
||||
|
{ |
||||
|
options.Tenants = new[] |
||||
|
{ |
||||
|
new TenantConfiguration(_testTenantId, _testTenantName) |
||||
|
}; |
||||
|
}); |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
[Fact] |
||||
|
public async Task TenantId_Not_Set_Test() |
||||
|
{ |
||||
|
var url = GetUrl<SerilogTestController>(nameof(SerilogTestController.Index)); |
||||
|
var result = await GetResponseAsStringAsync(url).ConfigureAwait(false); |
||||
|
|
||||
|
var executedLogEvent = GetLogEvent(ExecutedEndpointLogEventText); |
||||
|
|
||||
|
executedLogEvent.ShouldNotBeNull(); |
||||
|
executedLogEvent.Properties.ContainsKey(_serilogOptions.EnricherPropertyNames.TenantId) |
||||
|
.ShouldBe(false); |
||||
|
} |
||||
|
|
||||
|
[Fact] |
||||
|
public async Task TenantId_Set_Test() |
||||
|
{ |
||||
|
var url = |
||||
|
GetUrl<SerilogTestController>(nameof(SerilogTestController.Index)) + |
||||
|
$"?{_tenancyOptions.TenantKey}={_testTenantName}"; |
||||
|
var result = await GetResponseAsStringAsync(url).ConfigureAwait(false); |
||||
|
|
||||
|
var executedLogEvent = GetLogEvent(ExecutedEndpointLogEventText); |
||||
|
|
||||
|
executedLogEvent.ShouldNotBeNull(); |
||||
|
executedLogEvent.Properties.ContainsKey(_serilogOptions.EnricherPropertyNames.TenantId) |
||||
|
.ShouldBe(true); |
||||
|
((ScalarValue) executedLogEvent.Properties[_serilogOptions.EnricherPropertyNames.TenantId]).Value |
||||
|
.ShouldBe(_testTenantId); |
||||
|
} |
||||
|
|
||||
|
[Fact] |
||||
|
public async Task CorrelationId_Enrichers_Test() |
||||
|
{ |
||||
|
var url = GetUrl<SerilogTestController>(nameof(SerilogTestController.CorrelationId)); |
||||
|
var result = await GetResponseAsStringAsync(url).ConfigureAwait(false); |
||||
|
|
||||
|
var executedLogEvent = GetLogEvent(ExecutedEndpointLogEventText); |
||||
|
|
||||
|
executedLogEvent.ShouldNotBeNull(); |
||||
|
|
||||
|
executedLogEvent.Properties.ContainsKey(_serilogOptions.EnricherPropertyNames.CorrelationId) |
||||
|
.ShouldNotBeNull(); |
||||
|
|
||||
|
((ScalarValue) executedLogEvent.Properties[_serilogOptions.EnricherPropertyNames.CorrelationId]).Value |
||||
|
.ShouldBe(result); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -1,3 +1,10 @@ |
|||||
# Blogging Module |
# Blogging Module |
||||
|
|
||||
This module is used for ABP blog: https://abp.io/blog/abp/ |
This module adds a simple blog to your ABP application; |
||||
|
|
||||
|
* Allows to create multiple blogs in a single application. |
||||
|
* Supports the Markdown format. |
||||
|
* Allows to write comment for a post. |
||||
|
* Allows to assign tags to the blog posts. |
||||
|
|
||||
|
See the [blog.abp.io](https://blog.abp.io/) website as a live example of the blogging module. |
||||
@ -1,13 +1,15 @@ |
|||||
# Docs Module |
# Docs Module |
||||
This module is used to create technical documentation web sites. [abp.io](https://abp.io) web site uses this module for its documentation. |
This module is used to create technical documentation web sites; |
||||
|
|
||||
### Screenshot |
* Built-in **GitHub integration**: Directly write and manage documents on GitHub. |
||||
|
* **Versioning** support directly integrated to GitHub releases. |
||||
|
* Supports **multi-language** (with fallback support to the default language). |
||||
|
* Supports the **Markdown** and HTML formats. |
||||
|
* Provides a **navigation** and an **outline** section. |
||||
|
* Allows to host **multiple projects** documentation in a single application. |
||||
|
* Links to the file on GitHub, so anyone can easily contribute by clicking to the **Edit link**. |
||||
|
* In addition to the GitHub source, allows to simply use a folder as the documentation source. |
||||
|
|
||||
 |
ABP Framework uses this module to host its documentation. See [docs.abp.io](https://docs.abp.io/). A screenshot from the ABP documentation: |
||||
|
|
||||
### Main Features |
 |
||||
|
|
||||
* Retrieves documents from a Github repository. |
|
||||
* Supports Markdown document formatting. |
|
||||
* Supports versioning (integrated to Github releases). |
|
||||
* Supports multiple projects. |
|
||||
|
|||||
|
Before Width: | Height: | Size: 118 KiB |
|
After Width: | Height: | Size: 260 KiB |
@ -0,0 +1,8 @@ |
|||||
|
namespace Volo.Abp.Identity |
||||
|
{ |
||||
|
public class IdentityRoleNameChangedEvent |
||||
|
{ |
||||
|
public IdentityRole IdentityRole { get; set; } |
||||
|
public string OldName { get; set; } |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,43 @@ |
|||||
|
using System.Threading.Tasks; |
||||
|
using Volo.Abp.Authorization.Permissions; |
||||
|
using Volo.Abp.DependencyInjection; |
||||
|
using Volo.Abp.Domain.Entities.Events; |
||||
|
using Volo.Abp.EventBus; |
||||
|
using Volo.Abp.Identity; |
||||
|
|
||||
|
namespace Volo.Abp.PermissionManagement.Identity |
||||
|
{ |
||||
|
public class RoleUpdateEventHandler : |
||||
|
ILocalEventHandler<IdentityRoleNameChangedEvent>, |
||||
|
ITransientDependency |
||||
|
{ |
||||
|
protected IIdentityRoleRepository RoleRepository { get; } |
||||
|
protected IPermissionManager PermissionManager { get; } |
||||
|
protected IPermissionGrantRepository PermissionGrantRepository { get; } |
||||
|
|
||||
|
public RoleUpdateEventHandler( |
||||
|
IIdentityRoleRepository roleRepository, |
||||
|
IPermissionManager permissionManager, |
||||
|
IPermissionGrantRepository permissionGrantRepository) |
||||
|
{ |
||||
|
RoleRepository = roleRepository; |
||||
|
PermissionManager = permissionManager; |
||||
|
PermissionGrantRepository = permissionGrantRepository; |
||||
|
} |
||||
|
|
||||
|
public async Task HandleEventAsync(IdentityRoleNameChangedEvent eventData) |
||||
|
{ |
||||
|
var role = await RoleRepository.FindAsync(eventData.IdentityRole.Id, false).ConfigureAwait(false); |
||||
|
if (role == null) |
||||
|
{ |
||||
|
return; |
||||
|
} |
||||
|
|
||||
|
var permissionGrantsInRole = await PermissionGrantRepository.GetListAsync(RolePermissionValueProvider.ProviderName, eventData.OldName).ConfigureAwait(false); |
||||
|
foreach (var permissionGrant in permissionGrantsInRole) |
||||
|
{ |
||||
|
await PermissionManager.UpdateProviderKeyAsync(permissionGrant, eventData.IdentityRole.Name).ConfigureAwait(false); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,58 @@ |
|||||
|
using Microsoft.AspNetCore.Identity; |
||||
|
using Shouldly; |
||||
|
using System.Threading.Tasks; |
||||
|
using Volo.Abp.EventBus.Distributed; |
||||
|
using Volo.Abp.Guids; |
||||
|
using Volo.Abp.PermissionManagement; |
||||
|
using Volo.Abp.Uow; |
||||
|
using Xunit; |
||||
|
|
||||
|
namespace Volo.Abp.Identity |
||||
|
{ |
||||
|
public class RoleChangingEvents_Test : AbpIdentityDomainTestBase |
||||
|
{ |
||||
|
protected readonly IIdentityRoleRepository RoleRepository; |
||||
|
protected readonly IPermissionGrantRepository PermissionGrantRepository; |
||||
|
protected readonly IdentityRoleManager RoleManager; |
||||
|
protected readonly ILookupNormalizer LookupNormalizer; |
||||
|
protected readonly IGuidGenerator GuidGenerator; |
||||
|
protected readonly IUnitOfWorkManager UowManager; |
||||
|
|
||||
|
public RoleChangingEvents_Test() |
||||
|
{ |
||||
|
RoleRepository = GetRequiredService<IIdentityRoleRepository>(); ; |
||||
|
PermissionGrantRepository = GetRequiredService<IPermissionGrantRepository>(); ; |
||||
|
RoleManager = GetRequiredService<IdentityRoleManager>(); ; |
||||
|
LookupNormalizer = GetRequiredService<ILookupNormalizer>(); ; |
||||
|
GuidGenerator = GetRequiredService<IGuidGenerator>(); |
||||
|
UowManager = GetRequiredService<IUnitOfWorkManager>(); |
||||
|
} |
||||
|
|
||||
|
[Fact] |
||||
|
public async Task Role_Update_Event_Test() |
||||
|
{ |
||||
|
var role = await RoleRepository |
||||
|
.FindByNormalizedNameAsync(LookupNormalizer.NormalizeName("moderator")) |
||||
|
.ConfigureAwait(false); |
||||
|
|
||||
|
var permissionGrantsInRole = await PermissionGrantRepository.GetListAsync("R", role.Name).ConfigureAwait(false); |
||||
|
permissionGrantsInRole.ShouldNotBeNull(); |
||||
|
permissionGrantsInRole.Count.ShouldBeGreaterThan(0); |
||||
|
var count = permissionGrantsInRole.Count; |
||||
|
|
||||
|
using (var uow = UowManager.Begin()) |
||||
|
{ |
||||
|
var identityResult = await RoleManager.SetRoleNameAsync(role, "TestModerator").ConfigureAwait(false); |
||||
|
identityResult.Succeeded.ShouldBeTrue(); |
||||
|
var xx = await RoleRepository.UpdateAsync(role).ConfigureAwait(false); |
||||
|
await uow.CompleteAsync().ConfigureAwait(false); |
||||
|
} |
||||
|
|
||||
|
role = await RoleRepository.GetAsync(role.Id).ConfigureAwait(false); |
||||
|
role.Name.ShouldBe("TestModerator"); |
||||
|
|
||||
|
permissionGrantsInRole = await PermissionGrantRepository.GetListAsync("R", role.Name).ConfigureAwait(false); |
||||
|
permissionGrantsInRole.Count.ShouldBe(count); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue