mirror of
https://github.com/bitwarden/server.git
synced 2025-06-30 07:36:14 -05:00
feat: create new view for pending AuthRequest in sql project
This commit is contained in:
38
src/Sql/dbo/Auth/Views/AuthRequestPendingDetailsView.sql
Normal file
38
src/Sql/dbo/Auth/Views/AuthRequestPendingDetailsView.sql
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
CREATE VIEW [dbo].[AuthRequestPendingDetailsView]
|
||||||
|
AS
|
||||||
|
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].[AuthRequest] [AR]
|
||||||
|
LEFT JOIN [dbo].[Device] [D]
|
||||||
|
ON [AR].[RequestDeviceIdentifier] = [D].[Identifier]
|
||||||
|
AND [D].[UserId] = [AR].[UserId]
|
||||||
|
WHERE [AR].[Type] IN (0, 1) -- 0 = AuthenticateAndUnlock, 1 = Unlock
|
||||||
|
)
|
||||||
|
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 [PR].[rn] = 1
|
||||||
|
AND [PR].[Approved] IS NULL -- since we only want pending requests we only want the most recent that is also approved = null
|
Reference in New Issue
Block a user