1
0
mirror of https://github.com/bitwarden/server.git synced 2024-11-21 12:05:42 +01:00

Add OrganizationUser_UpdateDataForKeyRotation sproc (#4601)

This commit is contained in:
Thomas Rittson 2024-08-09 08:52:25 +10:00 committed by GitHub
parent 58a314d9f4
commit 374ef95656
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 73 additions and 0 deletions

View File

@ -0,0 +1,36 @@
CREATE PROCEDURE [dbo].[OrganizationUser_UpdateDataForKeyRotation]
@UserId UNIQUEIDENTIFIER,
@OrganizationUserJson NVARCHAR(MAX)
AS
BEGIN
SET NOCOUNT ON
-- Parse the JSON string and insert into a temporary table
DECLARE @OrganizationUserInput AS TABLE (
[Id] UNIQUEIDENTIFIER,
[ResetPasswordKey] VARCHAR(MAX)
)
INSERT INTO @OrganizationUserInput
SELECT
[Id],
[ResetPasswordKey]
FROM OPENJSON(@OrganizationUserJson)
WITH (
[Id] UNIQUEIDENTIFIER '$.Id',
[ResetPasswordKey] VARCHAR(MAX) '$.ResetPasswordKey'
)
-- Perform the update
UPDATE
[dbo].[OrganizationUser]
SET
[ResetPasswordKey] = OUI.[ResetPasswordKey]
FROM
[dbo].[OrganizationUser] OU
INNER JOIN
@OrganizationUserInput OUI ON OU.Id = OUI.Id
WHERE
OU.[UserId] = @UserId
END

View File

@ -0,0 +1,37 @@
CREATE OR ALTER PROCEDURE [dbo].[OrganizationUser_UpdateDataForKeyRotation]
@UserId UNIQUEIDENTIFIER,
@OrganizationUserJson NVARCHAR(MAX)
AS
BEGIN
SET NOCOUNT ON
-- Parse the JSON string and insert into a temporary table
DECLARE @OrganizationUserInput AS TABLE (
[Id] UNIQUEIDENTIFIER,
[ResetPasswordKey] VARCHAR(MAX)
)
INSERT INTO @OrganizationUserInput
SELECT
[Id],
[ResetPasswordKey]
FROM OPENJSON(@OrganizationUserJson)
WITH (
[Id] UNIQUEIDENTIFIER '$.Id',
[ResetPasswordKey] VARCHAR(MAX) '$.ResetPasswordKey'
)
-- Perform the update
UPDATE
[dbo].[OrganizationUser]
SET
[ResetPasswordKey] = OUI.[ResetPasswordKey]
FROM
[dbo].[OrganizationUser] OU
INNER JOIN
@OrganizationUserInput OUI ON OU.Id = OUI.Id
WHERE
OU.[UserId] = @UserId
END
GO