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:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user