Skip to content

Commit 6b34f9c

Browse files
authored
Merge pull request #25557 from abpframework/maliming/fix-edit-modal-soft-deleted-creator
Fix user edit modal failing when creator or modifier is soft-deleted
2 parents c2029c4 + 025e9c4 commit 6b34f9c

8 files changed

Lines changed: 119 additions & 2 deletions

File tree

modules/identity/src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/IIdentityUserAppService.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,6 @@ public interface IIdentityUserAppService
2222
Task<IdentityUserDto> FindByUsernameAsync(string userName);
2323

2424
Task<IdentityUserDto> FindByEmailAsync(string email);
25+
26+
Task<IdentityUserDto> FindByIdAsync(Guid id);
2527
}

modules/identity/src/Volo.Abp.Identity.Application/Volo/Abp/Identity/IdentityUserAppService.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,14 @@ await UserManager.FindByEmailAsync(email)
180180
);
181181
}
182182

183+
[Authorize(IdentityPermissions.Users.Default)]
184+
public virtual async Task<IdentityUserDto> FindByIdAsync(Guid id)
185+
{
186+
return ObjectMapper.Map<IdentityUser, IdentityUserDto>(
187+
await UserManager.FindByIdAsync(id.ToString())
188+
);
189+
}
190+
183191
protected virtual async Task UpdateUserByInput(IdentityUser user, IdentityUserCreateOrUpdateDtoBase input)
184192
{
185193
if (!string.Equals(user.Email, input.Email, StringComparison.InvariantCultureIgnoreCase))

modules/identity/src/Volo.Abp.Identity.HttpApi.Client/ClientProxies/Volo/Abp/Identity/IdentityUserClientProxy.Generated.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,14 @@ public virtual async Task DeleteAsync(Guid id)
5858
});
5959
}
6060

61+
public virtual async Task<IdentityUserDto> FindByIdAsync(Guid id)
62+
{
63+
return await RequestAsync<IdentityUserDto>(nameof(FindByIdAsync), new ClientProxyRequestTypeValue
64+
{
65+
{ typeof(Guid), id }
66+
});
67+
}
68+
6169
public virtual async Task<ListResultDto<IdentityRoleDto>> GetRolesAsync(Guid id)
6270
{
6371
return await RequestAsync<ListResultDto<IdentityRoleDto>>(nameof(GetRolesAsync), new ClientProxyRequestTypeValue

modules/identity/src/Volo.Abp.Identity.HttpApi.Client/ClientProxies/identity-generate-proxy.json

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,23 @@
487487
"typeSimple": "Volo.Abp.Identity.IdentityUserDto"
488488
}
489489
},
490+
{
491+
"name": "FindByIdAsync",
492+
"parametersOnMethod": [
493+
{
494+
"name": "id",
495+
"typeAsString": "System.Guid, System.Private.CoreLib",
496+
"type": "System.Guid",
497+
"typeSimple": "string",
498+
"isOptional": false,
499+
"defaultValue": null
500+
}
501+
],
502+
"returnValue": {
503+
"type": "Volo.Abp.Identity.IdentityUserDto",
504+
"typeSimple": "Volo.Abp.Identity.IdentityUserDto"
505+
}
506+
},
490507
{
491508
"name": "GetAsync",
492509
"parametersOnMethod": [
@@ -1019,6 +1036,43 @@
10191036
},
10201037
"allowAnonymous": null,
10211038
"implementFrom": "Volo.Abp.Identity.IIdentityUserAppService"
1039+
},
1040+
"FindByIdAsyncById": {
1041+
"uniqueName": "FindByIdAsyncById",
1042+
"name": "FindByIdAsync",
1043+
"httpMethod": "GET",
1044+
"url": "api/identity/users/by-id/{id}",
1045+
"supportedVersions": [],
1046+
"parametersOnMethod": [
1047+
{
1048+
"name": "id",
1049+
"typeAsString": "System.Guid, System.Private.CoreLib",
1050+
"type": "System.Guid",
1051+
"typeSimple": "string",
1052+
"isOptional": false,
1053+
"defaultValue": null
1054+
}
1055+
],
1056+
"parameters": [
1057+
{
1058+
"nameOnMethod": "id",
1059+
"name": "id",
1060+
"jsonName": null,
1061+
"type": "System.Guid",
1062+
"typeSimple": "string",
1063+
"isOptional": false,
1064+
"defaultValue": null,
1065+
"constraintTypes": [],
1066+
"bindingSourceId": "Path",
1067+
"descriptorName": ""
1068+
}
1069+
],
1070+
"returnValue": {
1071+
"type": "Volo.Abp.Identity.IdentityUserDto",
1072+
"typeSimple": "Volo.Abp.Identity.IdentityUserDto"
1073+
},
1074+
"allowAnonymous": null,
1075+
"implementFrom": "Volo.Abp.Identity.IIdentityUserAppService"
10221076
}
10231077
}
10241078
},

