Skip to content

Commit

Permalink
fix(device): [PM-2996] Devices with Auth Request - Updated the stored…
Browse files Browse the repository at this point in the history
… procedure with recommendations.
  • Loading branch information
Patrick-Pimentel-Bitwarden committed Dec 30, 2024
1 parent aaa8380 commit 67b35da
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,25 @@ CREATE PROCEDURE [dbo].[Device_ReadActiveWithPendingAuthRequestsByUserId]
@ExpirationMinutes INT
AS
BEGIN
SET NOCOUNT ON;

SELECT
D.*,
AR.Id as AuthRequestId,
AR.CreationDate as AuthRequestCreationDate
FROM [dbo].[DeviceView] D
LEFT OUTER JOIN (
FROM dbo.DeviceView D
LEFT JOIN (
SELECT TOP 1 -- Take only the top record sorted by auth request creation date
AR.Id,
AR.CreationDate,
AR.RequestDeviceIdentifier
FROM [dbo].[AuthRequestView] AR
WHERE AR.Type IN (0, 1) -- Include only AuthenticateAndUnlock and Unlock types, excluding Admin Approval (type 2)
AND DATEADD(mi, @ExpirationMinutes, AR.CreationDate) > GETUTCDATE() -- Ensure the request hasn't expired
AND AR.Approved IS NULL -- Include only requests that haven't been acknowledged or approved
ORDER BY AR.CreationDate DESC
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
AND D.Active = 1; -- Include only active devices
END;
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,25 @@ CREATE OR ALTER PROCEDURE [dbo].[Device_ReadActiveWithPendingAuthRequestsByUserI
@ExpirationMinutes INT
AS
BEGIN
SET NOCOUNT ON;

SELECT
D.*,
AR.Id as AuthRequestId,
AR.CreationDate as AuthRequestCreationDate
FROM [dbo].[DeviceView] D
LEFT OUTER JOIN (
AR.CreationDate as AuthRequestCreationDa
FROM dbo.DeviceView D
LEFT JOIN (
SELECT TOP 1 -- Take only the top record sorted by auth request creation date
AR.Id,
AR.CreationDate,
AR.RequestDeviceIdentifier
FROM [dbo].[AuthRequestView] AR
WHERE AR.Type IN (0, 1) -- Include only AuthenticateAndUnlock and Unlock types, excluding Admin Approval (type 2)
AND DATEADD(mi, @ExpirationMinutes, AR.CreationDate) > GETUTCDATE() -- Ensure the request hasn't expired
AND AR.Approved IS NULL -- Include only requests that haven't been acknowledged or approved
ORDER BY AR.CreationDate DESC
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
AND D.Active = 1; -- Include only active devices
END;

0 comments on commit 67b35da

Please sign in to comment.