mirror of
https://github.com/bitwarden/server.git
synced 2025-06-30 07:36:14 -05: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,27 @@
|
||||
CREATE OR ALTER PROCEDURE [dbo].[Device_ReadActiveWithPendingAuthRequestsByUserId]
|
||||
@UserId UNIQUEIDENTIFIER,
|
||||
@ExpirationMinutes INT
|
||||
AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON;
|
||||
|
||||
SELECT
|
||||
D.*,
|
||||
AR.Id as AuthRequestId,
|
||||
AR.CreationDate as AuthRequestCreationDate
|
||||
FROM dbo.DeviceView D
|
||||
LEFT JOIN (
|
||||
SELECT TOP 1 -- Take only the top record sorted by auth request creation date
|
||||
Id,
|
||||
CreationDate,
|
||||
RequestDeviceIdentifier
|
||||
FROM dbo.AuthRequestView
|
||||
WHERE Type IN (0, 1) -- Include only AuthenticateAndUnlock and Unlock types, excluding Admin Approval (type 2)
|
||||
AND CreationDate >= DATEADD(MINUTE, -@ExpirationMinutes, GETUTCDATE()) -- Ensure the request hasn't expired
|
||||
AND Approved IS NULL -- Include only requests that haven't been acknowledged or approved
|
||||
ORDER BY CreationDate DESC
|
||||
) AR ON D.Identifier = AR.RequestDeviceIdentifier
|
||||
WHERE
|
||||
D.UserId = @UserId
|
||||
AND D.Active = 1; -- Include only active devices
|
||||
END;
|
Reference in New Issue
Block a user