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

Commit a681f5d

Browse files
committed
Bug fix - Clone and change clientId
1 parent a8829b9 commit a681f5d

File tree

15 files changed

+1256
-12
lines changed

15 files changed

+1256
-12
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public ViewModelToDomainMappingProfile()
5454
/*
5555
* Client commands
5656
*/
57-
CreateMap<Client, UpdateClientCommand>().ConstructUsing(c => new UpdateClientCommand(c));
57+
CreateMap<ClientViewModel, UpdateClientCommand>().ConstructUsing(c => new UpdateClientCommand(c, c.OldClientId));
5858
CreateMap<RemoveClientSecretViewModel, RemoveClientSecretCommand>().ConstructUsing(c => new RemoveClientSecretCommand(c.Id, c.ClientId));
5959
CreateMap<RemovePropertyViewModel, RemovePropertyCommand>().ConstructUsing(c => new RemovePropertyCommand(c.Id, c.ClientId));
6060
CreateMap<SaveClientSecretViewModel, SaveClientSecretCommand>().ConstructUsing(c => new SaveClientSecretCommand(c.ClientId, c.Description, c.Value, c.Type, c.Expiration, (int)c.Hash.GetValueOrDefault(HashType.Sha256)));
@@ -64,7 +64,7 @@ public ViewModelToDomainMappingProfile()
6464
CreateMap<RemoveClientViewModel, RemoveClientCommand>().ConstructUsing(c => new RemoveClientCommand(c.ClientId));
6565
CreateMap<CopyClientViewModel, CopyClientCommand>().ConstructUsing(c => new CopyClientCommand(c.ClientId));
6666
CreateMap<SaveClientViewModel, SaveClientCommand>().ConstructUsing(c => new SaveClientCommand(c.ClientId, c.ClientName, c.ClientUri, c.LogoUri, c.Description, c.ClientType));
67-
67+
6868
/*
6969
* Identity Resource commands
7070
*/

src/Backend/Jp.Application/Interfaces/IClientAppService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public interface IClientAppService: IDisposable
1111
{
1212
Task<IEnumerable<ClientListViewModel>> GetClients();
1313
Task<Client> GetClientDetails(string clientId);
14-
Task Update(Client client);
14+
Task Update(ClientViewModel client);
1515
Task<IEnumerable<SecretViewModel>> GetSecrets(string clientId);
1616
Task RemoveSecret(RemoveClientSecretViewModel model);
1717
Task SaveSecret(SaveClientSecretViewModel model);

src/Backend/Jp.Application/Services/ClientAppService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public async Task<Client> GetClientDetails(string clientId)
5353
return _mapper.Map<Client>(resultado);
5454
}
5555

56-
public Task Update(Client client)
56+
public Task Update(ClientViewModel client)
5757
{
5858
var registerCommand = _mapper.Map<UpdateClientCommand>(client);
5959
return Bus.SendCommand(registerCommand);
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using System.ComponentModel.DataAnnotations;
2+
using IdentityServer4.Models;
3+
4+
namespace Jp.Application.ViewModels.ClientsViewModels
5+
{
6+
public class ClientViewModel : Client
7+
{
8+
[Required]
9+
public string OldClientId { get; set; }
10+
}
11+
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public async Task Handle(UpdateClientCommand request, CancellationToken cancella
7878
}
7979

8080
// Businness logic here
81-
var savedClient = await _clientRepository.GetClient(request.Client.ClientId);
81+
var savedClient = await _clientRepository.GetClient(request.OldClientId);
8282
if (savedClient == null)
8383
{
8484
await Bus.RaiseEvent(new DomainNotification("1", "Client not found"));

src/Backend/Jp.Domain/Commands/Client/ClientCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ namespace Jp.Domain.Commands.Client
66
public abstract class ClientCommand : Command
77
{
88
public IdentityServer4.Models.Client Client { get; set; }
9-
9+
public string OldClientId { get; set; }
1010
}
1111
}

src/Backend/Jp.Domain/Commands/Client/UpdateClientCommand.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,11 @@ namespace Jp.Domain.Commands.Client
44
{
55
public class UpdateClientCommand : ClientCommand
66
{
7-
public UpdateClientCommand(IdentityServer4.Models.Client client)
7+
8+
9+
public UpdateClientCommand(IdentityServer4.Models.Client client, string oldClientId)
810
{
11+
OldClientId = oldClientId;
912
this.Client = client;
1013
}
1114

src/Backend/Jp.Domain/Validations/Client/ClientValidations.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ protected void ValidateClientId()
1616
RuleFor(c => c.Client.ClientId).NotEmpty().WithMessage("ClientId must be set");
1717
}
1818

19+
protected void ValidateOldClientId()
20+
{
21+
RuleFor(c => c.OldClientId).NotEmpty().WithMessage("Last ClientId must be set");
22+
}
23+
1924
protected void ValidateClientName()
2025
{
2126
RuleFor(c => c.Client.ClientName).NotEmpty().WithMessage("Client Name must be set");

src/Backend/Jp.Domain/Validations/Client/UpdateClientCommandValidation.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ public class UpdateClientCommandValidation : ClientValidation<UpdateClientComman
77
public UpdateClientCommandValidation()
88
{
99
ValidateGrantType();
10+
ValidateOldClientId();
1011
}
1112
}
1213
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public async Task<ActionResult<DefaultResponse<bool>>> Save([FromBody] SaveClien
4949

5050
[HttpPost, Route("update"), Authorize(Policy = "Admin")
5151
]
52-
public async Task<ActionResult<DefaultResponse<bool>>> Update([FromBody] Client client)
52+
public async Task<ActionResult<DefaultResponse<bool>>> Update([FromBody] ClientViewModel client)
5353
{
5454
if (!ModelState.IsValid)
5555
{

0 commit comments

Comments
 (0)