mirror of
https://github.com/bitwarden/server
synced 2025-12-31 07:33:43 +00:00
Auth/pm 2996/add auth request data to devices response model (#5152)
fix(auth): [PM-2996] Add Pending Auth Request Data to Devices Response - New stored procedure to fetch the appropriate data. - Updated devices controller to respond with the new data. - Tests written at the controller and repository level. Resolves PM-2996
This commit is contained in:
committed by
GitHub
parent
5ae232e336
commit
cc96e35072
@@ -0,0 +1,38 @@
|
||||
using Bit.Core.Auth.Enums;
|
||||
using Bit.Core.Auth.Models.Data;
|
||||
using Bit.Infrastructure.EntityFramework.Repositories;
|
||||
|
||||
namespace Bit.Infrastructure.EntityFramework.Auth.Repositories.Queries;
|
||||
|
||||
public class DeviceWithPendingAuthByUserIdQuery
|
||||
{
|
||||
public IQueryable<DeviceAuthDetails> GetQuery(
|
||||
DatabaseContext dbContext,
|
||||
Guid userId,
|
||||
int expirationMinutes)
|
||||
{
|
||||
var devicesWithAuthQuery = (
|
||||
from device in dbContext.Devices
|
||||
where device.UserId == userId && device.Active
|
||||
select new
|
||||
{
|
||||
device,
|
||||
authRequest =
|
||||
(
|
||||
from authRequest in dbContext.AuthRequests
|
||||
where authRequest.RequestDeviceIdentifier == device.Identifier
|
||||
where authRequest.Type == AuthRequestType.AuthenticateAndUnlock || authRequest.Type == AuthRequestType.Unlock
|
||||
where authRequest.Approved == null
|
||||
where authRequest.UserId == userId
|
||||
where authRequest.CreationDate.AddMinutes(expirationMinutes) > DateTime.UtcNow
|
||||
orderby authRequest.CreationDate descending
|
||||
select authRequest
|
||||
).First()
|
||||
}).Select(deviceWithAuthRequest => new DeviceAuthDetails(
|
||||
deviceWithAuthRequest.device,
|
||||
deviceWithAuthRequest.authRequest.Id,
|
||||
deviceWithAuthRequest.authRequest.CreationDate));
|
||||
|
||||
return devicesWithAuthQuery;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user