From 9faa9406a6f6d3185bed09f02365e008ea74fd9f Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Tue, 1 Sep 2020 15:07:47 -0400 Subject: [PATCH] delete sso user when deleting org user (#901) --- .../OrganizationUser_DeleteById.sql | 16 ++++++ .../DbScripts/2020-09-01_00_DeleteSsoUser.sql | 49 +++++++++++++++++++ 2 files changed, 65 insertions(+) create mode 100644 util/Migrator/DbScripts/2020-09-01_00_DeleteSsoUser.sql diff --git a/src/Sql/dbo/Stored Procedures/OrganizationUser_DeleteById.sql b/src/Sql/dbo/Stored Procedures/OrganizationUser_DeleteById.sql index b8f751ac93..be2a12eeb0 100644 --- a/src/Sql/dbo/Stored Procedures/OrganizationUser_DeleteById.sql +++ b/src/Sql/dbo/Stored Procedures/OrganizationUser_DeleteById.sql @@ -5,6 +5,22 @@ BEGIN SET NOCOUNT ON EXEC [dbo].[User_BumpAccountRevisionDateByOrganizationUserId] @Id + + DECLARE @OrganizationId UNIQUEIDENTIFIER + DECLARE @UserId UNIQUEIDENTIFIER + + SELECT + @OrganizationId = [OrganizationId], + @UserId = [UserId] + FROM + [dbo].[OrganizationUser] + WHERE + [Id] = @Id + + IF @OrganizationId IS NOT NULL AND @UserId IS NOT NULL + BEGIN + EXEC [dbo].[SsoUser_Delete] @UserId, @OrganizationId + END DELETE FROM diff --git a/util/Migrator/DbScripts/2020-09-01_00_DeleteSsoUser.sql b/util/Migrator/DbScripts/2020-09-01_00_DeleteSsoUser.sql new file mode 100644 index 0000000000..7b8b3fe8ea --- /dev/null +++ b/util/Migrator/DbScripts/2020-09-01_00_DeleteSsoUser.sql @@ -0,0 +1,49 @@ +IF OBJECT_ID('[dbo].[OrganizationUser_DeleteById]') IS NOT NULL +BEGIN + DROP PROCEDURE [dbo].[OrganizationUser_DeleteById] +END +GO + +CREATE PROCEDURE [dbo].[OrganizationUser_DeleteById] + @Id UNIQUEIDENTIFIER +AS +BEGIN + SET NOCOUNT ON + + EXEC [dbo].[User_BumpAccountRevisionDateByOrganizationUserId] @Id + + DECLARE @OrganizationId UNIQUEIDENTIFIER + DECLARE @UserId UNIQUEIDENTIFIER + + SELECT + @OrganizationId = [OrganizationId], + @UserId = [UserId] + FROM + [dbo].[OrganizationUser] + WHERE + [Id] = @Id + + IF @OrganizationId IS NOT NULL AND @UserId IS NOT NULL + BEGIN + EXEC [dbo].[SsoUser_Delete] @UserId, @OrganizationId + END + + DELETE + FROM + [dbo].[CollectionUser] + WHERE + [OrganizationUserId] = @Id + + DELETE + FROM + [dbo].[GroupUser] + WHERE + [OrganizationUserId] = @Id + + DELETE + FROM + [dbo].[OrganizationUser] + WHERE + [Id] = @Id +END +GO