1
0
mirror of https://github.com/bitwarden/server.git synced 2025-06-30 07:36:14 -05:00

fix: update stored procedure

This commit is contained in:
Ike Kottlowski
2025-06-25 17:18:31 -04:00
parent 943b0024bb
commit 853551d9bd
3 changed files with 79 additions and 42 deletions

View File

@ -6,20 +6,42 @@ AS
BEGIN
SET NOCOUNT ON;
;WITH PendingRequests AS (
SELECT
AR.*,
D.Id AS DeviceId,
ROW_NUMBER() OVER (PARTITION BY AR.RequestDeviceIdentifier ORDER BY AR.CreationDate DESC) AS rn
FROM dbo.AuthRequestView AR
LEFT JOIN
Device D ON AR.RequestDeviceIdentifier = D.Identifier
WHERE AR.Type IN (0, 1) -- 0 = AuthenticateAndUnlock, 1 = Unlock
AND AR.CreationDate >= DATEADD(MINUTE, -@ExpirationMinutes, GETUTCDATE())
AND AR.UserId = @UserId
)
SELECT PR.*
;
WITH
PendingRequests
AS
(
SELECT
AR.*,
D.Id AS DeviceId,
ROW_NUMBER() OVER (PARTITION BY AR.RequestDeviceIdentifier ORDER BY AR.CreationDate DESC) AS rn
FROM dbo.AuthRequestView AR
LEFT JOIN Device D ON AR.RequestDeviceIdentifier = D.Identifier
AND D.UserId = AR.UserId
WHERE AR.Type IN (0, 1) -- 0 = AuthenticateAndUnlock, 1 = Unlock
AND AR.CreationDate >= DATEADD(MINUTE, -@ExpirationMinutes, GETUTCDATE())
AND AR.UserId = @UserId
)
SELECT
PR.Id,
PR.UserId,
PR.OrganizationId,
PR.Type,
PR.RequestDeviceIdentifier,
PR.RequestDeviceType,
PR.RequestIpAddress,
PR.RequestCountryName,
PR.ResponseDeviceId,
PR.AccessCode,
PR.PublicKey,
PR.[Key],
PR.MasterPasswordHash,
PR.Approved,
PR.CreationDate,
PR.ResponseDate,
PR.AuthenticationDate,
PR.DeviceId
FROM PendingRequests PR
WHERE rn = 1
AND PR.Approved IS NULL;
AND PR.Approved IS NULL;
END;