Skip to content
This repository has been archived by the owner on Sep 8, 2020. It is now read-only.

Commit

Permalink
Merge branch 'saga-rm' of https://github.com/ZA-PT/Obsidian into saga-rm
Browse files Browse the repository at this point in the history
  • Loading branch information
Henry Chu committed Oct 6, 2017
2 parents 1fad89f + af4cce9 commit 53fb841
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 24 deletions.
3 changes: 3 additions & 0 deletions src/Obsidian.Application/ClientManagement/ClientService.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Obsidian.Domain;
using Obsidian.Domain.Repositories;
using Obsidian.Foundation;
using System;
using System.Collections.Generic;
using System.Text;
Expand Down Expand Up @@ -27,6 +28,7 @@ public async Task<Client> CreateClient(string displayName,string redirectUri)
public async Task<Client> UpdateClientSecret(Guid clientId)
{
var client = await _repo.FindByIdAsync(clientId);
if (client == null) throw new EntityNotFoundException($"Can not find client with id {clientId}");
client.UpdateSecret();
await _repo.SaveAsync(client);
return client;
Expand All @@ -35,6 +37,7 @@ public async Task<Client> UpdateClientSecret(Guid clientId)
public async Task<Client> UpdateClient(Guid clientId,string displayName,string redirectUri)
{
var client = await _repo.FindByIdAsync(clientId);
if (client == null) throw new EntityNotFoundException($"Can not find client with id {clientId}");
client.DisplayName = displayName;
client.RedirectUri = new Uri(redirectUri);
await _repo.SaveAsync(client);
Expand Down
7 changes: 4 additions & 3 deletions src/Obsidian.Application/ScopeManagement/ScopeService.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
using Obsidian.Domain;
using Obsidian.Domain.Repositories;
using Obsidian.Foundation;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;

namespace Obsidian.Application.ScopeManagement
{
public class ScopeService
Expand All @@ -23,9 +23,10 @@ public async Task<PermissionScope> CreateScope(string scopeName,string displayNa
return scope;
}

public async Task<PermissionScope> UpdateScope(Guid Id, string displayName, string description, IList<ObsidianClaim> claims)
public async Task<PermissionScope> UpdateScope(Guid id, string displayName, string description, IList<ObsidianClaim> claims)
{
var scope = await _repo.FindByIdAsync(Id);
var scope = await _repo.FindByIdAsync(id);
if (scope == null) throw new EntityNotFoundException($"Can not find client with id {id}");
scope.Description = description;
scope.DisplayName = displayName;
scope.Claims = claims;
Expand Down
27 changes: 14 additions & 13 deletions src/Obsidian/Controllers/ApiControllers/ClientsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Obsidian.Application.Dto;
using Obsidian.Authorization;
using Obsidian.Domain.Repositories;
using Obsidian.Foundation;
using Obsidian.Foundation.ProcessManagement;
using Obsidian.Misc;
using Swashbuckle.AspNetCore.SwaggerGen;
Expand All @@ -18,14 +19,12 @@ namespace Obsidian.Controllers.ApiControllers
[Route("api/[controller]")]
public class ClientsController : Controller
{
private readonly SagaBus _sagaBus;
private readonly IClientRepository _clientRepository;
private readonly ClientService _service;

public ClientsController(IClientRepository repo, SagaBus bus, ClientService service)
public ClientsController(IClientRepository repo, ClientService service)
{
_clientRepository = repo;
_sagaBus = bus;
_service = service;
}

Expand Down Expand Up @@ -96,29 +95,31 @@ public async Task<IActionResult> Post([FromBody] ClientCreationDto dto)
[ValidateModel]
public async Task<IActionResult> Put([FromBody]UpdateClientDto dto, Guid id)
{
var client = await _clientRepository.FindByIdAsync(id);
if (client == null) return NotFound();
client = await _service.UpdateClient(id, dto.DisplayName, dto.RedirectUri);
if (client != null)
try
{
await _service.UpdateClient(id, dto.DisplayName, dto.RedirectUri);
return Created(Url.Action(), null);
}
return BadRequest();
catch (EntityNotFoundException)
{
return NotFound();
}
}

[HttpPut("{id:guid}/Secret")]
[RequireClaim(ManagementAPIClaimsType.IsClientSecretEditor, "Yes")]
[ValidateModel]
public async Task<IActionResult> UpdateSecret(Guid id)
{
var client = await _clientRepository.FindByIdAsync(id);
if (client == null) return NotFound();
client = await _service.UpdateClientSecret(id);
if (client != null)
try
{
await _service.UpdateClientSecret(id);
return Created(Url.Action(), null);
}
return BadRequest();
catch (EntityNotFoundException)
{
return NotFound();
}
}
}
}
16 changes: 8 additions & 8 deletions src/Obsidian/Controllers/ApiControllers/ScopesController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Obsidian.Application.ScopeManagement;
using Obsidian.Authorization;
using Obsidian.Domain.Repositories;
using Obsidian.Foundation;
using Obsidian.Foundation.ProcessManagement;
using Obsidian.Misc;
using System;
Expand All @@ -16,14 +17,12 @@ namespace Obsidian.Controllers.ApiControllers
[Route("api/[controller]")]
public class ScopesController : Controller
{
private readonly SagaBus _sagaBus;
private readonly IPermissionScopeRepository _scopeRepository;
private readonly ScopeService _service;

public ScopesController(IPermissionScopeRepository scopeRepo, SagaBus bus, ScopeService service)
public ScopesController(IPermissionScopeRepository scopeRepo, ScopeService service)
{
_scopeRepository = scopeRepo;
_sagaBus = bus;
_service = service;
}

Expand Down Expand Up @@ -65,14 +64,15 @@ public async Task<IActionResult> Post([FromBody]ScopeCreationDto dto)
[RequireClaim(ManagementAPIClaimsType.IsScopeEditor, "Yes")]
public async Task<IActionResult> Put([FromBody] UpdateScopeDto dto, Guid id)
{
var scope = await _scopeRepository.FindByIdAsync(id);
if (scope == null) return NotFound();
scope = await _service.UpdateScope(id, dto.DisplayName, dto.Description, dto.Claims);
if (scope != null)
try
{
await _service.UpdateScope(id, dto.DisplayName, dto.Description, dto.Claims);
return Created(Url.Action(), null);
}
return BadRequest();
catch (EntityNotFoundException)
{
return NotFound();
}
}
}
}

0 comments on commit 53fb841

Please sign in to comment.