1
0
mirror of https://github.com/bitwarden/server.git synced 2025-07-02 08:32:50 -05:00

[PM-3505][PM-4587] Update Delete Organization and User SPROCs and EF methods (#3604)

* update Organization_DeleteById SPROC

* Add migration for user delete

* Updated delete methods for EF support

* added WITH RECOMPILE

* updating sprocs in sql project

* Add recompile
This commit is contained in:
Ike
2023-12-27 07:08:49 -08:00
committed by GitHub
parent c60f260c0f
commit 9b50cf89b7
6 changed files with 290 additions and 0 deletions

View File

@ -157,6 +157,8 @@ public class OrganizationRepository : Repository<Core.AdminConsole.Entities.Orga
await deleteCiphersTransaction.CommitAsync();
var organizationDeleteTransaction = await dbContext.Database.BeginTransactionAsync();
await dbContext.AuthRequests.Where(ar => ar.OrganizationId == organization.Id)
.ExecuteDeleteAsync();
await dbContext.SsoUsers.Where(su => su.OrganizationId == organization.Id)
.ExecuteDeleteAsync();
await dbContext.SsoConfigs.Where(sc => sc.OrganizationId == organization.Id)

View File

@ -210,6 +210,7 @@ public class UserRepository : Repository<Core.Entities.User, User, Guid>, IUserR
var transaction = await dbContext.Database.BeginTransactionAsync();
dbContext.WebAuthnCredentials.RemoveRange(dbContext.WebAuthnCredentials.Where(w => w.UserId == user.Id));
dbContext.Ciphers.RemoveRange(dbContext.Ciphers.Where(c => c.UserId == user.Id));
dbContext.Folders.RemoveRange(dbContext.Folders.Where(f => f.UserId == user.Id));
dbContext.AuthRequests.RemoveRange(dbContext.AuthRequests.Where(s => s.UserId == user.Id));

View File

@ -1,5 +1,6 @@
CREATE PROCEDURE [dbo].[Organization_DeleteById]
@Id UNIQUEIDENTIFIER
WITH RECOMPILE
AS
BEGIN
SET NOCOUNT ON
@ -25,6 +26,12 @@ BEGIN
BEGIN TRANSACTION Organization_DeleteById
DELETE
FROM
[dbo].[AuthRequest]
WHERE
[OrganizationId] = @Id
DELETE
FROM
[dbo].[SsoUser]

View File

@ -24,6 +24,13 @@ BEGIN
BEGIN TRANSACTION User_DeleteById
-- Delete WebAuthnCredentials
DELETE
FROM
[dbo].[WebAuthnCredential]
WHERE
[UserId] = @Id
-- Delete folders
DELETE
FROM