1
0
mirror of https://github.com/bitwarden/server synced 2026-01-27 23:03:31 +00:00

Remove redundant OrganizationId column; remove private read method used by bulk insert

This commit is contained in:
Thomas Rittson
2026-01-01 09:30:24 +10:00
parent f668a0ce0a
commit 7ea237f5d5
15 changed files with 79 additions and 138 deletions

View File

@@ -1,4 +1,4 @@
using Bit.Core.Enums;
using Bit.Core.Enums;
using Bit.Core.Repositories;
using Xunit;
@@ -40,8 +40,8 @@ public class CreateDefaultCollectionsTests
Assert.All(defaultCollections, c => Assert.Equal("My Items", c.Item1.Name));
Assert.All(defaultCollections, c => Assert.Equal(organization.Id, c.Item1.OrganizationId));
var semaphores = await collectionRepository.GetDefaultCollectionSemaphoresAsync(organization.Id);
Assert.Equal([orgUser1.Id, orgUser2.Id], semaphores.ToHashSet());
var semaphores = await collectionRepository.GetDefaultCollectionSemaphoresAsync([orgUser1.Id, orgUser2.Id]);
Assert.Equal([orgUser1.Id, orgUser2.Id], semaphores);
// Verify each user has exactly 1 collection with correct permissions
var orgUser1Collection = Assert.Single(defaultCollections,
@@ -100,7 +100,7 @@ public class CreateDefaultCollectionsTests
Assert.Single(defaultCollections);
var semaphores = await collectionRepository.GetDefaultCollectionSemaphoresAsync(organization.Id);
var semaphores = await collectionRepository.GetDefaultCollectionSemaphoresAsync([orgUser.Id]);
Assert.Equal([orgUser.Id], semaphores);
var access = await collectionRepository.GetManyUsersByIdAsync(defaultCollections.Single().Id);

View File

@@ -1,10 +1,4 @@
using Bit.Core.AdminConsole.Entities;
using Bit.Core.Billing.Enums;
using Bit.Core.Entities;
using Bit.Core.Enums;
using Bit.Core.Repositories;
using Bit.Infrastructure.EntityFramework.Repositories;
using Microsoft.EntityFrameworkCore;
using Bit.Core.Repositories;
using Xunit;
namespace Bit.Infrastructure.IntegrationTest.AdminConsole.Repositories.CollectionRepository;
@@ -32,14 +26,14 @@ public class DefaultCollectionSemaphoreTests
"My Items");
// Verify semaphore exists
var semaphoreBefore = await collectionRepository.GetDefaultCollectionSemaphoresAsync(organization.Id);
var semaphoreBefore = await collectionRepository.GetDefaultCollectionSemaphoresAsync([orgUser.Id]);
Assert.Single(semaphoreBefore, s => s == orgUser.Id);
// Act - Delete organization user
await organizationUserRepository.DeleteAsync(orgUser);
// Assert - Semaphore should be cascade deleted
var semaphoreAfter = await collectionRepository.GetDefaultCollectionSemaphoresAsync(organization.Id);
var semaphoreAfter = await collectionRepository.GetDefaultCollectionSemaphoresAsync([orgUser.Id]);
Assert.Empty(semaphoreAfter);
}
@@ -65,14 +59,14 @@ public class DefaultCollectionSemaphoreTests
"My Items");
// Verify semaphore exists
var semaphoreBefore = await collectionRepository.GetDefaultCollectionSemaphoresAsync(organization.Id);
var semaphoreBefore = await collectionRepository.GetDefaultCollectionSemaphoresAsync([orgUser.Id]);
Assert.Single(semaphoreBefore, s => s == orgUser.Id);
// Act - Delete organization (which cascades to OrganizationUser, which cascades to semaphore)
await organizationRepository.DeleteAsync(organization);
// Assert - Semaphore should be cascade deleted via OrganizationUser
var semaphoreAfter = await collectionRepository.GetDefaultCollectionSemaphoresAsync(organization.Id);
var semaphoreAfter = await collectionRepository.GetDefaultCollectionSemaphoresAsync([orgUser.Id]);
Assert.Empty(semaphoreAfter);
}
}

View File

@@ -31,7 +31,7 @@ public class UpsertDefaultCollectionsBulkTests
// Assert
await AssertAllUsersHaveOneDefaultCollectionAsync(collectionRepository, resultOrganizationUsers, organization.Id);
await AssertSempahoresCreatedAsync(collectionRepository, affectedOrgUserIds, organization.Id);
await AssertSempahoresCreatedAsync(collectionRepository, affectedOrgUserIds);
await CleanupAsync(organizationRepository, userRepository, organization, resultOrganizationUsers);
}
@@ -69,7 +69,7 @@ public class UpsertDefaultCollectionsBulkTests
// Assert
await AssertAllUsersHaveOneDefaultCollectionAsync(collectionRepository, arrangedOrganizationUsers, organization.Id);
await AssertSempahoresCreatedAsync(collectionRepository, affectedOrgUserIds, organization.Id);
await AssertSempahoresCreatedAsync(collectionRepository, affectedOrgUserIds);
await CleanupAsync(organizationRepository, userRepository, organization, affectedOrgUsers);
}
@@ -99,7 +99,7 @@ public class UpsertDefaultCollectionsBulkTests
// Assert
await AssertAllUsersHaveOneDefaultCollectionAsync(collectionRepository, resultOrganizationUsers, organization.Id);
await AssertSempahoresCreatedAsync(collectionRepository, affectedOrgUserIds, organization.Id);
await AssertSempahoresCreatedAsync(collectionRepository, affectedOrgUserIds);
await CleanupAsync(organizationRepository, userRepository, organization, resultOrganizationUsers);
}
@@ -138,10 +138,11 @@ public class UpsertDefaultCollectionsBulkTests
}
private static async Task AssertSempahoresCreatedAsync(ICollectionRepository collectionRepository,
IEnumerable<Guid> organizationUserIds, Guid organizationId)
IEnumerable<Guid> organizationUserIds)
{
var semaphores = await collectionRepository.GetDefaultCollectionSemaphoresAsync(organizationId);
Assert.Equal(organizationUserIds.ToHashSet(), semaphores.ToHashSet());
var organizationUserIdHashSet = organizationUserIds.ToHashSet();
var semaphores = await collectionRepository.GetDefaultCollectionSemaphoresAsync(organizationUserIdHashSet);
Assert.Equal(organizationUserIdHashSet, semaphores);
}
private static async Task CleanupAsync(IOrganizationRepository organizationRepository,