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

feat(pm-20348) : add migration scripts for Read Pending Auth Requests by UserId stored procedure.

This commit is contained in:
Ike Kottlowski 2025-06-04 23:28:09 -04:00
parent 1ec06faf7d
commit 9a8317b2a9
No known key found for this signature in database
GPG Key ID: C86308E3DCA6D76F
2 changed files with 43 additions and 0 deletions

View File

@ -0,0 +1,21 @@
CREATE PROCEDURE [dbo].[AuthRequest_ReadPendingByUserId]
@UserId UNIQUEIDENTIFIER,
@ExpirationMinutes INT
AS
BEGIN
SET NOCOUNT ON;
;WITH PendingRequests AS (
SELECT
AR.*,
ROW_NUMBER() OVER (PARTITION BY RequestDeviceIdentifier ORDER BY CreationDate DESC) AS rn
FROM dbo.AuthRequestView AR
WHERE Type IN (0, 1)
AND AR.CreationDate >= DATEADD(MINUTE, -@ExpirationMinutes, GETUTCDATE())
AND AR.UserId = @UserId
AND AR.Approved IS NULL
)
SELECT PR.*
FROM PendingRequests PR
WHERE rn = 1;
END;

View File

@ -0,0 +1,22 @@
-- Adds a stored procedure to read pending authentication requests by user ID.
CREATE OR ALTER PROCEDURE [dbo].[AuthRequest_ReadPendingByUserId]
@UserId UNIQUEIDENTIFIER,
@ExpirationMinutes INT
AS
BEGIN
SET NOCOUNT ON;
;WITH PendingRequests AS (
SELECT
AR.*,
ROW_NUMBER() OVER (PARTITION BY RequestDeviceIdentifier ORDER BY CreationDate DESC) AS rn
FROM dbo.AuthRequestView AR
WHERE Type IN (0, 1)
AND AR.CreationDate >= DATEADD(MINUTE, -@ExpirationMinutes, GETUTCDATE())
AND AR.UserId = @UserId
AND AR.Approved IS NULL
)
SELECT PR.*
FROM PendingRequests PR
WHERE rn = 1;
END;