Browse Source

feat: 增加适用于identity模块的webhooks.

pull/532/head
cKey 4 years ago
parent
commit
11ca6efa33
  1. 3
      aspnet-core/modules/webhooks/LINGYUN.Abp.Webhooks.Identity/FodyWeavers.xml
  2. 30
      aspnet-core/modules/webhooks/LINGYUN.Abp.Webhooks.Identity/FodyWeavers.xsd
  3. 30
      aspnet-core/modules/webhooks/LINGYUN.Abp.Webhooks.Identity/LINGYUN.Abp.Webhooks.Identity.csproj
  4. 32
      aspnet-core/modules/webhooks/LINGYUN.Abp.Webhooks.Identity/LINGYUN/Abp/Webhooks/Identity/AbpWebhooksIdentityModule.cs
  5. 12
      aspnet-core/modules/webhooks/LINGYUN.Abp.Webhooks.Identity/LINGYUN/Abp/Webhooks/Identity/IdentityRoleNameChangedWto.cs
  6. 62
      aspnet-core/modules/webhooks/LINGYUN.Abp.Webhooks.Identity/LINGYUN/Abp/Webhooks/Identity/IdentityRoleWebHooker.cs
  7. 10
      aspnet-core/modules/webhooks/LINGYUN.Abp.Webhooks.Identity/LINGYUN/Abp/Webhooks/Identity/IdentityRoleWto.cs
  8. 55
      aspnet-core/modules/webhooks/LINGYUN.Abp.Webhooks.Identity/LINGYUN/Abp/Webhooks/Identity/IdentityUserWebHooker.cs
  9. 22
      aspnet-core/modules/webhooks/LINGYUN.Abp.Webhooks.Identity/LINGYUN/Abp/Webhooks/Identity/IdentityUserWto.cs
  10. 60
      aspnet-core/modules/webhooks/LINGYUN.Abp.Webhooks.Identity/LINGYUN/Abp/Webhooks/Identity/IdentityWebhookDefinitionProvider.cs
  11. 22
      aspnet-core/modules/webhooks/LINGYUN.Abp.Webhooks.Identity/LINGYUN/Abp/Webhooks/Identity/IdentityWebhookNames.cs
  12. 19
      aspnet-core/modules/webhooks/LINGYUN.Abp.Webhooks.Identity/LINGYUN/Abp/Webhooks/Identity/Localization/Resources/en.json
  13. 19
      aspnet-core/modules/webhooks/LINGYUN.Abp.Webhooks.Identity/LINGYUN/Abp/Webhooks/Identity/Localization/Resources/zh-Hans.json
  14. 49
      aspnet-core/modules/webhooks/LINGYUN.Abp.Webhooks.Identity/LINGYUN/Abp/Webhooks/Identity/OrganizationUnitWebHooker.cs
  15. 12
      aspnet-core/modules/webhooks/LINGYUN.Abp.Webhooks.Identity/LINGYUN/Abp/Webhooks/Identity/OrganizationUnitWto.cs
  16. 2
      aspnet-core/modules/webhooks/LINGYUN.Abp.WebhooksManagement.Domain/LINGYUN/Abp/WebhooksManagement/Webhooks/WebhooksNames.cs
  17. 1
      aspnet-core/services/LY.MicroService.WebhooksManagement.HttpApi.Host/LY.MicroService.WebhooksManagement.HttpApi.Host.csproj
  18. 2
      aspnet-core/services/LY.MicroService.WebhooksManagement.HttpApi.Host/WebhooksManagementHttpApiHostModule.cs

3
aspnet-core/modules/webhooks/LINGYUN.Abp.Webhooks.Identity/FodyWeavers.xml

@ -0,0 +1,3 @@
<Weavers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FodyWeavers.xsd">
<ConfigureAwait />
</Weavers>

30
aspnet-core/modules/webhooks/LINGYUN.Abp.Webhooks.Identity/FodyWeavers.xsd

