Skip to content
This repository was archived by the owner on Aug 1, 2021. It is now read-only.

Commit 223b2ea

Browse files
committed
claim to remove
# Conflicts: # src/Backend/Jp.Infra.CrossCutting.Identity/Services/UserService.cs
1 parent f318b1f commit 223b2ea

16 files changed

Lines changed: 29771 additions & 15 deletions

File tree

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,6 @@ ClientBin/
193193
*.publishsettings
194194
node_modules/
195195
orleans.codegen.cs
196-
package-lock.json
197196

198197
# RIA/Silverlight projects
199198
Generated_Code/

src/Backend/Jp.Application/AutoMapper/ViewModelToDomainMappingProfile.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public ViewModelToDomainMappingProfile()
4646
CreateMap<SetPasswordViewModel, SetPasswordCommand>().ConstructUsing(c => new SetPasswordCommand(c.Id, c.NewPassword, c.ConfirmPassword));
4747
CreateMap<RemoveAccountViewModel, RemoveAccountCommand>().ConstructUsing(c => new RemoveAccountCommand(c.Id));
4848
CreateMap<SaveUserClaimViewModel, SaveUserClaimCommand>().ConstructUsing(c => new SaveUserClaimCommand(c.Username, c.Type, c.Value));
49-
CreateMap<RemoveUserClaimViewModel, RemoveUserClaimCommand>().ConstructUsing(c => new RemoveUserClaimCommand(c.Username, c.Type));
49+
CreateMap<RemoveUserClaimViewModel, RemoveUserClaimCommand>().ConstructUsing(c => new RemoveUserClaimCommand(c.Username, c.Type, c.Value));
5050
CreateMap<RemoveUserRoleViewModel, RemoveUserRoleCommand>().ConstructUsing(c => new RemoveUserRoleCommand(c.Username, c.Role));
5151
CreateMap<SaveUserRoleViewModel, SaveUserRoleCommand>().ConstructUsing(c => new SaveUserRoleCommand(c.Username, c.Role));
5252
CreateMap<RemoveUserLoginViewModel, RemoveUserLoginCommand>().ConstructUsing(c => new RemoveUserLoginCommand(c.Username, c.LoginProvider, c.ProviderKey));

src/Backend/Jp.Application/ViewModels/UserViewModels/RemoveUserClaimViewModel.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,7 @@ public class RemoveUserClaimViewModel
88
public string Type { get; set; }
99
[Required]
1010
public string Username { get; set; }
11+
12+
public string Value { get; set; }
1113
}
1214
}

src/Backend/Jp.Domain/CommandHandlers/ClientCommandHandler.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,6 @@ public async Task<bool> Handle(SaveClientCommand request, CancellationToken canc
301301
}
302302

303303

