forked from abpframework/abp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor modules' local user synchronization
Resolve abpframework#17167
- Loading branch information
Showing
29 changed files
with
188 additions
and
176 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
...rc/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Entities/Events/Distributed/IEntitySynchronizer.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace Volo.Abp.Domain.Entities.Events.Distributed; | ||
|
||
public interface IEntitySynchronizer<TSourceEntityEto> | ||
{ | ||
Task<bool> TryCreateOrUpdateEntityAsync(TSourceEntityEto eto, CancellationToken cancellationToken = default); | ||
|
||
Task<bool> TryDeleteEntityAsync(TSourceEntityEto eto, CancellationToken cancellationToken = default); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 2 additions & 9 deletions
11
modules/blogging/src/Volo.Blogging.Domain/Volo/Blogging/Users/BlogUserLookupService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 17 additions & 26 deletions
43
modules/blogging/src/Volo.Blogging.Domain/Volo/Blogging/Users/BlogUserSynchronizer.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,33 @@ | ||
using System.Threading.Tasks; | ||
using Volo.Abp.DependencyInjection; | ||
using System; | ||
using System.Threading.Tasks; | ||
using JetBrains.Annotations; | ||
using Volo.Abp.Domain.Entities.Events.Distributed; | ||
using Volo.Abp.EventBus.Distributed; | ||
using Volo.Abp.Domain.Repositories; | ||
using Volo.Abp.ObjectMapping; | ||
using Volo.Abp.Users; | ||
|
||
namespace Volo.Blogging.Users | ||
{ | ||
public class BlogUserSynchronizer : | ||
IDistributedEventHandler<EntityUpdatedEto<UserEto>>, | ||
ITransientDependency | ||
public class BlogUserSynchronizer : EntitySynchronizer<BlogUser, Guid, UserEto> | ||
{ | ||
protected IBlogUserRepository UserRepository { get; } | ||
protected IBlogUserLookupService UserLookupService { get; } | ||
|
||
public BlogUserSynchronizer( | ||
IBlogUserRepository userRepository, | ||
IBlogUserLookupService userLookupService) | ||
public BlogUserSynchronizer([NotNull] IObjectMapper objectMapper, | ||
[NotNull] IRepository<BlogUser, Guid> repository) : base(objectMapper, repository) | ||
{ | ||
UserRepository = userRepository; | ||
UserLookupService = userLookupService; | ||
} | ||
|
||
public async Task HandleEventAsync(EntityUpdatedEto<UserEto> eventData) | ||
protected override Task<BlogUser> MapToEntityAsync(UserEto eto) | ||
{ | ||
var user = await UserRepository.FindAsync(eventData.Entity.Id); | ||
if (user == null) | ||
{ | ||
user = await UserLookupService.FindByIdAsync(eventData.Entity.Id); | ||
if (user == null) | ||
{ | ||
return; | ||
} | ||
} | ||
return Task.FromResult(new BlogUser(eto)); | ||
} | ||
|
||
protected override Task MapToEntityAsync(UserEto eto, BlogUser localEntity) | ||
{ | ||
localEntity.Update(eto); | ||
|
||
if (user.Update(eventData.Entity)) | ||
{ | ||
await UserRepository.UpdateAsync(user); | ||
} | ||
return Task.CompletedTask; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 3 additions & 10 deletions
13
modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Users/CmsUserLookupService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,15 @@ | ||
using Volo.Abp.Uow; | ||
using Volo.Abp.Users; | ||
using Volo.Abp.Users; | ||
|
||
namespace Volo.CmsKit.Users; | ||
|
||
public class CmsUserLookupService : UserLookupService<CmsUser, ICmsUserRepository>, ICmsUserLookupService | ||
{ | ||
public CmsUserLookupService( | ||
ICmsUserRepository userRepository, | ||
IUnitOfWorkManager unitOfWorkManager) | ||
: base( | ||
userRepository, | ||
unitOfWorkManager) | ||
public CmsUserLookupService() | ||
{ | ||
|
||
} | ||
|
||
protected override CmsUser CreateUser(IUserData externalUser) | ||
{ | ||
return new CmsUser(externalUser); | ||
} | ||
} | ||
} |
55 changes: 21 additions & 34 deletions
55
modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Users/CmsUserSynchronizer.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,37 @@ | ||
using System.Linq; | ||
using System; | ||
using System.Threading.Tasks; | ||
using Volo.Abp.DependencyInjection; | ||
using JetBrains.Annotations; | ||
using Volo.Abp.Domain.Entities.Events.Distributed; | ||
using Volo.Abp.EventBus.Distributed; | ||
using Volo.Abp.Domain.Repositories; | ||
using Volo.Abp.GlobalFeatures; | ||
using Volo.Abp.ObjectMapping; | ||
using Volo.Abp.Users; | ||
using Volo.CmsKit.GlobalFeatures; | ||
|
||
namespace Volo.CmsKit.Users; | ||
|
||
public class CmsUserSynchronizer : | ||
IDistributedEventHandler<EntityUpdatedEto<UserEto>>, | ||
ITransientDependency | ||
public class CmsUserSynchronizer : EntitySynchronizer<CmsUser, Guid, UserEto> | ||
{ | ||
protected ICmsUserRepository UserRepository { get; } | ||
|
||
protected ICmsUserLookupService UserLookupService { get; } | ||
|
||
public CmsUserSynchronizer( | ||
ICmsUserRepository userRepository, | ||
ICmsUserLookupService userLookupService) | ||
{ | ||
UserRepository = userRepository; | ||
UserLookupService = userLookupService; | ||
} | ||
|
||
public virtual async Task HandleEventAsync(EntityUpdatedEto<UserEto> eventData) | ||
public CmsUserSynchronizer([NotNull] IObjectMapper objectMapper, [NotNull] IRepository<CmsUser, Guid> repository) : | ||
base(objectMapper, repository) | ||
{ | ||
if (!GlobalFeatureManager.Instance.IsEnabled<CmsUserFeature>()) | ||
{ | ||
return; | ||
IgnoreEntityCreatedEvent = true; | ||
IgnoreEntityUpdatedEvent = true; | ||
IgnoreEntityDeletedEvent = true; | ||
} | ||
} | ||
|
||
var user = await UserRepository.FindAsync(eventData.Entity.Id); | ||
if (user == null) | ||
{ | ||
user = await UserLookupService.FindByIdAsync(eventData.Entity.Id); | ||
if (user == null) | ||
{ | ||
return; | ||
} | ||
} | ||
protected override Task<CmsUser> MapToEntityAsync(UserEto eto) | ||
{ | ||
return Task.FromResult(new CmsUser(eto)); | ||
} | ||
|
||
if (user.Update(eventData.Entity)) | ||
{ | ||
await UserRepository.UpdateAsync(user); | ||
} | ||
protected override Task MapToEntityAsync(UserEto eto, CmsUser localEntity) | ||
{ | ||
localEntity.Update(eto); | ||
|
||
return Task.CompletedTask; | ||
} | ||
} | ||
} |
2 changes: 0 additions & 2 deletions
2
modules/identity/src/Volo.Abp.Identity.Domain/Volo.Abp.Identity.Domain.csproj.DotSettings
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 0 additions & 2 deletions
2
...Abp.Identity.EntityFrameworkCore/Volo.Abp.Identity.EntityFrameworkCore.csproj.DotSettings
This file was deleted.
Oops, something went wrong.
2 changes: 0 additions & 2 deletions
2
.../src/Volo.Abp.Identity.HttpApi.Client/Volo.Abp.Identity.HttpApi.Client.csproj.DotSettings
This file was deleted.
Oops, something went wrong.
2 changes: 0 additions & 2 deletions
2
modules/identity/src/Volo.Abp.Identity.MongoDB/Volo.Abp.Identity.MongoDB.csproj.DotSettings
This file was deleted.
Oops, something went wrong.
2 changes: 0 additions & 2 deletions
2
...Server.EntityFrameworkCore/Volo.Abp.IdentityServer.EntityFrameworkCore.csproj.DotSettings
This file was deleted.
Oops, something went wrong.
2 changes: 0 additions & 2 deletions
2
.../src/Volo.Abp.TenantManagement.Domain/Volo.Abp.TenantManagement.Domain.csproj.DotSettings
This file was deleted.
Oops, something went wrong.
2 changes: 0 additions & 2 deletions
2
...ment.EntityFrameworkCore/Volo.Abp.TenantManagement.EntityFrameworkCore.csproj.DotSettings
This file was deleted.
Oops, something went wrong.
2 changes: 0 additions & 2 deletions
2
...rc/Volo.Abp.TenantManagement.MongoDB/Volo.Abp.TenantManagement.MongoDB.csproj.DotSettings
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 0 additions & 2 deletions
2
modules/users/src/Volo.Abp.Users.Abstractions/Volo.Abp.Users.Abstractions.csproj.DotSettings
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
modules/users/src/Volo.Abp.Users.Abstractions/Volo/Abp/Users/IUserData.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.