Browse Source
- **NOTES: Due to the disorderly submission order, there is no need to waste effort in sorting and consolidating the submissions.**pull/1548/head
31 changed files with 637 additions and 119 deletions
@ -0,0 +1,19 @@ |
|||
using LINGYUN.Abp.MicroService.AuthServer.DataSeeds; |
|||
using Volo.Abp.Data; |
|||
using Volo.Abp.DependencyInjection; |
|||
|
|||
namespace LINGYUN.Abp.MicroService.AuthServer; |
|||
|
|||
public class AuthServerInitializeDataSeeder : ITransientDependency |
|||
{ |
|||
protected IdentityUserNotificationDataSeeder UserNotificationDataSeeder { get; } |
|||
public AuthServerInitializeDataSeeder(IdentityUserNotificationDataSeeder userNotificationDataSeeder) |
|||
{ |
|||
UserNotificationDataSeeder = userNotificationDataSeeder; |
|||
} |
|||
|
|||
public virtual async Task SeedAsync(DataSeedContext context) |
|||
{ |
|||
await UserNotificationDataSeeder.SeedAsync(context); |
|||
} |
|||
} |
|||
@ -0,0 +1,89 @@ |
|||
using LINGYUN.Abp.Identity.Notifications; |
|||
using LINGYUN.Abp.Notifications; |
|||
using Microsoft.Extensions.Logging; |
|||
using Microsoft.Extensions.Logging.Abstractions; |
|||
using Volo.Abp.Data; |
|||
using Volo.Abp.DependencyInjection; |
|||
using Volo.Abp.Identity; |
|||
using Volo.Abp.Users; |
|||
|
|||
namespace LINGYUN.Abp.MicroService.AuthServer.DataSeeds; |
|||
|
|||
public class IdentityUserNotificationDataSeeder : ITransientDependency |
|||
{ |
|||
public ILogger<IdentityUserNotificationDataSeeder> Logger { protected get; set; } |
|||
protected IdentityUserManager IdentityUserManager { get; } |
|||
protected INotificationSender NotificationSender { get; } |
|||
protected INotificationSubscriptionManager NotificationSubscriptionManager { get; } |
|||
public IdentityUserNotificationDataSeeder( |
|||
IdentityUserManager identityUserManager, |
|||
INotificationSender notificationSender, |
|||
INotificationSubscriptionManager notificationSubscriptionManager) |
|||
{ |
|||
IdentityUserManager = identityUserManager; |
|||
NotificationSender = notificationSender; |
|||
NotificationSubscriptionManager = notificationSubscriptionManager; |
|||
|
|||
Logger = NullLogger<IdentityUserNotificationDataSeeder>.Instance; |
|||
} |
|||
|
|||
public virtual async Task SeedAsync(DataSeedContext context) |
|||
{ |
|||
await SubscribeDefaultNotifierAsync(context); |
|||
} |
|||
|
|||
protected async virtual Task SubscribeDefaultNotifierAsync(DataSeedContext context) |
|||
{ |
|||
var user = await IdentityUserManager.FindByNameAsync("admin"); |
|||
if (user == null) |
|||
{ |
|||
Logger.LogInformation("No user information named {UserName} was found, so default messages cannot be subscribed to.", "admin"); |
|||
return; |
|||
} |
|||
Logger.LogInformation("User {UserId} has subscribed to default notifications.", user.Id); |
|||
var userIdentifer = new UserIdentifier(user.Id, user.UserName); |
|||
// 订阅内置通知
|
|||
await NotificationSubscriptionManager |
|||
.SubscribeAsync( |
|||
context.TenantId, |
|||
userIdentifer, |
|||
DefaultNotifications.SystemNotice); |
|||
await NotificationSubscriptionManager |
|||
.SubscribeAsync( |
|||
context.TenantId, |
|||
userIdentifer, |
|||
DefaultNotifications.OnsideNotice); |
|||
await NotificationSubscriptionManager |
|||
.SubscribeAsync( |
|||
context.TenantId, |
|||
userIdentifer, |
|||
DefaultNotifications.ActivityNotice); |
|||
|
|||
// 新用户订阅会话过期通知
|
|||
await NotificationSubscriptionManager |
|||
.SubscribeAsync( |
|||
context.TenantId, |
|||
userIdentifer, |
|||
IdentityNotificationNames.Session.ExpirationSession); |
|||
// 新用户订阅不活跃用户相关通知
|
|||
await NotificationSubscriptionManager |
|||
.SubscribeAsync( |
|||
context.TenantId, |
|||
userIdentifer, |
|||
IdentityNotificationNames.IdentityUser.InactiveUserReminderNotifier); |
|||
await NotificationSubscriptionManager |
|||
.SubscribeAsync( |
|||
context.TenantId, |
|||
userIdentifer, |
|||
IdentityNotificationNames.IdentityUser.InactiveUserDeactivationNotifier); |
|||
|
|||
// 订阅用户欢迎消息
|
|||
await NotificationSubscriptionManager |
|||
.SubscribeAsync( |
|||
context.TenantId, |
|||
userIdentifer, |
|||
UserNotificationNames.WelcomeToApplication); |
|||
|
|||
Logger.LogInformation("User {UserId} is subscribed to notifications by default.", user.Id); |
|||
} |
|||
} |
|||
@ -0,0 +1,20 @@ |
|||
using LY.MicroService.AuthServer.DbMigrator.DataSeeds; |
|||
using Volo.Abp.Data; |
|||
using Volo.Abp.DependencyInjection; |
|||
|
|||
namespace LY.MicroService.AuthServer.DbMigrator; |
|||
|
|||
public class AuthServerInitializeDataSeeder : ITransientDependency |
|||
{ |
|||
protected IdentityUserNotificationDataSeeder UserNotificationDataSeeder { get; } |
|||
public AuthServerInitializeDataSeeder(IdentityUserNotificationDataSeeder userNotificationDataSeeder) |
|||
{ |
|||
UserNotificationDataSeeder = userNotificationDataSeeder; |
|||
} |
|||
|
|||
public virtual async Task SeedAsync(DataSeedContext context) |
|||
{ |
|||
await UserNotificationDataSeeder.SeedAsync(context); |
|||
} |
|||
} |
|||
|
|||
@ -0,0 +1,89 @@ |
|||
using LINGYUN.Abp.Identity.Notifications; |
|||
using LINGYUN.Abp.Notifications; |
|||
using Microsoft.Extensions.Logging; |
|||
using Microsoft.Extensions.Logging.Abstractions; |
|||
using Volo.Abp.Data; |
|||
using Volo.Abp.DependencyInjection; |
|||
using Volo.Abp.Identity; |
|||
using Volo.Abp.Users; |
|||
|
|||
namespace LY.MicroService.AuthServer.DbMigrator.DataSeeds; |
|||
|
|||
public class IdentityUserNotificationDataSeeder : ITransientDependency |
|||
{ |
|||
public ILogger<IdentityUserNotificationDataSeeder> Logger { protected get; set; } |
|||
protected IdentityUserManager IdentityUserManager { get; } |
|||
protected INotificationSender NotificationSender { get; } |
|||
protected INotificationSubscriptionManager NotificationSubscriptionManager { get; } |
|||
public IdentityUserNotificationDataSeeder( |
|||
IdentityUserManager identityUserManager, |
|||
INotificationSender notificationSender, |
|||
INotificationSubscriptionManager notificationSubscriptionManager) |
|||
{ |
|||
IdentityUserManager = identityUserManager; |
|||
NotificationSender = notificationSender; |
|||
NotificationSubscriptionManager = notificationSubscriptionManager; |
|||
|
|||
Logger = NullLogger<IdentityUserNotificationDataSeeder>.Instance; |
|||
} |
|||
|
|||
public virtual async Task SeedAsync(DataSeedContext context) |
|||
{ |
|||
await SubscribeDefaultNotifierAsync(context); |
|||
} |
|||
|
|||
protected async virtual Task SubscribeDefaultNotifierAsync(DataSeedContext context) |
|||
{ |
|||
var user = await IdentityUserManager.FindByNameAsync("admin"); |
|||
if (user == null) |
|||
{ |
|||
Logger.LogInformation("No user information named {UserName} was found, so default messages cannot be subscribed to.", "admin"); |
|||
return; |
|||
} |
|||
Logger.LogInformation("User {UserId} has subscribed to default notifications.", user.Id); |
|||
var userIdentifer = new UserIdentifier(user.Id, user.UserName); |
|||
// 订阅内置通知
|
|||
await NotificationSubscriptionManager |
|||
.SubscribeAsync( |
|||
context.TenantId, |
|||
userIdentifer, |
|||
DefaultNotifications.SystemNotice); |
|||
await NotificationSubscriptionManager |
|||
.SubscribeAsync( |
|||
context.TenantId, |
|||
userIdentifer, |
|||
DefaultNotifications.OnsideNotice); |
|||
await NotificationSubscriptionManager |
|||
.SubscribeAsync( |
|||
context.TenantId, |
|||
userIdentifer, |
|||
DefaultNotifications.ActivityNotice); |
|||
|
|||
// 新用户订阅会话过期通知
|
|||
await NotificationSubscriptionManager |
|||
.SubscribeAsync( |
|||
context.TenantId, |
|||
userIdentifer, |
|||
IdentityNotificationNames.Session.ExpirationSession); |
|||
// 新用户订阅不活跃用户相关通知
|
|||
await NotificationSubscriptionManager |
|||
.SubscribeAsync( |
|||
context.TenantId, |
|||
userIdentifer, |
|||
IdentityNotificationNames.IdentityUser.InactiveUserReminderNotifier); |
|||
await NotificationSubscriptionManager |
|||
.SubscribeAsync( |
|||
context.TenantId, |
|||
userIdentifer, |
|||
IdentityNotificationNames.IdentityUser.InactiveUserDeactivationNotifier); |
|||
|
|||
// 订阅用户欢迎消息
|
|||
await NotificationSubscriptionManager |
|||
.SubscribeAsync( |
|||
context.TenantId, |
|||
userIdentifer, |
|||
UserNotificationNames.WelcomeToApplication); |
|||
|
|||
Logger.LogInformation("User {UserId} is subscribed to notifications by default.", user.Id); |
|||
} |
|||
} |
|||
@ -0,0 +1,139 @@ |
|||
using LINGYUN.Abp.Notifications; |
|||
using Microsoft.Extensions.Logging; |
|||
using Microsoft.Extensions.Logging.Abstractions; |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.Data; |
|||
using Volo.Abp.DependencyInjection; |
|||
using Volo.Abp.MultiTenancy; |
|||
using Volo.Abp.Users; |
|||
|
|||
namespace LY.MicroService.RealtimeMessage.EntityFrameworkCore.DataSeeds; |
|||
|
|||
public class NotificationDataSeeder : ITransientDependency |
|||
{ |
|||
public ILogger<NotificationDataSeeder> Logger { protected get; set; } |
|||
protected INotificationSender NotificationSender { get; } |
|||
protected INotificationSubscriptionManager NotificationSubscriptionManager { get; } |
|||
public NotificationDataSeeder( |
|||
INotificationSender notificationSender, |
|||
INotificationSubscriptionManager notificationSubscriptionManager) |
|||
{ |
|||
NotificationSender = notificationSender; |
|||
NotificationSubscriptionManager = notificationSubscriptionManager; |
|||
|
|||
Logger = NullLogger<NotificationDataSeeder>.Instance; |
|||
} |
|||
|
|||
public virtual async Task SeedAsync(DataSeedContext context) |
|||
{ |
|||
await SubscribeDefaultNotifierAsync(context); |
|||
await SeedWelcomeNotifierAsync(context); |
|||
} |
|||
|
|||
public async virtual Task SubscribeDefaultNotifierAsync(DataSeedContext context) |
|||
{ |
|||
if (!context.Properties.TryGetValue(RealtimeMessageDataSeedConsts.AdminUserIdPropertyName, out var userIdString) || |
|||
!Guid.TryParse(userIdString?.ToString(), out var adminUserId)) |
|||
{ |
|||
return; |
|||
} |
|||
var adminUserName = context.Properties.GetOrDefault(RealtimeMessageDataSeedConsts.AdminUserNamePropertyName)?.ToString() |
|||
?? RealtimeMessageDataSeedConsts.AdminUserNameDefaultValue; |
|||
var userIdentifer = new UserIdentifier(adminUserId, adminUserName); |
|||
// 订阅内置通知
|
|||
await NotificationSubscriptionManager |
|||
.SubscribeAsync( |
|||
context.TenantId, |
|||
userIdentifer, |
|||
DefaultNotifications.SystemNotice); |
|||
await NotificationSubscriptionManager |
|||
.SubscribeAsync( |
|||
context.TenantId, |
|||
userIdentifer, |
|||
DefaultNotifications.OnsideNotice); |
|||
await NotificationSubscriptionManager |
|||
.SubscribeAsync( |
|||
context.TenantId, |
|||
userIdentifer, |
|||
DefaultNotifications.ActivityNotice); |
|||
|
|||
// 新用户订阅会话过期通知
|
|||
await NotificationSubscriptionManager |
|||
.SubscribeAsync( |
|||
context.TenantId, |
|||
userIdentifer, |
|||
"AbpIdentity.Session.Expiration"); |
|||
// 新用户订阅不活跃用户相关通知
|
|||
await NotificationSubscriptionManager |
|||
.SubscribeAsync( |
|||
context.TenantId, |
|||
userIdentifer, |
|||
"AbpIdentity.IdentityUser.InactiveUserReminderNotifier"); |
|||
await NotificationSubscriptionManager |
|||
.SubscribeAsync( |
|||
context.TenantId, |
|||
userIdentifer, |
|||
"AbpIdentity.IdentityUser.InactiveUserDeactivationNotifier"); |
|||
|
|||
// 订阅用户欢迎消息
|
|||
await NotificationSubscriptionManager |
|||
.SubscribeAsync( |
|||
context.TenantId, |
|||
userIdentifer, |
|||
UserNotificationNames.WelcomeToApplication); |
|||
} |
|||
|
|||
public async virtual Task SeedWelcomeNotifierAsync(DataSeedContext context) |
|||
{ |
|||
try |
|||
{ |
|||
if (!context.TenantId.HasValue) |
|||
{ |
|||
return; |
|||
} |
|||
if (!context.Properties.TryGetValue(RealtimeMessageDataSeedConsts.AdminUserIdPropertyName, out var userIdString) || |
|||
!Guid.TryParse(userIdString?.ToString(), out var adminUserId)) |
|||
{ |
|||
return; |
|||
} |
|||
var adminEmailAddress = context.Properties.GetOrDefault(RealtimeMessageDataSeedConsts.AdminEmailPropertyName)?.ToString() |
|||
?? RealtimeMessageDataSeedConsts.AdminEmailDefaultValue; |
|||
var adminUserName = context.Properties.GetOrDefault(RealtimeMessageDataSeedConsts.AdminUserNamePropertyName)?.ToString() |
|||
?? RealtimeMessageDataSeedConsts.AdminUserNameDefaultValue; |
|||
|
|||
var tenantAdminUserIdentifier = new UserIdentifier(adminUserId, adminEmailAddress); |
|||
|
|||
// 租户管理员订阅事件
|
|||
await NotificationSubscriptionManager |
|||
.SubscribeAsync( |
|||
context.TenantId, |
|||
tenantAdminUserIdentifier, |
|||
TenantNotificationNames.NewTenantRegistered); |
|||
|
|||
Logger.LogInformation("publish new tenant notification.."); |
|||
await NotificationSender.SendNofiterAsync( |
|||
TenantNotificationNames.NewTenantRegistered, |
|||
new NotificationTemplate( |
|||
TenantNotificationNames.NewTenantRegistered, |
|||
formUser: adminEmailAddress, |
|||
data: new Dictionary<string, object?> |
|||
{ |
|||
{ "name", adminUserName }, |
|||
{ "email", adminEmailAddress }, |
|||
{ "id", context.TenantId }, |
|||
}), |
|||
tenantAdminUserIdentifier, |
|||
context.TenantId, |
|||
NotificationSeverity.Success); |
|||
|
|||
Logger.LogInformation("tenant administrator subscribes to new tenant events.."); |
|||
} |
|||
catch (Exception ex) |
|||
{ |
|||
Logger.LogWarning(ex, "Failed to send the tenant initialization notification."); |
|||
} |
|||
} |
|||
} |
|||
|
|||
@ -0,0 +1,10 @@ |
|||
namespace LY.MicroService.RealtimeMessage.EntityFrameworkCore; |
|||
|
|||
public class RealtimeMessageDataSeedConsts |
|||
{ |
|||
public const string AdminUserIdPropertyName = "AdminUserId"; |
|||
public const string AdminEmailPropertyName = "AdminEmail"; |
|||
public const string AdminEmailDefaultValue = "admin@abp.io"; |
|||
public const string AdminUserNamePropertyName = "AdminUserName"; |
|||
public const string AdminUserNameDefaultValue = "admin"; |
|||
} |
|||
@ -0,0 +1,33 @@ |
|||
using LY.MicroService.RealtimeMessage.EntityFrameworkCore.DataSeeds; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.Data; |
|||
using Volo.Abp.DependencyInjection; |
|||
using Volo.Abp.MultiTenancy; |
|||
|
|||
namespace LY.MicroService.RealtimeMessage.EntityFrameworkCore; |
|||
|
|||
public class RealtimeMessageDataSeeder : ITransientDependency |
|||
{ |
|||
protected NotificationDataSeeder NotificationDataSeeder { get; } |
|||
protected ICurrentTenant CurrentTenant { get; } |
|||
public RealtimeMessageDataSeeder( |
|||
ICurrentTenant currentTenant, |
|||
NotificationDataSeeder notificationDataSeeder) |
|||
{ |
|||
CurrentTenant = currentTenant; |
|||
NotificationDataSeeder = notificationDataSeeder; |
|||
} |
|||
|
|||
public async virtual Task SeedAsync(DataSeedContext context) |
|||
{ |
|||
using (CurrentTenant.Change(context.TenantId)) |
|||
{ |
|||
await SeedNotificationAsync(context); |
|||
} |
|||
} |
|||
|
|||
private async Task SeedNotificationAsync(DataSeedContext context) |
|||
{ |
|||
await NotificationDataSeeder.SeedAsync(context); |
|||
} |
|||
} |
|||
Loading…
Reference in new issue