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

Rename upsert -> create to reflect behavior

This commit is contained in:
Thomas Rittson
2025-12-31 13:42:32 +10:00
parent 843fd7ac9d
commit 90f2e2baeb
7 changed files with 24 additions and 26 deletions

View File

@@ -347,6 +347,6 @@ public class ConfirmOrganizationUserCommand : IConfirmOrganizationUserCommand
return;
}
await _collectionRepository.UpsertDefaultCollectionsAsync(organizationId, eligibleOrganizationUserIds, defaultUserCollectionName);
await _collectionRepository.CreateDefaultCollectionsAsync(organizationId, eligibleOrganizationUserIds, defaultUserCollectionName);
}
}

View File

@@ -64,23 +64,21 @@ public interface ICollectionRepository : IRepository<Collection, Guid>
IEnumerable<CollectionAccessSelection> users, IEnumerable<CollectionAccessSelection> groups);
/// <summary>
/// Creates default user collections for the specified organization users if they do not already have one.
/// Uses the stored procedure approach with semaphore-based duplicate prevention.
/// Creates default user collections for the specified organization users.
/// Throws an exception if any user already has a default collection for the organization.
/// </summary>
/// <param name="organizationId">The Organization ID.</param>
/// <param name="organizationUserIds">The Organization User IDs to create default collections for.</param>
/// <param name="defaultCollectionName">The encrypted string to use as the default collection name.</param>
/// <returns></returns>
Task UpsertDefaultCollectionsAsync(Guid organizationId, IEnumerable<Guid> organizationUserIds, string defaultCollectionName);
Task CreateDefaultCollectionsAsync(Guid organizationId, IEnumerable<Guid> organizationUserIds, string defaultCollectionName);
/// <summary>
/// Creates default user collections for the specified organization users using bulk insert operations.
/// Inserts semaphore entries before collections to prevent duplicates.
/// Gracefully skips users who already have a default collection for the organization.
/// </summary>
/// <param name="organizationId">The Organization ID.</param>
/// <param name="organizationUserIds">The Organization User IDs to create default collections for.</param>
/// <param name="defaultCollectionName">The encrypted string to use as the default collection name.</param>
/// <returns></returns>
Task UpsertDefaultCollectionsBulkAsync(Guid organizationId, IEnumerable<Guid> organizationUserIds, string defaultCollectionName);
/// <summary>

View File

@@ -360,7 +360,7 @@ public class CollectionRepository : Repository<Collection, Guid>, ICollectionRep
}
}
public async Task UpsertDefaultCollectionsAsync(Guid organizationId, IEnumerable<Guid> organizationUserIds, string defaultCollectionName)
public async Task CreateDefaultCollectionsAsync(Guid organizationId, IEnumerable<Guid> organizationUserIds, string defaultCollectionName)
{
organizationUserIds = organizationUserIds.ToList();
if (!organizationUserIds.Any())

View File

@@ -795,7 +795,7 @@ public class CollectionRepository : Repository<Core.Entities.Collection, Collect
// SaveChangesAsync is expected to be called outside this method
}
public async Task UpsertDefaultCollectionsAsync(Guid organizationId, IEnumerable<Guid> organizationUserIds, string defaultCollectionName)
public async Task CreateDefaultCollectionsAsync(Guid organizationId, IEnumerable<Guid> organizationUserIds, string defaultCollectionName)
{
organizationUserIds = organizationUserIds.ToList();
if (!organizationUserIds.Any())
@@ -836,7 +836,7 @@ public class CollectionRepository : Repository<Core.Entities.Collection, Collect
public async Task UpsertDefaultCollectionsBulkAsync(Guid organizationId, IEnumerable<Guid> organizationUserIds, string defaultCollectionName)
{
// EF uses the same bulk copy approach as the main method
await UpsertDefaultCollectionsAsync(organizationId, organizationUserIds, defaultCollectionName);
await CreateDefaultCollectionsAsync(organizationId, organizationUserIds, defaultCollectionName);
}
public async Task<IEnumerable<Guid>> GetDefaultCollectionSemaphoresAsync(Guid organizationId)

View File

@@ -525,7 +525,7 @@ public class ConfirmOrganizationUserCommandTests
await sutProvider.GetDependency<ICollectionRepository>()
.DidNotReceive()
.UpsertDefaultCollectionsAsync(Arg.Any<Guid>(), Arg.Any<IEnumerable<Guid>>(), Arg.Any<string>());
.CreateDefaultCollectionsAsync(Arg.Any<Guid>(), Arg.Any<IEnumerable<Guid>>(), Arg.Any<string>());
}
[Theory, BitAutoData]
@@ -560,7 +560,7 @@ public class ConfirmOrganizationUserCommandTests
await sutProvider.GetDependency<ICollectionRepository>()
.DidNotReceive()
.UpsertDefaultCollectionsAsync(Arg.Any<Guid>(), Arg.Any<IEnumerable<Guid>>(), Arg.Any<string>());
.CreateDefaultCollectionsAsync(Arg.Any<Guid>(), Arg.Any<IEnumerable<Guid>>(), Arg.Any<string>());
}
[Theory, BitAutoData]

View File

