From 374ef956569aa253b0fd0f07f958f78497f49954 Mon Sep 17 00:00:00 2001 From: Thomas Rittson <31796059+eliykat@users.noreply.github.com> Date: Fri, 9 Aug 2024 08:52:25 +1000 Subject: [PATCH] Add OrganizationUser_UpdateDataForKeyRotation sproc (#4601) --- ...anizationUser_UpdateDataForKeyRotation.sql | 36 ++++++++++++++++++ ...anizationUser_UpdateDataForKeyRotation.sql | 37 +++++++++++++++++++ 2 files changed, 73 insertions(+) create mode 100644 src/Sql/dbo/Stored Procedures/OrganizationUser_UpdateDataForKeyRotation.sql create mode 100644 util/Migrator/DbScripts/2024-08-09_00_OrganizationUser_UpdateDataForKeyRotation.sql diff --git a/src/Sql/dbo/Stored Procedures/OrganizationUser_UpdateDataForKeyRotation.sql b/src/Sql/dbo/Stored Procedures/OrganizationUser_UpdateDataForKeyRotation.sql new file mode 100644 index 0000000000..3c7047042c --- /dev/null +++ b/src/Sql/dbo/Stored Procedures/OrganizationUser_UpdateDataForKeyRotation.sql @@ -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 diff --git a/util/Migrator/DbScripts/2024-08-09_00_OrganizationUser_UpdateDataForKeyRotation.sql b/util/Migrator/DbScripts/2024-08-09_00_OrganizationUser_UpdateDataForKeyRotation.sql new file mode 100644 index 0000000000..11066e4954 --- /dev/null +++ b/util/Migrator/DbScripts/2024-08-09_00_OrganizationUser_UpdateDataForKeyRotation.sql @@ -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