@ -0,0 +1,30 @@
<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<!-- This file was generated by Fody. Manual changes to this file will be lost when your project is rebuilt. -->
<xs:element name="Weavers">
<xs:complexType>
<xs:all>
<xs:element name="ConfigureAwait" minOccurs="0" maxOccurs="1">
<xs:complexType>
<xs:attribute name="ContinueOnCapturedContext" type="xs:boolean" />
</xs:complexType>
</xs:element>
</xs:all>
<xs:attribute name="VerifyAssembly" type="xs:boolean">
<xs:annotation>
<xs:documentation>'true' to run assembly verification (PEVerify) on the target assembly after all weavers have been executed.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="VerifyIgnoreCodes" type="xs:string">
<xs:annotation>
<xs:documentation>A comma-separated list of error codes that can be safely ignored in assembly verification.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="GenerateXsd" type="xs:boolean">
<xs:annotation>
<xs:documentation>'false' to turn off automatic generation of the XML Schema file.</xs:documentation>
</xs:annotation>
</xs:attribute>
</xs:complexType>
</xs:element>
</xs:schema>

30
aspnet-core/modules/webhooks/LINGYUN.Abp.Webhooks.Identity/LINGYUN.Abp.Webhooks.Identity.csproj

@ -0,0 +1,30 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="..\..\..\configureawait.props" />
<Import Project="..\..\..\common.props" />
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<RootNamespace />
</PropertyGroup>
<ItemGroup>
<None Remove="LINGYUN\Abp\Webhooks\Identity\Localization\Resources\*.json" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="LINGYUN\Abp\Webhooks\Identity\Localization\Resources\*.json" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Volo.Abp.Ddd.Domain" Version="$(VoloAbpPackageVersion)" />
<PackageReference Include="Volo.Abp.EventBus" Version="$(VoloAbpPackageVersion)" />
<PackageReference Include="Volo.Abp.Users.Abstractions" Version="$(VoloAbpPackageVersion)" />
<PackageReference Include="Volo.Abp.Identity.Domain.Shared" Version="$(VoloAbpPackageVersion)" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\LINGYUN.Abp.Webhooks\LINGYUN.Abp.Webhooks.csproj" />
</ItemGroup>
</Project>

32
aspnet-core/modules/webhooks/LINGYUN.Abp.Webhooks.Identity/LINGYUN/Abp/Webhooks/Identity/AbpWebhooksIdentityModule.cs

@ -0,0 +1,32 @@
using Volo.Abp.Domain;
using Volo.Abp.EventBus;
using Volo.Abp.Identity;
using Volo.Abp.Identity.Localization;
using Volo.Abp.Localization;
using Volo.Abp.Modularity;
using Volo.Abp.Users;
using Volo.Abp.VirtualFileSystem;
namespace LINGYUN.Abp.Webhooks.Identity;
[DependsOn(typeof(AbpDddDomainModule))]
[DependsOn(typeof(AbpEventBusModule))]
[DependsOn(typeof(AbpUsersAbstractionModule))]
[DependsOn(typeof(AbpIdentityDomainSharedModule))]
public class AbpWebhooksIdentityModule : AbpModule
{
public override void ConfigureServices(ServiceConfigurationContext context)
{
Configure<AbpVirtualFileSystemOptions>(options =>
{
options.FileSets.AddEmbedded<AbpWebhooksIdentityModule>();
});
Configure<AbpLocalizationOptions>(options =>
{
options.Resources
.Get<IdentityResource>()
.AddVirtualJson("/LINGYUN/Abp/Webhooks/Identity/Localization/Resources");
});
}
}

12
aspnet-core/modules/webhooks/LINGYUN.Abp.Webhooks.Identity/LINGYUN/Abp/Webhooks/Identity/IdentityRoleNameChangedWto.cs

@ -0,0 +1,12 @@
using System;
namespace LINGYUN.Abp.Webhooks.Identity;
public class IdentityRoleNameChangedWto
{
public Guid Id { get; set; }
public string Name { get; set; }
public string OldName { get; set; }
}

