1
0
mirror of https://github.com/bitwarden/server.git synced 2025-07-02 16:42:50 -05:00

react to contact changes not being set from identity

This commit is contained in:
Kyle Spearrin
2017-01-24 22:46:54 -05:00
parent 9a10382b46
commit 0648c2d0a3
13 changed files with 104 additions and 84 deletions

View File

@ -19,22 +19,22 @@ namespace Bit.Api.Controllers
{
private readonly IDeviceRepository _deviceRepository;
private readonly IDeviceService _deviceService;
private readonly UserManager<User> _userManager;
private readonly IUserService _userService;
public DevicesController(
IDeviceRepository deviceRepository,
IDeviceService deviceService,
UserManager<User> userManager)
IUserService userService)
{
_deviceRepository = deviceRepository;
_deviceService = deviceService;
_userManager = userManager;
_userService = userService;
}
[HttpGet("{id}")]
public async Task<DeviceResponseModel> Get(string id)
{
var device = await _deviceRepository.GetByIdAsync(new Guid(id), new Guid(_userManager.GetUserId(User)));
var device = await _deviceRepository.GetByIdAsync(new Guid(id), _userService.GetProperUserId(User).Value);
if(device == null)
{
throw new NotFoundException();
@ -47,7 +47,7 @@ namespace Bit.Api.Controllers
[HttpGet("identifier/{identifier}")]
public async Task<DeviceResponseModel> GetByIdentifier(string identifier)
{
var device = await _deviceRepository.GetByIdentifierAsync(identifier, new Guid(_userManager.GetUserId(User)));
var device = await _deviceRepository.GetByIdentifierAsync(identifier, _userService.GetProperUserId(User).Value);
if(device == null)
{
throw new NotFoundException();
@ -60,7 +60,7 @@ namespace Bit.Api.Controllers
[HttpGet("")]
public async Task<ListResponseModel<DeviceResponseModel>> Get()
{
ICollection<Device> devices = await _deviceRepository.GetManyByUserIdAsync(new Guid(_userManager.GetUserId(User)));
ICollection<Device> devices = await _deviceRepository.GetManyByUserIdAsync(_userService.GetProperUserId(User).Value);
var responses = devices.Select(d => new DeviceResponseModel(d));
return new ListResponseModel<DeviceResponseModel>(responses);
}
@ -68,7 +68,7 @@ namespace Bit.Api.Controllers
[HttpPost("")]
public async Task<DeviceResponseModel> Post([FromBody]DeviceRequestModel model)
{
var device = model.ToDevice(_userManager.GetUserId(User));
var device = model.ToDevice(_userService.GetProperUserId(User));
await _deviceService.SaveAsync(device);
var response = new DeviceResponseModel(device);
@ -79,7 +79,7 @@ namespace Bit.Api.Controllers
[HttpPost("{id}")]
public async Task<DeviceResponseModel> Put(string id, [FromBody]DeviceRequestModel model)
{
var device = await _deviceRepository.GetByIdAsync(new Guid(id), new Guid(_userManager.GetUserId(User)));
var device = await _deviceRepository.GetByIdAsync(new Guid(id), _userService.GetProperUserId(User).Value);
if(device == null)
{
throw new NotFoundException();
@ -95,7 +95,7 @@ namespace Bit.Api.Controllers
[HttpPost("identifier/{identifier}/token")]
public async Task PutToken(string identifier, [FromBody]DeviceTokenRequestModel model)
{
var device = await _deviceRepository.GetByIdentifierAsync(identifier, new Guid(_userManager.GetUserId(User)));
var device = await _deviceRepository.GetByIdentifierAsync(identifier, _userService.GetProperUserId(User).Value);
if(device == null)
{
throw new NotFoundException();
@ -116,7 +116,7 @@ namespace Bit.Api.Controllers
[HttpPost("{id}/delete")]
public async Task Delete(string id)
{
var device = await _deviceRepository.GetByIdAsync(new Guid(id), new Guid(_userManager.GetUserId(User)));
var device = await _deviceRepository.GetByIdAsync(new Guid(id), _userService.GetProperUserId(User).Value);
if(device == null)
{
throw new NotFoundException();