1
0
mirror of https://github.com/bitwarden/server.git synced 2025-07-06 18:42:49 -05:00

Added bulk procedure for saving users, collections and groups from inviting. Added test to validate Ef and Sproc

This commit is contained in:
jrmccannon
2025-02-17 16:32:23 -06:00
parent fcaa449f83
commit 926e786f82
15 changed files with 416 additions and 29 deletions

View File

@ -1,7 +1,11 @@
using Bit.Core.AdminConsole.Entities;
using Bit.Core.AdminConsole.OrganizationFeatures.OrganizationUsers.InviteUsers.Models;
using Bit.Core.AdminConsole.Repositories;
using Bit.Core.Entities;
using Bit.Core.Enums;
using Bit.Core.Models.Data;
using Bit.Core.Repositories;
using Bit.Core.Utilities;
using Xunit;
namespace Bit.Infrastructure.IntegrationTest.Repositories;
@ -354,4 +358,73 @@ public class OrganizationUserRepositoryTests
Assert.Single(responseModel);
Assert.Equal(orgUser1.Id, responseModel.Single().Id);
}
[DatabaseTheory, DatabaseData]
public async Task CreateManyAsync_WithCollectionAndGroup_SaveSuccessfully(
IOrganizationUserRepository organizationUserRepository,
IOrganizationRepository organizationRepository,
ICollectionRepository collectionRepository,
IGroupRepository groupRepository)
{
var requestTime = DateTime.UtcNow;
var organization = await organizationRepository.CreateAsync(new Organization
{
Name = "Test Org",
BillingEmail = "billing@test.com", // TODO: EF does not enfore this being NOT NULL
Plan = "Test", // TODO: EF does not enforce this being NOT NULl,
CreationDate = requestTime
});
var collection = await collectionRepository.CreateAsync(new Collection
{
Id = CoreHelpers.GenerateComb(),
OrganizationId = organization.Id,
Name = "Test Collection",
ExternalId = "external-collection-1",
CreationDate = requestTime,
RevisionDate = requestTime
});
var group = await groupRepository.CreateAsync(new Group
{
Id = CoreHelpers.GenerateComb(),
OrganizationId = organization.Id,
Name = "Test Group",
ExternalId = "external-group-1"
});
var orgUserCollection = new List<CreateOrganizationUser>
{
new CreateOrganizationUser
{
User = new OrganizationUser
{
Id = CoreHelpers.GenerateComb(),
OrganizationId = organization.Id,
Email = "test-user@test.com",
Status = OrganizationUserStatusType.Invited,
Type = OrganizationUserType.Owner,
ExternalId = "externalid-1",
Permissions = CoreHelpers.ClassToJsonData(new Permissions()),
AccessSecretsManager = false
},
Collections =
[
new CollectionAccessSelection
{
Id = collection.Id,
ReadOnly = true,
HidePasswords = false,
Manage = false
}
],
Groups = [group.Id]
}
};
await organizationUserRepository.CreateManyAsync(orgUserCollection);
var orgUser = await organizationUserRepository.GetDetailsByIdAsync(orgUserCollection.First().User.Id);
}
}