62
aspnet-core/modules/webhooks/LINGYUN.Abp.Webhooks.Identity/LINGYUN/Abp/Webhooks/Identity/IdentityRoleWebHooker.cs

@ -0,0 +1,62 @@
using System.Threading.Tasks;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Domain.Entities.Events.Distributed;
using Volo.Abp.EventBus.Distributed;
using Volo.Abp.Identity;
namespace LINGYUN.Abp.Webhooks.Identity;
public class IdentityRoleWebHooker :
IDistributedEventHandler<EntityCreatedEto<IdentityRoleEto>>,
IDistributedEventHandler<EntityUpdatedEto<IdentityRoleEto>>,
IDistributedEventHandler<IdentityRoleNameChangedEto>,
ITransientDependency
{
private readonly IWebhookPublisher _webhookPublisher;
public IdentityRoleWebHooker(
IWebhookPublisher webhookPublisher)
{
_webhookPublisher = webhookPublisher;
}
public async virtual Task HandleEventAsync(EntityCreatedEto<IdentityRoleEto> eventData)
{
await PublishAsync(IdentityWebhookNames.IdentityRole.Create, eventData.Entity);
}
public async virtual Task HandleEventAsync(EntityUpdatedEto<IdentityRoleEto> eventData)
{
await PublishAsync(IdentityWebhookNames.IdentityRole.Update, eventData.Entity);
}
public async virtual Task HandleEventAsync(EntityDeletedEto<IdentityRoleEto> eventData)
{
await PublishAsync(IdentityWebhookNames.IdentityRole.Delete, eventData.Entity);
}
public async virtual Task HandleEventAsync(IdentityRoleNameChangedEto eventData)
{
await _webhookPublisher.PublishAsync(
IdentityWebhookNames.IdentityRole.ChangeName,
new IdentityRoleNameChangedWto
{
Id = eventData.Id,
Name = eventData.Name,
OldName = eventData.OldName,
},
eventData.TenantId);
}
protected async virtual Task PublishAsync(string webhookName, IdentityRoleEto eto)
{
await _webhookPublisher.PublishAsync(
webhookName,
new IdentityRoleWto
{
Id = eto.Id,
Name = eto.Name
},
eto.TenantId);
}
}

10
aspnet-core/modules/webhooks/LINGYUN.Abp.Webhooks.Identity/LINGYUN/Abp/Webhooks/Identity/IdentityRoleWto.cs

@ -0,0 +1,10 @@
using System;
namespace LINGYUN.Abp.Webhooks.Identity;
public class IdentityRoleWto
{
public Guid Id { get; set; }
public string Name { get; set; }
}

55
aspnet-core/modules/webhooks/LINGYUN.Abp.Webhooks.Identity/LINGYUN/Abp/Webhooks/Identity/IdentityUserWebHooker.cs

@ -0,0 +1,55 @@
using System.Threading.Tasks;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Domain.Entities.Events.Distributed;
using Volo.Abp.EventBus.Distributed;
using Volo.Abp.Users;
namespace LINGYUN.Abp.Webhooks.Identity;
public class IdentityUserWebHooker :
IDistributedEventHandler<EntityCreatedEto<UserEto>>,
IDistributedEventHandler<EntityUpdatedEto<UserEto>>,
IDistributedEventHandler<EntityDeletedEto<UserEto>>,
ITransientDependency
{
private readonly IWebhookPublisher _webhookPublisher;
public IdentityUserWebHooker(
IWebhookPublisher webhookPublisher)
{
_webhookPublisher = webhookPublisher;
}
public async virtual Task HandleEventAsync(EntityCreatedEto<UserEto> eventData)
{
await PublishAsync(IdentityWebhookNames.IdentityUser.Create, eventData.Entity);
}
public async virtual Task HandleEventAsync(EntityUpdatedEto<UserEto> eventData)
{
await PublishAsync(IdentityWebhookNames.IdentityUser.Update, eventData.Entity);
}
public async virtual Task HandleEventAsync(EntityDeletedEto<UserEto> eventData)
{
await PublishAsync(IdentityWebhookNames.IdentityUser.Delete, eventData.Entity);
}
protected async virtual Task PublishAsync(string webhookName, UserEto eto)
{
await _webhookPublisher.PublishAsync(
webhookName,
new IdentityUserWto
{
Id = eto.Id,
Name = eto.Name,
Email = eto.Email,
EmailConfirmed = eto.EmailConfirmed,
UserName = eto.UserName,
PhoneNumber = eto.PhoneNumber,
PhoneNumberConfirmed = eto.PhoneNumberConfirmed,
Surname = eto.Surname,
},
eto.TenantId);
}
}

