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:
@ -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)
|
||||
|
@ -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));
|
||||
|
@ -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]
|
||||
|
@ -24,6 +24,13 @@ BEGIN
|
||||
|
||||
BEGIN TRANSACTION User_DeleteById
|
||||
|
||||
-- Delete WebAuthnCredentials
|
||||
DELETE
|
||||
FROM
|
||||
[dbo].[WebAuthnCredential]
|
||||
WHERE
|
||||
[UserId] = @Id
|
||||
|
||||
-- Delete folders
|
||||
DELETE
|
||||
FROM
|
||||
|
Reference in New Issue
Block a user