mirror of
https://github.com/bitwarden/server.git
synced 2024-11-26 12:55:17 +01:00
PM-2731 - DevicesController.cs - Add new method GetExistenceByTypes (#3039)
* PM-2731 - DevicesController.cs - Add new method HasDevicesOfTypes to accept an array of DeviceType values and return a boolean if the authN user has at least a device of one of the given types. * Dotnet format to pass lint rules * PM-2731 - Update naming of HasDevicesOfTypes to be GetExistenceByTypes for increased clarity per PR feedback. * PM-2731-Make GetExistenceByTypes route singular * Update src/Api/Controllers/DevicesController.cs to use var Co-authored-by: Justin Baur <19896123+justindbaur@users.noreply.github.com> --------- Co-authored-by: Justin Baur <19896123+justindbaur@users.noreply.github.com>
This commit is contained in:
parent
926d9bb5f2
commit
a6ffadf086
@ -1,6 +1,7 @@
|
|||||||
using Bit.Api.Models.Request;
|
using Bit.Api.Models.Request;
|
||||||
using Bit.Api.Models.Response;
|
using Bit.Api.Models.Response;
|
||||||
using Bit.Core.Entities;
|
using Bit.Core.Entities;
|
||||||
|
using Bit.Core.Enums;
|
||||||
using Bit.Core.Exceptions;
|
using Bit.Core.Exceptions;
|
||||||
using Bit.Core.Repositories;
|
using Bit.Core.Repositories;
|
||||||
using Bit.Core.Services;
|
using Bit.Core.Services;
|
||||||
@ -65,6 +66,15 @@ public class DevicesController : Controller
|
|||||||
return new ListResponseModel<DeviceResponseModel>(responses);
|
return new ListResponseModel<DeviceResponseModel>(responses);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[HttpPost("exist-by-types")]
|
||||||
|
public async Task<ActionResult<bool>> GetExistenceByTypes([FromBody] DeviceType[] deviceTypes)
|
||||||
|
{
|
||||||
|
var userId = _userService.GetProperUserId(User).Value;
|
||||||
|
var devices = await _deviceRepository.GetManyByUserIdAsync(userId);
|
||||||
|
var userHasDeviceOfTypes = devices.Any(d => deviceTypes.Contains(d.Type));
|
||||||
|
return Ok(userHasDeviceOfTypes);
|
||||||
|
}
|
||||||
|
|
||||||
[HttpPost("")]
|
[HttpPost("")]
|
||||||
public async Task<DeviceResponseModel> Post([FromBody] DeviceRequestModel model)
|
public async Task<DeviceResponseModel> Post([FromBody] DeviceRequestModel model)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user