22
aspnet-core/modules/webhooks/LINGYUN.Abp.Webhooks.Identity/LINGYUN/Abp/Webhooks/Identity/IdentityUserWto.cs

@ -0,0 +1,22 @@
using System;
namespace LINGYUN.Abp.Webhooks.Identity;
public class IdentityUserWto
{
public Guid Id { get; set; }
public string UserName { get; set; }
public string Name { get; set; }
public string Surname { get; set; }
public string Email { get; set; }
public bool EmailConfirmed { get; set; }
public string PhoneNumber { get; set; }
public bool PhoneNumberConfirmed { get; set; }
}

60
aspnet-core/modules/webhooks/LINGYUN.Abp.Webhooks.Identity/LINGYUN/Abp/Webhooks/Identity/IdentityWebhookDefinitionProvider.cs

@ -0,0 +1,60 @@
using Volo.Abp.Identity.Localization;
using Volo.Abp.Localization;
namespace LINGYUN.Abp.Webhooks.Identity;
public class IdentityWebhookDefinitionProvider : WebhookDefinitionProvider
{
public override void Define(IWebhookDefinitionContext context)
{
context.Add(CreateIdentityRoleWebhooks());
context.Add(CreateIdentityUserWebhooks());
}
protected virtual WebhookDefinition[] CreateIdentityRoleWebhooks()
{
return new[]
{
new WebhookDefinition(
IdentityWebhookNames.IdentityRole.Create,
L("Webhooks:CreateRole"),
L("Webhooks:CreateRoleDesc")),
new WebhookDefinition(
IdentityWebhookNames.IdentityRole.Update,
L("Webhooks:UpdateRole"),
L("Webhooks:UpdateRoleDesc")),
new WebhookDefinition(
IdentityWebhookNames.IdentityRole.Delete,
L("Webhooks:DeleteRole"),
L("Webhooks:DeleteRoleDesc")),
new WebhookDefinition(
IdentityWebhookNames.IdentityRole.ChangeName,
L("Webhooks:ChangeRoleName"),
L("Webhooks:ChangeRoleNameDesc")),
};
}
protected virtual WebhookDefinition[] CreateIdentityUserWebhooks()
{
return new[]
{
new WebhookDefinition(
IdentityWebhookNames.IdentityUser.Create,
L("Webhooks:CreateUser"),
L("Webhooks:CreateUserDesc")),
new WebhookDefinition(
IdentityWebhookNames.IdentityUser.Update,
L("Webhooks:UpdateUser"),
L("Webhooks:UpdateUserDesc")),
new WebhookDefinition(
IdentityWebhookNames.IdentityUser.Delete,
L("Webhooks:DeleteUser"),
L("Webhooks:DeleteUserDesc")),
};
}
private static ILocalizableString L(string name)
{
return LocalizableString.Create<IdentityResource>(name);
}
}

22
aspnet-core/modules/webhooks/LINGYUN.Abp.Webhooks.Identity/LINGYUN/Abp/Webhooks/Identity/IdentityWebhookNames.cs

