mirror of
https://github.com/bitwarden/server
synced 2026-02-22 04:13:43 +00:00
59 lines
1.9 KiB
C#
59 lines
1.9 KiB
C#
using Bit.Core.AdminConsole.Entities;
|
|
using Bit.Core.Billing.Enums;
|
|
using Bit.Core.Entities;
|
|
using Bit.Core.Enums;
|
|
using Bit.Core.Utilities;
|
|
|
|
namespace Bit.Seeder.Factories;
|
|
|
|
internal static class OrganizationSeeder
|
|
{
|
|
internal static Organization Create(string name, string domain, int seats, string? publicKey = null, string? privateKey = null, PlanType planType = PlanType.EnterpriseAnnually)
|
|
{
|
|
var org = new Organization
|
|
{
|
|
Id = CoreHelpers.GenerateComb(),
|
|
Identifier = domain,
|
|
Name = name,
|
|
BillingEmail = $"billing@{domain}",
|
|
Seats = seats,
|
|
Status = OrganizationStatusType.Created,
|
|
PublicKey = publicKey,
|
|
PrivateKey = privateKey
|
|
};
|
|
|
|
PlanFeatures.Apply(org, planType);
|
|
|
|
return org;
|
|
}
|
|
}
|
|
|
|
internal static class OrganizationExtensions
|
|
{
|
|
/// <summary>
|
|
/// Creates an OrganizationUser with a dynamically provided encrypted org key.
|
|
/// The encryptedOrgKey should be generated using sdkService.GenerateUserOrganizationKey().
|
|
/// </summary>
|
|
internal static OrganizationUser CreateOrganizationUserWithKey(
|
|
this Organization organization,
|
|
User user,
|
|
OrganizationUserType type,
|
|
OrganizationUserStatusType status,
|
|
string? encryptedOrgKey)
|
|
{
|
|
var shouldLinkUserId = status != OrganizationUserStatusType.Invited;
|
|
var shouldIncludeKey = status == OrganizationUserStatusType.Confirmed || status == OrganizationUserStatusType.Revoked;
|
|
|
|
return new OrganizationUser
|
|
{
|
|
Id = CoreHelpers.GenerateComb(),
|
|
OrganizationId = organization.Id,
|
|
UserId = shouldLinkUserId ? user.Id : null,
|
|
Email = shouldLinkUserId ? null : user.Email,
|
|
Key = shouldIncludeKey ? encryptedOrgKey : null,
|
|
Type = type,
|
|
Status = status
|
|
};
|
|
}
|
|
}
|