mirror of
https://github.com/bitwarden/server
synced 2025-12-06 00:03:34 +00:00
* migrate default collection to a shared collection when users are removed * remove redundant logic * fix test * fix tests * fix test * clean up * add migrations * run dotnet format * clean up, refactor duplicate logic to sproc, wip integration test * fix sql * add migration for new sproc * integration test wip * integration test wip * integration test wip * integration test wip * fix integration test LINQ expression * fix using wrong Id * wip integration test for DeleteManyAsync * fix LINQ * only set DefaultUserEmail when it is null in sproc * check for null * spelling, separate create and update request models * fix test * fix child class * refactor sproc * clean up * more cleanup * fix tests * fix user email * remove unneccesary test * add DefaultUserCollectionEmail to EF query * fix test * fix EF logic to match sprocs * clean up logic * cleanup
56 lines
1.2 KiB
Transact-SQL
56 lines
1.2 KiB
Transact-SQL
CREATE OR ALTER 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
|
|
|
|
-- Migrate DefaultUserCollection to SharedCollection
|
|
DECLARE @Ids [dbo].[GuidIdArray]
|
|
INSERT INTO @Ids (Id) VALUES (@Id)
|
|
EXEC [dbo].[OrganizationUser_MigrateDefaultCollection] @Ids
|
|
|
|
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].[AccessPolicy]
|
|
WHERE
|
|
[OrganizationUserId] = @Id
|
|
|
|
EXEC [dbo].[OrganizationSponsorship_OrganizationUserDeleted] @Id
|
|
|
|
DELETE
|
|
FROM
|
|
[dbo].[OrganizationUser]
|
|
WHERE
|
|
[Id] = @Id
|
|
END
|