diff --git a/modules/identity/src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/IIdentityUserAppService.cs b/modules/identity/src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/IIdentityUserAppService.cs index 55946e21ab..6a175303e5 100644 --- a/modules/identity/src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/IIdentityUserAppService.cs +++ b/modules/identity/src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/IIdentityUserAppService.cs @@ -22,4 +22,6 @@ public interface IIdentityUserAppService Task FindByUsernameAsync(string userName); Task FindByEmailAsync(string email); + + Task FindByIdAsync(Guid id); } diff --git a/modules/identity/src/Volo.Abp.Identity.Application/Volo/Abp/Identity/IdentityUserAppService.cs b/modules/identity/src/Volo.Abp.Identity.Application/Volo/Abp/Identity/IdentityUserAppService.cs index f9b5a53a46..23499937f5 100644 --- a/modules/identity/src/Volo.Abp.Identity.Application/Volo/Abp/Identity/IdentityUserAppService.cs +++ b/modules/identity/src/Volo.Abp.Identity.Application/Volo/Abp/Identity/IdentityUserAppService.cs @@ -180,6 +180,14 @@ public class IdentityUserAppService : IdentityAppServiceBase, IIdentityUserAppSe ); } + [Authorize(IdentityPermissions.Users.Default)] + public virtual async Task FindByIdAsync(Guid id) + { + return ObjectMapper.Map( + await UserManager.FindByIdAsync(id.ToString()) + ); + } + protected virtual async Task UpdateUserByInput(IdentityUser user, IdentityUserCreateOrUpdateDtoBase input) { if (!string.Equals(user.Email, input.Email, StringComparison.InvariantCultureIgnoreCase)) diff --git a/modules/identity/src/Volo.Abp.Identity.HttpApi.Client/ClientProxies/Volo/Abp/Identity/IdentityUserClientProxy.Generated.cs b/modules/identity/src/Volo.Abp.Identity.HttpApi.Client/ClientProxies/Volo/Abp/Identity/IdentityUserClientProxy.Generated.cs index b6e18e1e0f..11c0bb54c3 100644 --- a/modules/identity/src/Volo.Abp.Identity.HttpApi.Client/ClientProxies/Volo/Abp/Identity/IdentityUserClientProxy.Generated.cs +++ b/modules/identity/src/Volo.Abp.Identity.HttpApi.Client/ClientProxies/Volo/Abp/Identity/IdentityUserClientProxy.Generated.cs @@ -58,6 +58,14 @@ public partial class IdentityUserClientProxy : ClientProxyBase FindByIdAsync(Guid id) + { + return await RequestAsync(nameof(FindByIdAsync), new ClientProxyRequestTypeValue + { + { typeof(Guid), id } + }); + } + public virtual async Task> GetRolesAsync(Guid id) { return await RequestAsync>(nameof(GetRolesAsync), new ClientProxyRequestTypeValue diff --git a/modules/identity/src/Volo.Abp.Identity.HttpApi.Client/ClientProxies/identity-generate-proxy.json b/modules/identity/src/Volo.Abp.Identity.HttpApi.Client/ClientProxies/identity-generate-proxy.json index 3937d99aa9..d66a185094 100644 --- a/modules/identity/src/Volo.Abp.Identity.HttpApi.Client/ClientProxies/identity-generate-proxy.json +++ b/modules/identity/src/Volo.Abp.Identity.HttpApi.Client/ClientProxies/identity-generate-proxy.json @@ -487,6 +487,23 @@ "typeSimple": "Volo.Abp.Identity.IdentityUserDto" } }, + { + "name": "FindByIdAsync", + "parametersOnMethod": [ + { + "name": "id", + "typeAsString": "System.Guid, System.Private.CoreLib", + "type": "System.Guid", + "typeSimple": "string", + "isOptional": false, + "defaultValue": null + } + ], + "returnValue": { + "type": "Volo.Abp.Identity.IdentityUserDto", + "typeSimple": "Volo.Abp.Identity.IdentityUserDto" + } + }, { "name": "GetAsync", "parametersOnMethod": [ @@ -1019,6 +1036,43 @@ }, "allowAnonymous": null, "implementFrom": "Volo.Abp.Identity.IIdentityUserAppService" + }, + "FindByIdAsyncById": { + "uniqueName": "FindByIdAsyncById", + "name": "FindByIdAsync", + "httpMethod": "GET", + "url": "api/identity/users/by-id/{id}", + "supportedVersions": [], + "parametersOnMethod": [ + { + "name": "id", + "typeAsString": "System.Guid, System.Private.CoreLib", + "type": "System.Guid", + "typeSimple": "string", + "isOptional": false, + "defaultValue": null + } + ], + "parameters": [ + { + "nameOnMethod": "id", + "name": "id", + "jsonName": null, + "type": "System.Guid", + "typeSimple": "string", + "isOptional": false, + "defaultValue": null, + "constraintTypes": [], + "bindingSourceId": "Path", + "descriptorName": "" + } + ], + "returnValue": { + "type": "Volo.Abp.Identity.IdentityUserDto", + "typeSimple": "Volo.Abp.Identity.IdentityUserDto" + }, + "allowAnonymous": null, + "implementFrom": "Volo.Abp.Identity.IIdentityUserAppService" } } }, diff --git a/modules/identity/src/Volo.Abp.Identity.HttpApi/Volo/Abp/Identity/IdentityUserController.cs b/modules/identity/src/Volo.Abp.Identity.HttpApi/Volo/Abp/Identity/IdentityUserController.cs index 67039a1800..54f0fde491 100644 --- a/modules/identity/src/Volo.Abp.Identity.HttpApi/Volo/Abp/Identity/IdentityUserController.cs +++ b/modules/identity/src/Volo.Abp.Identity.HttpApi/Volo/Abp/Identity/IdentityUserController.cs @@ -53,6 +53,13 @@ public class IdentityUserController : AbpControllerBase, IIdentityUserAppService return UserAppService.DeleteAsync(id); } + [HttpGet] + [Route("by-id/{id}")] + public virtual Task FindByIdAsync(Guid id) + { + return UserAppService.FindByIdAsync(id); + } + [HttpGet] [Route("{id}/roles")] public virtual Task> GetRolesAsync(Guid id) diff --git a/modules/identity/src/Volo.Abp.Identity.Web/Pages/Identity/Users/EditModal.cshtml.cs b/modules/identity/src/Volo.Abp.Identity.Web/Pages/Identity/Users/EditModal.cshtml.cs index 08ea27081b..b9f89b2446 100644 --- a/modules/identity/src/Volo.Abp.Identity.Web/Pages/Identity/Users/EditModal.cshtml.cs +++ b/modules/identity/src/Volo.Abp.Identity.Web/Pages/Identity/Users/EditModal.cshtml.cs @@ -83,8 +83,8 @@ public class EditModalModel : IdentityPageModel return null; } - var user = await IdentityUserAppService.GetAsync(userId.Value); - return user.UserName; + var user = await IdentityUserAppService.FindByIdAsync(userId.Value); + return user?.UserName; } public virtual async Task OnPostAsync() diff --git a/modules/identity/src/Volo.Abp.Identity.Web/wwwroot/client-proxies/identity-proxy.js b/modules/identity/src/Volo.Abp.Identity.Web/wwwroot/client-proxies/identity-proxy.js index 6de3aeb8d5..b30bd0b20d 100644 --- a/modules/identity/src/Volo.Abp.Identity.Web/wwwroot/client-proxies/identity-proxy.js +++ b/modules/identity/src/Volo.Abp.Identity.Web/wwwroot/client-proxies/identity-proxy.js @@ -102,6 +102,13 @@ }, ajaxParams)); }; + volo.abp.identity.identityUser.findById = function(id, ajaxParams) { + return abp.ajax($.extend(true, { + url: abp.appPath + 'api/identity/users/by-id/' + id + '', + type: 'GET' + }, ajaxParams)); + }; + volo.abp.identity.identityUser.getRoles = function(id, ajaxParams) { return abp.ajax($.extend(true, { url: abp.appPath + 'api/identity/users/' + id + '/roles', diff --git a/modules/identity/test/Volo.Abp.Identity.Application.Tests/Volo/Abp/Identity/IdentityUserAppService_Tests.cs b/modules/identity/test/Volo.Abp.Identity.Application.Tests/Volo/Abp/Identity/IdentityUserAppService_Tests.cs index 0c1a8d6ffc..ff3c503657 100644 --- a/modules/identity/test/Volo.Abp.Identity.Application.Tests/Volo/Abp/Identity/IdentityUserAppService_Tests.cs +++ b/modules/identity/test/Volo.Abp.Identity.Application.Tests/Volo/Abp/Identity/IdentityUserAppService_Tests.cs @@ -51,6 +51,37 @@ public class IdentityUserAppService_Tests : AbpIdentityApplicationTestBase result.PhoneNumber.ShouldBe(johnNash.PhoneNumber); } + [Fact] + public async Task FindByIdAsync_Should_Return_User_When_Exists() + { + var johnNash = GetUser("john.nash"); + + var result = await _userAppService.FindByIdAsync(johnNash.Id); + + result.ShouldNotBeNull(); + result.Id.ShouldBe(johnNash.Id); + result.UserName.ShouldBe(johnNash.UserName); + } + + [Fact] + public async Task FindByIdAsync_Should_Return_Null_When_User_Does_Not_Exist() + { + var result = await _userAppService.FindByIdAsync(Guid.NewGuid()); + + result.ShouldBeNull(); + } + + [Fact] + public async Task FindByIdAsync_Should_Return_Null_When_User_Is_Soft_Deleted() + { + var johnNash = GetUser("john.nash"); + await _userAppService.DeleteAsync(johnNash.Id); + + var result = await _userAppService.FindByIdAsync(johnNash.Id); + + result.ShouldBeNull(); + } + [Fact] public async Task GetListAsync() {