304-
305304
public async Task<bool> Handle(CopyClientCommand request, CancellationToken cancellationToken)
306305
{
307306
if (!request.IsValid())
@@ -310,7 +309,7 @@ public async Task<bool> Handle(CopyClientCommand request, CancellationToken canc
310309
return false;
311310
}
312311

313-
var savedClient = await _clientRepository.GetByClientId(request.Client.ClientId);
312+
var savedClient = await _clientRepository.GetClient(request.Client.ClientId);
314313
if (savedClient == null)
315314
{
316315
await Bus.RaiseEvent(new DomainNotification("Client", "Client not found"));

src/Backend/Jp.Domain/CommandHandlers/UserManagementCommandHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ public async Task<bool> Handle(RemoveUserClaimCommand request, CancellationToken
188188
return false;
189189
}
190190

191-
var success = await _userService.RemoveClaim(userDb.Id, request.Type);
191+
var success = await _userService.RemoveClaim(userDb.Id, request.Type, request.Value);
192192

193193
if (success)
194194
{

src/Backend/Jp.Domain/Commands/User/RemoveUserClaimCommand.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
using System;
21
using Jp.Domain.Validations.User;
32

43
namespace Jp.Domain.Commands.User
54
{
65
public class RemoveUserClaimCommand : UserClaimCommand
76
{
8-
public RemoveUserClaimCommand(string username, string type)
7+
8+
public RemoveUserClaimCommand(string username, string type, string value)
99
{
10+
Value = value;
1011
Type = type;
1112
Username = username;
1213
}

src/Backend/Jp.Domain/Interfaces/IUserService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public interface IUserService
3535
Task UpdateUserAsync(User user);
3636
Task<IEnumerable<Claim>> GetClaimByName(string userName);
3737
Task<bool> SaveClaim(Guid userId, Claim claim);
38-
Task<bool> RemoveClaim(Guid userId, string claimType);
38+
Task<bool> RemoveClaim(Guid userId, string claimType, string value);
3939
Task<IEnumerable<string>> GetRoles(string userName);
4040
Task<bool> RemoveRole(Guid userDbId, string requestRole);
4141
Task<bool> SaveRole(Guid userId, string role);

src/Backend/Jp.Infra.CrossCutting.Identity/Services/UserService.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -464,11 +464,15 @@ public async Task<bool> SaveClaim(Guid userDbId, Claim claim)
464464
return result.Succeeded;
465465
}
466466

467-
public async Task<bool> RemoveClaim(Guid userId, string type)
467+
public async Task<bool> RemoveClaim(Guid userId, string claimType, string value)
468468
{
469469
var user = await _userManager.FindByIdAsync(userId.ToString());
470470
var claims = await _userManager.GetClaimsAsync(user);
471-
var claimToRemove = claims.First(c => c.Type == type);
471+
472+
var claimToRemove = string.IsNullOrEmpty(value) ?
473+
claims.First(c => c.Type.Equals(claimType)) :
474+
claims.First(c => c.Type.Equals(claimType) && c.Value.Equals(value));
475+
472476
var result = await _userManager.RemoveClaimAsync(user, claimToRemove);
473477

474478
foreach (var error in result.Errors)

src/Backend/Jp.UserManagement/Controllers/UserAdminController.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ public async Task<ActionResult<DefaultResponse<UserViewModel>>> Details(string u
5858
return Response(irs);
5959
}
6060

61-
6261
[HttpPut, Route("{username}/update"), Authorize(Policy = "Admin")]
6362
public async Task<ActionResult<DefaultResponse<bool>>> Update(string username, [FromBody] UserViewModel model)
6463
{

src/Backend/Jp.UserManagement/Controllers/UserController.cs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
using System.Threading.Tasks;
2-
using Jp.Application.Interfaces;
1+
using Jp.Application.Interfaces;
32
using Jp.Application.ViewModels.UserViewModels;
43
using Jp.Domain.Core.Bus;
54
using Jp.Domain.Core.Notifications;
65
using Jp.Infra.CrossCutting.Tools.Model;
76
using MediatR;
87
using Microsoft.AspNetCore.Authorization;
98
using Microsoft.AspNetCore.Mvc;
9+
using System.Threading.Tasks;
1010

1111
namespace Jp.Management.Controllers
1212
{
@@ -37,6 +37,20 @@ public async Task<ActionResult<DefaultResponse<bool>>> Register([FromBody] Regis
3737
return Response(true);
3838
}
3939

40+
[HttpPost, Route("add-user")]
41+
public async Task<ActionResult<DefaultResponse<bool>>> AddUser([FromBody] RegisterUserViewModel model)
42+
{
43+
if (!ModelState.IsValid)
44+
{
45+
NotifyModelStateErrors();
46+
return Response(false);
47+
}
48+
49+
await _userAppService.Register(model);
50+
51+
return Response(true);
52+
}
53+
4054
[HttpPost, Route("register-provider")]
4155
public async Task<ActionResult<DefaultResponse<bool>>> RegisterWithProvider([FromBody] RegisterUserViewModel model)
4256
{
@@ -109,6 +123,6 @@ public async Task<ActionResult<DefaultResponse<bool>>> ConfirmEmail([FromBody] C
109123
return Response(true);
110124
}
111125

112-
126+
113127
}
114128
}

0 commit comments

Comments
 (0)