1
0
mirror of https://github.com/bitwarden/server synced 2025-12-16 00:03:54 +00:00

Add support for destroying seeded data

This commit is contained in:
Hinton
2025-10-07 14:59:17 -07:00
parent 2b340b72da
commit 79f5d8f147
4 changed files with 83 additions and 13 deletions

View File

@@ -1,7 +1,9 @@
using Bit.Infrastructure.EntityFramework.Models;
using Bit.Infrastructure.EntityFramework.AdminConsole.Models;
using Bit.Infrastructure.EntityFramework.Models;
using Bit.Infrastructure.EntityFramework.Repositories;
using Bit.Seeder.Factories;
using LinqToDB.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
namespace Bit.Seeder.Recipes;
@@ -34,4 +36,18 @@ public class OrganizationWithUsersRecipe(DatabaseContext db)
return organization.Id;
}
public void Destroy(Guid organizationId)
{
var organization = db.Organizations.Include(o => o.OrganizationUsers)
.ThenInclude(ou => ou.User).FirstOrDefault(p => p.Id == organizationId);
if (organization == null)
{
throw new Exception($"Organization with ID {organizationId} not found.");
}
var users = organization.OrganizationUsers.Select(u => u.User);
db.RemoveRange(users);
db.Remove(organization);
}
}