modules/identity/src/Volo.Abp.Identity.HttpApi/Volo/Abp/Identity/IdentityUserController.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,13 @@ public virtual Task DeleteAsync(Guid id)
5353
return UserAppService.DeleteAsync(id);
5454
}
5555

56+
[HttpGet]
57+
[Route("by-id/{id}")]
58+
public virtual Task<IdentityUserDto> FindByIdAsync(Guid id)
59+
{
60+
return UserAppService.FindByIdAsync(id);
61+
}
62+
5663
[HttpGet]
5764
[Route("{id}/roles")]
5865
public virtual Task<ListResultDto<IdentityRoleDto>> GetRolesAsync(Guid id)

modules/identity/src/Volo.Abp.Identity.Web/Pages/Identity/Users/EditModal.cshtml.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ private async Task<string> GetUserNameOrNullAsync(Guid? userId)
8383
return null;
8484
}
8585

86-
var user = await IdentityUserAppService.GetAsync(userId.Value);
87-
return user.UserName;
86+
var user = await IdentityUserAppService.FindByIdAsync(userId.Value);
87+
return user?.UserName;
8888
}
8989

9090
public virtual async Task<IActionResult> OnPostAsync()

modules/identity/src/Volo.Abp.Identity.Web/wwwroot/client-proxies/identity-proxy.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,13 @@
102102
}, ajaxParams));
103103
};
104104

105+
volo.abp.identity.identityUser.findById = function(id, ajaxParams) {
106+
return abp.ajax($.extend(true, {
107+
url: abp.appPath + 'api/identity/users/by-id/' + id + '',
108+
type: 'GET'
109+
}, ajaxParams));
110+
};
111+
105112
volo.abp.identity.identityUser.getRoles = function(id, ajaxParams) {
106113
return abp.ajax($.extend(true, {
107114
url: abp.appPath + 'api/identity/users/' + id + '/roles',

modules/identity/test/Volo.Abp.Identity.Application.Tests/Volo/Abp/Identity/IdentityUserAppService_Tests.cs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,37 @@ public async Task GetAsync()
5151
result.PhoneNumber.ShouldBe(johnNash.PhoneNumber);
5252
}
5353

54+
[Fact]
55+
public async Task FindByIdAsync_Should_Return_User_When_Exists()
56+
{
57+
var johnNash = GetUser("john.nash");
58+
59+
var result = await _userAppService.FindByIdAsync(johnNash.Id);
60+
61+
result.ShouldNotBeNull();
62+
result.Id.ShouldBe(johnNash.Id);
63+
result.UserName.ShouldBe(johnNash.UserName);
64+
}
65+
66+
[Fact]
67+
public async Task FindByIdAsync_Should_Return_Null_When_User_Does_Not_Exist()
68+
{
69+
var result = await _userAppService.FindByIdAsync(Guid.NewGuid());
70+
71+
result.ShouldBeNull();
72+
}
73+
74+
[Fact]
75+
public async Task FindByIdAsync_Should_Return_Null_When_User_Is_Soft_Deleted()
76+
{
77+
var johnNash = GetUser("john.nash");
78+
await _userAppService.DeleteAsync(johnNash.Id);
79+
80+
var result = await _userAppService.FindByIdAsync(johnNash.Id);
81+
82+
result.ShouldBeNull();
83+
}
84+
5485
[Fact]
5586
public async Task GetListAsync()
5687
{

0 commit comments

Comments
 (0)