diff --git a/modules/blogging/src/Volo.Blogging.Application/Volo/Blogging/Posts/PostAppService.cs b/modules/blogging/src/Volo.Blogging.Application/Volo/Blogging/Posts/PostAppService.cs index a88fd46679..69e325f0c7 100644 --- a/modules/blogging/src/Volo.Blogging.Application/Volo/Blogging/Posts/PostAppService.cs +++ b/modules/blogging/src/Volo.Blogging.Application/Volo/Blogging/Posts/PostAppService.cs @@ -60,20 +60,19 @@ namespace Volo.Blogging.Posts { if (postDto.CreatorId.HasValue) { - var creatorUser = await UserLookupService.FindByIdAsync(postDto.CreatorId.Value); - - if (creatorUser != null && !userDictionary.ContainsKey(creatorUser.Id)) + if (!userDictionary.ContainsKey(postDto.CreatorId.Value)) { - userDictionary.Add(creatorUser.Id, ObjectMapper.Map(creatorUser)); + var creatorUser = await UserLookupService.FindByIdAsync(postDto.CreatorId.Value); + if (creatorUser != null) + { + userDictionary[creatorUser.Id] = ObjectMapper.Map(creatorUser); + } } - } - } - foreach (var postDto in postDtos) - { - if (postDto.CreatorId.HasValue && userDictionary.ContainsKey((Guid)postDto.CreatorId)) - { - postDto.Writer = userDictionary[(Guid)postDto.CreatorId]; + if (userDictionary.ContainsKey(postDto.CreatorId.Value)) + { + postDto.Writer = userDictionary[(Guid)postDto.CreatorId]; + } } } diff --git a/modules/identity/src/Volo.Abp.Identity.Application.Contracts/Volo.Abp.Identity.Application.Contracts.csproj b/modules/identity/src/Volo.Abp.Identity.Application.Contracts/Volo.Abp.Identity.Application.Contracts.csproj index 8550b20c3e..8d113899a9 100644 --- a/modules/identity/src/Volo.Abp.Identity.Application.Contracts/Volo.Abp.Identity.Application.Contracts.csproj +++ b/modules/identity/src/Volo.Abp.Identity.Application.Contracts/Volo.Abp.Identity.Application.Contracts.csproj @@ -19,9 +19,8 @@ - - + diff --git a/modules/identity/src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/AbpIdentityApplicationContractsModule.cs b/modules/identity/src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/AbpIdentityApplicationContractsModule.cs index 88fdbcfec3..9a45258f4f 100644 --- a/modules/identity/src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/AbpIdentityApplicationContractsModule.cs +++ b/modules/identity/src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/AbpIdentityApplicationContractsModule.cs @@ -1,19 +1,22 @@ -using Microsoft.Extensions.DependencyInjection; -using Volo.Abp.Application; +using Volo.Abp.Application; using Volo.Abp.Authorization; using Volo.Abp.Authorization.Permissions; using Volo.Abp.Identity.Localization; using Volo.Abp.Localization; using Volo.Abp.Modularity; using Volo.Abp.PermissionManagement; +using Volo.Abp.Users; using Volo.Abp.VirtualFileSystem; namespace Volo.Abp.Identity { - [DependsOn(typeof(AbpIdentityDomainSharedModule))] - [DependsOn(typeof(AbpAuthorizationModule))] - [DependsOn(typeof(AbpDddApplicationModule))] - [DependsOn(typeof(AbpPermissionManagementApplicationContractsModule))] + [DependsOn( + typeof(AbpIdentityDomainSharedModule), + typeof(AbpUsersAbstractionModule), + typeof(AbpAuthorizationModule), + typeof(AbpDddApplicationModule), + typeof(AbpPermissionManagementApplicationContractsModule) + )] public class AbpIdentityApplicationContractsModule : AbpModule { public override void ConfigureServices(ServiceConfigurationContext context) diff --git a/modules/identity/src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/IIdentityUserLookupAppService.cs b/modules/identity/src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/IIdentityUserLookupAppService.cs new file mode 100644 index 0000000000..1ab79f400e --- /dev/null +++ b/modules/identity/src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/IIdentityUserLookupAppService.cs @@ -0,0 +1,14 @@ +using System; +using System.Threading.Tasks; +using Volo.Abp.Application.Services; +using Volo.Abp.Users; + +namespace Volo.Abp.Identity +{ + public interface IIdentityUserLookupAppService : IApplicationService + { + Task FindByIdAsync(Guid id); + + Task FindByUserNameAsync(string userName); + } +} diff --git a/modules/identity/src/Volo.Abp.Identity.Application/Volo/Abp/Identity/IdentityUserLookupAppService.cs b/modules/identity/src/Volo.Abp.Identity.Application/Volo/Abp/Identity/IdentityUserLookupAppService.cs new file mode 100644 index 0000000000..4e788359c7 --- /dev/null +++ b/modules/identity/src/Volo.Abp.Identity.Application/Volo/Abp/Identity/IdentityUserLookupAppService.cs @@ -0,0 +1,41 @@ +using System; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Authorization; +using Volo.Abp.Users; + +namespace Volo.Abp.Identity +{ + //TODO: Authorization (for clients, not users) + public class IdentityUserLookupAppService : IdentityAppServiceBase, IIdentityUserLookupAppService + { + protected IdentityUserRepositoryExternalUserLookupServiceProvider UserLookupServiceProvider { get; } + + public IdentityUserLookupAppService( + IdentityUserRepositoryExternalUserLookupServiceProvider userLookupServiceProvider) + { + UserLookupServiceProvider = userLookupServiceProvider; + } + + public virtual async Task FindByIdAsync(Guid id) + { + var userData = await UserLookupServiceProvider.FindByIdAsync(id); + if (userData == null) + { + return null; + } + + return new UserData(userData); + } + + public virtual async Task FindByUserNameAsync(string userName) + { + var userData = await UserLookupServiceProvider.FindByUserNameAsync(userName); + if (userData == null) + { + return null; + } + + return new UserData(userData); + } + } +} diff --git a/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityUserRepositoryExternalUserLookupServiceProvider.cs b/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityUserRepositoryExternalUserLookupServiceProvider.cs index 30611a4a53..684eec938f 100644 --- a/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityUserRepositoryExternalUserLookupServiceProvider.cs +++ b/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityUserRepositoryExternalUserLookupServiceProvider.cs @@ -30,7 +30,7 @@ namespace Volo.Abp.Identity includeDetails: false, cancellationToken: cancellationToken ) - ).ToAbpUserData(); + )?.ToAbpUserData(); } public async Task FindByUserNameAsync( @@ -43,7 +43,7 @@ namespace Volo.Abp.Identity includeDetails: false, cancellationToken: cancellationToken ) - ).ToAbpUserData(); + )?.ToAbpUserData(); } } } diff --git a/modules/identity/src/Volo.Abp.Identity.HttpApi.Client/Volo.Abp.Identity.HttpApi.Client.csproj b/modules/identity/src/Volo.Abp.Identity.HttpApi.Client/Volo.Abp.Identity.HttpApi.Client.csproj index 6c168dbbf2..b7e8a18755 100644 --- a/modules/identity/src/Volo.Abp.Identity.HttpApi.Client/Volo.Abp.Identity.HttpApi.Client.csproj +++ b/modules/identity/src/Volo.Abp.Identity.HttpApi.Client/Volo.Abp.Identity.HttpApi.Client.csproj @@ -15,9 +15,6 @@ - - - diff --git a/modules/identity/src/Volo.Abp.Identity.HttpApi.Client/Volo/Abp/Identity/AbpIdentityHttpApiClientModule.cs b/modules/identity/src/Volo.Abp.Identity.HttpApi.Client/Volo/Abp/Identity/AbpIdentityHttpApiClientModule.cs index 4ee0b06ff1..ed830a1212 100644 --- a/modules/identity/src/Volo.Abp.Identity.HttpApi.Client/Volo/Abp/Identity/AbpIdentityHttpApiClientModule.cs +++ b/modules/identity/src/Volo.Abp.Identity.HttpApi.Client/Volo/Abp/Identity/AbpIdentityHttpApiClientModule.cs @@ -1,13 +1,11 @@ using Microsoft.Extensions.DependencyInjection; using Volo.Abp.Http.Client; using Volo.Abp.Modularity; -using Volo.Abp.Users; namespace Volo.Abp.Identity { [DependsOn( typeof(AbpIdentityApplicationContractsModule), - typeof(AbpUsersAbstractionModule), typeof(AbpHttpClientModule))] public class AbpIdentityHttpApiClientModule : AbpModule { diff --git a/modules/identity/src/Volo.Abp.Identity.HttpApi.Client/Volo/Abp/Identity/HttpClientIdentityUserLookupService.cs b/modules/identity/src/Volo.Abp.Identity.HttpApi.Client/Volo/Abp/Identity/HttpClientIdentityUserLookupService.cs index b6f58277d6..53eb6a1af1 100644 --- a/modules/identity/src/Volo.Abp.Identity.HttpApi.Client/Volo/Abp/Identity/HttpClientIdentityUserLookupService.cs +++ b/modules/identity/src/Volo.Abp.Identity.HttpApi.Client/Volo/Abp/Identity/HttpClientIdentityUserLookupService.cs @@ -1,5 +1,4 @@ using System; -using System.Linq; using System.Threading; using System.Threading.Tasks; using Volo.Abp.DependencyInjection; @@ -10,24 +9,21 @@ namespace Volo.Abp.Identity [Dependency(TryRegister = true)] public class HttpClientExternalUserLookupServiceProvider : IExternalUserLookupServiceProvider, ITransientDependency { - private readonly IIdentityUserAppService _userAppService; + private readonly IIdentityUserLookupAppService _userLookupAppService; - public HttpClientExternalUserLookupServiceProvider(IIdentityUserAppService userAppService) + public HttpClientExternalUserLookupServiceProvider(IIdentityUserLookupAppService userLookupAppService) { - _userAppService = userAppService; + _userLookupAppService = userLookupAppService; } public async Task FindByIdAsync(Guid id, CancellationToken cancellationToken = default) { - //TODO: Should return null if not found! - return (await _userAppService.GetAsync(id)).ToUserInfo(); + return await _userLookupAppService.FindByIdAsync(id); } public async Task FindByUserNameAsync(string userName, CancellationToken cancellationToken = default) { - //TODO: Should return null if not found! - //TODO: Search by UserName, not by a general filter! - return (await _userAppService.GetListAsync(new GetIdentityUsersInput { Filter = userName })).Items.FirstOrDefault()?.ToUserInfo(); + return await _userLookupAppService.FindByUserNameAsync(userName); } } } diff --git a/modules/identity/src/Volo.Abp.Identity.HttpApi/Volo/Abp/Identity/IdentityUserLookupController.cs b/modules/identity/src/Volo.Abp.Identity.HttpApi/Volo/Abp/Identity/IdentityUserLookupController.cs new file mode 100644 index 0000000000..ba663858fb --- /dev/null +++ b/modules/identity/src/Volo.Abp.Identity.HttpApi/Volo/Abp/Identity/IdentityUserLookupController.cs @@ -0,0 +1,36 @@ +using System; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Mvc; +using Volo.Abp.AspNetCore.Mvc; +using Volo.Abp.Users; + +namespace Volo.Abp.Identity +{ + [RemoteService] + [Area("identity")] + [ControllerName("UserLookup")] + [Route("api/identity/user-lookup")] + public class IdentityUserLookupController : AbpController, IIdentityUserLookupAppService + { + protected IIdentityUserLookupAppService LookupAppService { get; } + + public IdentityUserLookupController(IIdentityUserLookupAppService lookupAppService) + { + LookupAppService = lookupAppService; + } + + [HttpGet] + [Route("{id}")] + public Task FindByIdAsync(Guid id) + { + return LookupAppService.FindByIdAsync(id); + } + + [HttpGet] + [Route("by-username/{userName}")] + public Task FindByUserNameAsync(string userName) + { + return LookupAppService.FindByUserNameAsync(userName); + } + } +} diff --git a/modules/users/src/Volo.Abp.Users.Abstractions/Volo/Abp/Users/UserData.cs b/modules/users/src/Volo.Abp.Users.Abstractions/Volo/Abp/Users/UserData.cs index 391e0ef955..bd979cde11 100644 --- a/modules/users/src/Volo.Abp.Users.Abstractions/Volo/Abp/Users/UserData.cs +++ b/modules/users/src/Volo.Abp.Users.Abstractions/Volo/Abp/Users/UserData.cs @@ -28,6 +28,19 @@ namespace Volo.Abp.Users } + public UserData(IUserData userData) + { + Id = userData.Id; + UserName = userData.UserName; + Email = userData.Email; + Name = userData.Name; + Surname = userData.Surname; + EmailConfirmed = userData.EmailConfirmed; + PhoneNumber = userData.PhoneNumber; + PhoneNumberConfirmed = userData.PhoneNumberConfirmed; + TenantId = userData.TenantId; + } + public UserData( Guid id, [NotNull] string userName, diff --git a/samples/MicroserviceDemo/applications/PublicWebSite.Host/PublicWebSiteHostModule.cs b/samples/MicroserviceDemo/applications/PublicWebSite.Host/PublicWebSiteHostModule.cs index dab1006ec0..cf189bb460 100644 --- a/samples/MicroserviceDemo/applications/PublicWebSite.Host/PublicWebSiteHostModule.cs +++ b/samples/MicroserviceDemo/applications/PublicWebSite.Host/PublicWebSiteHostModule.cs @@ -66,8 +66,10 @@ namespace PublicWebSite.Host options.Scope.Add("email"); options.Scope.Add("phone"); options.Scope.Add("PublicWebSiteGateway"); + options.Scope.Add("InternalGateway"); options.Scope.Add("ProductService"); options.Scope.Add("BloggingService"); + options.Scope.Add("IdentityService"); options.ClaimActions.MapAbpClaimTypes(); }); diff --git a/samples/MicroserviceDemo/databases/MsDemo_Identity.zip b/samples/MicroserviceDemo/databases/MsDemo_Identity.zip index d4157d1200..c98ede82f7 100644 Binary files a/samples/MicroserviceDemo/databases/MsDemo_Identity.zip and b/samples/MicroserviceDemo/databases/MsDemo_Identity.zip differ