1
0
mirror of https://github.com/bitwarden/server.git synced 2025-07-17 07:30:59 -05:00

handle user delete scenarios when part of org

This commit is contained in:
Kyle Spearrin
2017-04-27 17:28:39 -04:00
parent da03c276aa
commit 628a72b13f
6 changed files with 66 additions and 4 deletions

View File

@ -179,5 +179,6 @@
<Build Include="dbo\Stored Procedures\OrganizationUserOrganizationDetails_ReadByUserIdStatus.sql" />
<Build Include="dbo\Stored Procedures\OrganizationUserUserDetails_ReadById.sql" />
<Build Include="dbo\User Defined Types\GuidIdArray.sql" />
<Build Include="dbo\Stored Procedures\OrganizationUser_ReadCountByOrganizationOwnerUser.sql" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,14 @@
CREATE PROCEDURE [dbo].[OrganizationUser_ReadCountByOrganizationOwnerUser]
@UserId UNIQUEIDENTIFIER
AS
BEGIN
SET NOCOUNT ON
SELECT
COUNT(1)
FROM
[dbo].[OrganizationUser] OU
WHERE
OU.[UserId] = @UserId
AND OU.[Type] = 0
END

View File

@ -6,6 +6,7 @@ BEGIN
SET NOCOUNT ON
DECLARE @BatchSize INT = 100
-- Delete ciphers
WHILE @BatchSize > 0
BEGIN
BEGIN TRANSACTION User_DeleteById_Ciphers
@ -23,12 +24,25 @@ BEGIN
BEGIN TRANSACTION User_DeleteById
-- Delete collection users
DELETE
CU
FROM
[dbo].[CollectionUser] CU
INNER JOIN
[dbo].[OrganizationUser] OU ON OU.[Id] = CU.[OrganizationUserId]
WHERE
OU.[UserId] = @Id
-- Delete organization users
DELETE
FROM
[dbo].[Device]
[dbo].[OrganizationUser]
WHERE
[UserId] = @Id
AND [Type] != 0 -- 0 = owner
-- Finally, delete the user
DELETE
FROM
[dbo].[User]