@ -0,0 +1,22 @@
namespace LINGYUN.Abp.Webhooks.Identity;
public static class IdentityWebhookNames
{
public const string GroupName = "abp.identity";
public static class IdentityRole
{
public const string Prefix = GroupName + ".roles";
public const string Create = Prefix + ".create";
public const string Update = Prefix + ".update";
public const string Delete = Prefix + ".delete";
public const string ChangeName = Prefix + ".change_name";
}
public static class IdentityUser
{
public const string Prefix = GroupName + ".users";
public const string Create = Prefix + ".create";
public const string Update = Prefix + ".update";
public const string Delete = Prefix + ".delete";
}
}

19
aspnet-core/modules/webhooks/LINGYUN.Abp.Webhooks.Identity/LINGYUN/Abp/Webhooks/Identity/Localization/Resources/en.json

@ -0,0 +1,19 @@
{
"culture": "en",
"texts": {
"Webhooks:CreateRole": "Create Role",
"Webhooks:CreateRoleDesc": "A new role has been created",
"Webhooks:UpdateRole": "Update Role",
"Webhooks:UpdateRoleDesc": "A role has changed",
"Webhooks:DeleteRole": "Delete Role",
"Webhooks:DeleteRoleDesc": "Deleted Role",
"Webhooks:ChangeRoleName": "Change Role Name",
"Webhooks:ChangeRoleNameDesc": "The name of a role was changed",
"Webhooks:CreateUser": "Create User",
"Webhooks:CreateUserDesc": "A new user has been created",
"Webhooks:UpdateUser": "Update User",
"Webhooks:UpdateUserDesc": "A user has been changed",
"Webhooks:DeleteUser": "Delete User",
"Webhooks:DeleteUserDesc": "Deleted User"
}
}

19
aspnet-core/modules/webhooks/LINGYUN.Abp.Webhooks.Identity/LINGYUN/Abp/Webhooks/Identity/Localization/Resources/zh-Hans.json

@ -0,0 +1,19 @@
{
"culture": "zh-Hans",
"texts": {
"Webhooks:CreateRole": "创建角色",
"Webhooks:CreateRoleDesc": "一个新角色已创建",
"Webhooks:UpdateRole": "编辑角色",
"Webhooks:UpdateRoleDesc": "一个角色属性已变更",
"Webhooks:DeleteRole": "删除角色",
"Webhooks:DeleteRoleDesc": "已删除角色",
"Webhooks:ChangeRoleName": "改变角色名称",
"Webhooks:ChangeRoleNameDesc": "一个角色的名称被更改",
"Webhooks:CreateUser": "创建用户",
"Webhooks:CreateUserDesc": "一个新用户已创建",
"Webhooks:UpdateUser": "编辑用户",
"Webhooks:UpdateUserDesc": "一个用户属性已变更",
"Webhooks:DeleteUser": "删除用户",
"Webhooks:DeleteUserDesc": "已删除用户"
}
}

49
aspnet-core/modules/webhooks/LINGYUN.Abp.Webhooks.Identity/LINGYUN/Abp/Webhooks/Identity/OrganizationUnitWebHooker.cs

@ -0,0 +1,49 @@
using System.Threading.Tasks;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Domain.Entities.Events.Distributed;
using Volo.Abp.EventBus.Distributed;
using Volo.Abp.Identity;
namespace LINGYUN.Abp.Webhooks.Identity;
public class OrganizationUnitWebHooker :
IDistributedEventHandler<EntityCreatedEto<OrganizationUnitEto>>,
IDistributedEventHandler<EntityUpdatedEto<OrganizationUnitEto>>,
IDistributedEventHandler<EntityDeletedEto<OrganizationUnitEto>>,
ITransientDependency
{
private readonly IWebhookPublisher _webhookPublisher;
public OrganizationUnitWebHooker(
IWebhookPublisher webhookPublisher)
{
_webhookPublisher = webhookPublisher;
}
public async virtual Task HandleEventAsync(EntityCreatedEto<OrganizationUnitEto> eventData)
{
await PublishAsync(IdentityWebhookNames.IdentityRole.Create, eventData.Entity);
}
public async virtual Task HandleEventAsync(EntityUpdatedEto<OrganizationUnitEto> eventData)
{
await PublishAsync(IdentityWebhookNames.IdentityRole.Update, eventData.Entity);
}
public async virtual Task HandleEventAsync(EntityDeletedEto<OrganizationUnitEto> eventData)
{
await PublishAsync(IdentityWebhookNames.IdentityRole.Delete, eventData.Entity);
}
protected async virtual Task PublishAsync(string webhookName, OrganizationUnitEto eto)
{
await _webhookPublisher.PublishAsync(
webhookName,
new OrganizationUnitWto
{
Id = eto.Id,
DisplayName = eto.DisplayName
},
eto.TenantId);
}
}

