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

Commit 677bf74

Browse files
Merge pull request #31 from alperhankendi/master
fixed some bugs on jpadmin.UI and Jp.Management
2 parents 4313809 + 1087fde commit 677bf74

File tree

10 files changed

+37
-12
lines changed

10 files changed

+37
-12
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public ViewModelToDomainMappingProfile()
7070
* Identity Resource commands
7171
*/
7272
CreateMap<IdentityResource, RegisterIdentityResourceCommand>().ConstructUsing(c => new RegisterIdentityResourceCommand(c));
73-
CreateMap<IdentityResource, UpdateIdentityResourceCommand>().ConstructUsing(c => new UpdateIdentityResourceCommand(c));
73+
CreateMap<IdentityResourceViewModel, UpdateIdentityResourceCommand>().ConstructUsing(c => new UpdateIdentityResourceCommand(c,c.OldName));
7474
CreateMap<RemoveIdentityResourceViewModel, RemoveIdentityResourceCommand>().ConstructUsing(c => new RemoveIdentityResourceCommand(c.Name));
7575

7676
/*
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
using IdentityServer4.Models;
2+
3+
namespace Jp.Application.ViewModels.IdentityResourceViewModels
4+
{
5+
public class IdentityResourceViewModel : IdentityResource
6+
{
7+
public string OldName { get; set; }
8+
}
9+
}

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<bool> Handle(UpdateClientCommand request, CancellationToken ca
7878
return false;
7979
}
8080

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

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ public async Task<bool> Handle(UpdateIdentityResourceCommand request, Cancellati
6262
NotifyValidationErrors(request);
6363
return false;
6464
}
65-
66-
var savedClient = await _identityResourceRepository.GetByName(request.Resource.Name);
65+
66+
var savedClient = await _identityResourceRepository.GetByName(request.OldIdentityResourceName != request.Resource.Name ? request.OldIdentityResourceName : request.Resource.Name);
6767
if (savedClient == null)
6868
{
6969
await Bus.RaiseEvent(new DomainNotification("1", "Resource not found"));

src/Backend/Jp.Domain/Commands/IdentityResource/IdentityResourceCommand.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ namespace Jp.Domain.Commands.IdentityResource
66
public abstract class IdentityResourceCommand : Command
77
{
88
public IdentityServer4.Models.IdentityResource Resource { get; protected set; }
9+
10+
public string OldIdentityResourceName { get; protected set; }
911

1012
}
1113
}

src/Backend/Jp.Domain/Commands/IdentityResource/UpdateIdentityResourceCommand.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ namespace Jp.Domain.Commands.IdentityResource
44
{
55
public class UpdateIdentityResourceCommand : IdentityResourceCommand
66
{
7-
public UpdateIdentityResourceCommand(IdentityServer4.Models.IdentityResource resource)
7+
public UpdateIdentityResourceCommand(IdentityServer4.Models.IdentityResource resource,string oldIdentityResourceName)
88
{
99
Resource = resource;
10+
this.OldIdentityResourceName = oldIdentityResourceName;
1011
}
1112

1213
public override bool IsValid()

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ public async Task<ActionResult<DefaultResponse<bool>>> Save([FromBody] IdentityR
5454
return Response(true);
5555
}
5656

57-
[HttpPost, Route("update"), Authorize(Policy = "Admin")]
58-
public async Task<ActionResult<DefaultResponse<bool>>> Update([FromBody] IdentityResource model)
57+
[HttpPut, Route("update"), Authorize(Policy = "Admin")]
58+
public async Task<ActionResult<DefaultResponse<bool>>> Update([FromBody] IdentityResourceViewModel model)
5959
{
6060
if (!ModelState.IsValid)
6161
{

src/Frontend/Jp.AdminUI/src/app/panel/identity-resources/edit/identity-resource-edit.component.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Component, OnInit } from "@angular/core";
22
import { TranslatorService } from "@core/translator/translator.service";
3-
import { flatMap } from "rxjs/operators";
3+
import { flatMap,tap } from "rxjs/operators";
44
import { ActivatedRoute, Router } from "@angular/router";
55
import { ToasterConfig, ToasterService } from "angular2-toaster";
66
import { DefaultResponse } from "@shared/viewModel/default-response.model";
@@ -26,6 +26,7 @@ export class IdentityResourceEditComponent implements OnInit {
2626
});
2727
public showButtonLoading: boolean;
2828
standardClaims: string[];
29+
public name:string;
2930

3031
constructor(
3132
private route: ActivatedRoute,
@@ -35,7 +36,13 @@ export class IdentityResourceEditComponent implements OnInit {
3536
public toasterService: ToasterService) { }
3637

3738
public ngOnInit() {
38-
this.route.params.pipe(flatMap(p => this.identityResourceService.getIdentityResourceDetails(p["name"]))).subscribe(result => this.model = result.data);
39+
40+
this.route.params
41+
.pipe(tap(p => this.name = p["name"]))
42+
.pipe(flatMap(p =>
43+
this.identityResourceService.getIdentityResourceDetails(p["name"])
44+
))
45+
.subscribe(result => this.model = result.data);
3946
this.errors = [];
4047
this.showButtonLoading = false;
4148
this.standardClaims = StandardClaims.claims;
@@ -46,7 +53,7 @@ export class IdentityResourceEditComponent implements OnInit {
4653
this.showButtonLoading = true;
4754
this.errors = [];
4855
try {
49-
56+
this.model.oldName = this.name;
5057
this.identityResourceService.update(this.model).subscribe(
5158
registerResult => {
5259
if (registerResult.data) {

src/Frontend/Jp.AdminUI/src/app/shared/viewModel/identity-resource.model.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@ export class IdentityResource {
1313
displayName: string;
1414
description: string;
1515
userClaims: string[];
16+
oldName:string;
1617
}

tests/JpProject.Domain.Tests/ClientTests/ClientCommandHandlerTests.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,13 @@ public async Task ShouldNotAcceptNegativeDeviceCodeLifetime()
176176
public async Task ShouldUpdateClient()
177177
{
178178
var command = ClientCommandFaker.GenerateUpdateClientCommand().Generate();
179-
_clientRepository.Setup(s => s.UpdateWithChildrens(It.Is<Client>(a => a.ClientId == command.Client.ClientId))).Returns(Task.CompletedTask);
180-
_clientRepository.Setup(s => s.GetClient(It.Is<string>(a => a == command.Client.ClientId))).ReturnsAsync(EntityClientFaker.GenerateClient().Generate());
179+
180+
var clientId = command.Client.ClientId == command.OldClientId
181+
? command.Client.ClientId
182+
: command.OldClientId;
183+
184+
_clientRepository.Setup(s => s.UpdateWithChildrens(It.Is<Client>(a => a.ClientId == clientId))).Returns(Task.CompletedTask);
185+
_clientRepository.Setup(s => s.GetClient(It.Is<string>(a => a == clientId))).ReturnsAsync(EntityClientFaker.GenerateClient().Generate());
181186
_uow.Setup(s => s.Commit()).Returns(true);
182187

183188
var result = await _commandHandler.Handle(command, _tokenSource.Token);

0 commit comments

Comments
 (0)