@@ -10,10 +10,10 @@ using Xunit;
namespace Bit.Infrastructure.IntegrationTest.AdminConsole.Repositories.CollectionRepository;
public class CollectionRepositoryUpsertDefaultCollectionsTests
public class CreateDefaultCollectionsTests
{
/// <summary>
/// Test that UpsertDefaultCollectionsAsync successfully creates default collections for new users
/// Test that CreateDefaultCollectionsAsync successfully creates default collections for new users
/// </summary>
[DatabaseTheory, DatabaseData]
public async Task UpsertDefaultCollectionsAsync_CreatesDefaultCollections_Success(
@@ -62,7 +62,7 @@ public class CollectionRepositoryUpsertDefaultCollectionsTests
});
// Act
await collectionRepository.UpsertDefaultCollectionsAsync(
await collectionRepository.CreateDefaultCollectionsAsync(
organization.Id,
new[] { orgUser1.Id, orgUser2.Id },
"My Items");
@@ -77,7 +77,7 @@ public class CollectionRepositoryUpsertDefaultCollectionsTests
}
/// <summary>
/// Test that calling UpsertDefaultCollectionsAsync multiple times does NOT create duplicates
/// Test that calling CreateDefaultCollectionsAsync multiple times does NOT create duplicates
/// </summary>
[DatabaseTheory, DatabaseData]
public async Task UpsertDefaultCollectionsAsync_CalledMultipleTimes_DoesNotCreateDuplicates(
@@ -111,14 +111,14 @@ public class CollectionRepositoryUpsertDefaultCollectionsTests
});
// Act - Call twice
await collectionRepository.UpsertDefaultCollectionsAsync(
await collectionRepository.CreateDefaultCollectionsAsync(
organization.Id,
new[] { orgUser.Id },
"My Items");
// Second call should not create duplicate
await Assert.ThrowsAnyAsync<Exception>(() =>
collectionRepository.UpsertDefaultCollectionsAsync(
collectionRepository.CreateDefaultCollectionsAsync(
organization.Id,
new[] { orgUser.Id },
"My Items"));
@@ -221,7 +221,7 @@ public class CollectionRepositoryUpsertDefaultCollectionsTests
Status = OrganizationUserStatusType.Confirmed,
});
await collectionRepository.UpsertDefaultCollectionsAsync(
await collectionRepository.CreateDefaultCollectionsAsync(
organization.Id,
new[] { orgUser.Id },
"My Items");
@@ -276,7 +276,7 @@ public class CollectionRepositoryUpsertDefaultCollectionsTests
Status = OrganizationUserStatusType.Confirmed,
});
await collectionRepository.UpsertDefaultCollectionsAsync(
await collectionRepository.CreateDefaultCollectionsAsync(
organization.Id,
new[] { orgUser.Id },
"My Items");
@@ -296,7 +296,7 @@ public class CollectionRepositoryUpsertDefaultCollectionsTests
}
/// <summary>
/// Test that UpsertDefaultCollectionsAsync with empty user list does nothing
/// Test that CreateDefaultCollectionsAsync with empty user list does nothing
/// </summary>
[DatabaseTheory, DatabaseData]
public async Task UpsertDefaultCollectionsAsync_WithEmptyList_DoesNothing(
@@ -313,7 +313,7 @@ public class CollectionRepositoryUpsertDefaultCollectionsTests
});
// Act
await collectionRepository.UpsertDefaultCollectionsAsync(
await collectionRepository.CreateDefaultCollectionsAsync(
organization.Id,
Array.Empty<Guid>(),
"My Items");
@@ -324,7 +324,7 @@ public class CollectionRepositoryUpsertDefaultCollectionsTests
}
/// <summary>
/// Test that UpsertDefaultCollectionsAsync creates CollectionUser entries with correct permissions
/// Test that CreateDefaultCollectionsAsync creates CollectionUser entries with correct permissions
/// </summary>
[DatabaseTheory, DatabaseData]
public async Task UpsertDefaultCollectionsAsync_CreatesCollectionUsersWithCorrectPermissions(
@@ -358,7 +358,7 @@ public class CollectionRepositoryUpsertDefaultCollectionsTests
});
// Act
await collectionRepository.UpsertDefaultCollectionsAsync(
await collectionRepository.CreateDefaultCollectionsAsync(
organization.Id,
new[] { orgUser.Id },
"My Items");

View File

@@ -26,7 +26,7 @@ public class DefaultCollectionSemaphoreTests
var organization = await organizationRepository.CreateTestOrganizationAsync();
var orgUser = await organizationUserRepository.CreateTestOrganizationUserAsync(organization, user);
await collectionRepository.UpsertDefaultCollectionsAsync(
await collectionRepository.CreateDefaultCollectionsAsync(
organization.Id,
[orgUser.Id],
"My Items");
@@ -59,7 +59,7 @@ public class DefaultCollectionSemaphoreTests
var organization = await organizationRepository.CreateTestOrganizationAsync();
var orgUser = await organizationUserRepository.CreateTestOrganizationUserAsync(organization, user);
await collectionRepository.UpsertDefaultCollectionsAsync(
await collectionRepository.CreateDefaultCollectionsAsync(
organization.Id,
[orgUser.Id],
"My Items");