12
aspnet-core/modules/webhooks/LINGYUN.Abp.Webhooks.Identity/LINGYUN/Abp/Webhooks/Identity/OrganizationUnitWto.cs

@ -0,0 +1,12 @@
using System;
namespace LINGYUN.Abp.Webhooks.Identity;
public class OrganizationUnitWto
{
public Guid Id { get; set; }
public string Code { get; set; }
public string DisplayName { get; set; }
}

2
aspnet-core/modules/webhooks/LINGYUN.Abp.WebhooksManagement.Domain/LINGYUN/Abp/WebhooksManagement/Webhooks/WebhooksNames.cs

@ -2,5 +2,5 @@
public static class WebhooksNames
{
public const string CheckConnect = "Abp.Webhooks.CheckConnect";
public const string CheckConnect = "abp.webhooks.check_connect";
}

1
aspnet-core/services/LY.MicroService.WebhooksManagement.HttpApi.Host/LY.MicroService.WebhooksManagement.HttpApi.Host.csproj

@ -57,6 +57,7 @@
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\modules\webhooks\LINGYUN.Abp.Webhooks.Identity\LINGYUN.Abp.Webhooks.Identity.csproj" />
<ProjectReference Include="..\..\modules\webhooks\LINGYUN.Abp.WebhooksManagement.Application\LINGYUN.Abp.WebhooksManagement.Application.csproj" />
<ProjectReference Include="..\..\modules\webhooks\LINGYUN.Abp.WebhooksManagement.EntityFrameworkCore\LINGYUN.Abp.WebhooksManagement.EntityFrameworkCore.csproj" />
<ProjectReference Include="..\..\modules\webhooks\LINGYUN.Abp.WebhooksManagement.HttpApi\LINGYUN.Abp.WebhooksManagement.HttpApi.csproj" />

2
aspnet-core/services/LY.MicroService.WebhooksManagement.HttpApi.Host/WebhooksManagementHttpApiHostModule.cs

@ -7,6 +7,7 @@ using LINGYUN.Abp.LocalizationManagement.EntityFrameworkCore;
using LINGYUN.Abp.Saas.EntityFrameworkCore;
using LINGYUN.Abp.Serilog.Enrichers.Application;
using LINGYUN.Abp.Serilog.Enrichers.UniqueId;
using LINGYUN.Abp.Webhooks.Identity;
using LINGYUN.Abp.WebhooksManagement;
using LINGYUN.Abp.WebhooksManagement.EntityFrameworkCore;
using Microsoft.AspNetCore.Builder;
@ -38,6 +39,7 @@ namespace LY.MicroService.WebhooksManagement;
typeof(WebhooksManagementApplicationModule),
typeof(WebhooksManagementHttpApiModule),
typeof(WebhooksManagementEntityFrameworkCoreModule),
typeof(AbpWebhooksIdentityModule),
typeof(AbpEntityFrameworkCoreMySQLModule),
typeof(AbpAspNetCoreAuthenticationJwtBearerModule),
typeof(AbpEmailingExceptionHandlingModule),

Loading…
Cancel
Save