mirror of
https://github.com/bitwarden/server.git
synced 2025-05-13 07:32:17 -05:00
Remove SignupClientAsync method from IOrganizationService and OrganizationService, along with associated unit tests
This commit is contained in:
parent
bec9c555c6
commit
2dc57cc9ef
@ -20,9 +20,6 @@ public interface IOrganizationService
|
|||||||
Task AutoAddSeatsAsync(Organization organization, int seatsToAdd);
|
Task AutoAddSeatsAsync(Organization organization, int seatsToAdd);
|
||||||
Task<string> AdjustSeatsAsync(Guid organizationId, int seatAdjustment);
|
Task<string> AdjustSeatsAsync(Guid organizationId, int seatAdjustment);
|
||||||
Task VerifyBankAsync(Guid organizationId, int amount1, int amount2);
|
Task VerifyBankAsync(Guid organizationId, int amount1, int amount2);
|
||||||
#nullable enable
|
|
||||||
Task<(Organization organization, OrganizationUser organizationUser, Collection defaultCollection)> SignupClientAsync(OrganizationSignup signup);
|
|
||||||
#nullable disable
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Create a new organization on a self-hosted instance
|
/// Create a new organization on a self-hosted instance
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -440,65 +440,6 @@ public class OrganizationService : IOrganizationService
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<(Organization organization, OrganizationUser organizationUser, Collection defaultCollection)> SignupClientAsync(OrganizationSignup signup)
|
|
||||||
{
|
|
||||||
var plan = await _pricingClient.GetPlanOrThrow(signup.Plan);
|
|
||||||
|
|
||||||
ValidatePlan(plan, signup.AdditionalSeats, "Password Manager");
|
|
||||||
|
|
||||||
var organization = new Organization
|
|
||||||
{
|
|
||||||
// Pre-generate the org id so that we can save it with the Stripe subscription.
|
|
||||||
Id = CoreHelpers.GenerateComb(),
|
|
||||||
Name = signup.Name,
|
|
||||||
BillingEmail = signup.BillingEmail,
|
|
||||||
PlanType = plan!.Type,
|
|
||||||
Seats = signup.AdditionalSeats,
|
|
||||||
MaxCollections = plan.PasswordManager.MaxCollections,
|
|
||||||
MaxStorageGb = 1,
|
|
||||||
UsePolicies = plan.HasPolicies,
|
|
||||||
UseSso = plan.HasSso,
|
|
||||||
UseGroups = plan.HasGroups,
|
|
||||||
UseEvents = plan.HasEvents,
|
|
||||||
UseDirectory = plan.HasDirectory,
|
|
||||||
UseTotp = plan.HasTotp,
|
|
||||||
Use2fa = plan.Has2fa,
|
|
||||||
UseApi = plan.HasApi,
|
|
||||||
UseResetPassword = plan.HasResetPassword,
|
|
||||||
SelfHost = plan.HasSelfHost,
|
|
||||||
UsersGetPremium = plan.UsersGetPremium,
|
|
||||||
UseCustomPermissions = plan.HasCustomPermissions,
|
|
||||||
UseScim = plan.HasScim,
|
|
||||||
Plan = plan.Name,
|
|
||||||
Gateway = GatewayType.Stripe,
|
|
||||||
ReferenceData = signup.Owner.ReferenceData,
|
|
||||||
Enabled = true,
|
|
||||||
LicenseKey = CoreHelpers.SecureRandomString(20),
|
|
||||||
PublicKey = signup.PublicKey,
|
|
||||||
PrivateKey = signup.PrivateKey,
|
|
||||||
CreationDate = DateTime.UtcNow,
|
|
||||||
RevisionDate = DateTime.UtcNow,
|
|
||||||
Status = OrganizationStatusType.Created,
|
|
||||||
UsePasswordManager = true,
|
|
||||||
// Secrets Manager not available for purchase with Consolidated Billing.
|
|
||||||
UseSecretsManager = false,
|
|
||||||
};
|
|
||||||
|
|
||||||
var returnValue = await SignUpAsync(organization, default, signup.OwnerKey, signup.CollectionName, false);
|
|
||||||
|
|
||||||
await _referenceEventService.RaiseEventAsync(
|
|
||||||
new ReferenceEvent(ReferenceEventType.Signup, organization, _currentContext)
|
|
||||||
{
|
|
||||||
PlanName = plan.Name,
|
|
||||||
PlanType = plan.Type,
|
|
||||||
Seats = returnValue.Item1.Seats,
|
|
||||||
SignupInitiationPath = signup.InitiationPath,
|
|
||||||
Storage = returnValue.Item1.MaxStorageGb,
|
|
||||||
});
|
|
||||||
|
|
||||||
return returnValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
private async Task ValidateSignUpPoliciesAsync(Guid ownerId)
|
private async Task ValidateSignUpPoliciesAsync(Guid ownerId)
|
||||||
{
|
{
|
||||||
var anySingleOrgPolicies = await _policyService.AnyPoliciesApplicableToUserAsync(ownerId, PolicyType.SingleOrg);
|
var anySingleOrgPolicies = await _policyService.AnyPoliciesApplicableToUserAsync(ownerId, PolicyType.SingleOrg);
|
||||||
|
@ -9,7 +9,6 @@ using Bit.Core.Auth.Models.Business.Tokenables;
|
|||||||
using Bit.Core.Billing.Enums;
|
using Bit.Core.Billing.Enums;
|
||||||
using Bit.Core.Billing.Pricing;
|
using Bit.Core.Billing.Pricing;
|
||||||
using Bit.Core.Context;
|
using Bit.Core.Context;
|
||||||
using Bit.Core.Entities;
|
|
||||||
using Bit.Core.Enums;
|
using Bit.Core.Enums;
|
||||||
using Bit.Core.Exceptions;
|
using Bit.Core.Exceptions;
|
||||||
using Bit.Core.Models.Business;
|
using Bit.Core.Models.Business;
|
||||||
@ -177,47 +176,6 @@ public class OrganizationServiceTests
|
|||||||
referenceEvent.Users == expectedNewUsersCount));
|
referenceEvent.Users == expectedNewUsersCount));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Theory, BitAutoData]
|
|
||||||
public async Task SignupClientAsync_Succeeds(
|
|
||||||
OrganizationSignup signup,
|
|
||||||
SutProvider<OrganizationService> sutProvider)
|
|
||||||
{
|
|
||||||
signup.Plan = PlanType.TeamsMonthly;
|
|
||||||
|
|
||||||
var plan = StaticStore.GetPlan(signup.Plan);
|
|
||||||
|
|
||||||
sutProvider.GetDependency<IPricingClient>().GetPlanOrThrow(signup.Plan).Returns(plan);
|
|
||||||
|
|
||||||
var (organization, _, _) = await sutProvider.Sut.SignupClientAsync(signup);
|
|
||||||
|
|
||||||
await sutProvider.GetDependency<IOrganizationRepository>().Received(1).CreateAsync(Arg.Is<Organization>(org =>
|
|
||||||
org.Id == organization.Id &&
|
|
||||||
org.Name == signup.Name &&
|
|
||||||
org.Plan == plan.Name &&
|
|
||||||
org.PlanType == plan.Type &&
|
|
||||||
org.UsePolicies == plan.HasPolicies &&
|
|
||||||
org.PublicKey == signup.PublicKey &&
|
|
||||||
org.PrivateKey == signup.PrivateKey &&
|
|
||||||
org.UseSecretsManager == false));
|
|
||||||
|
|
||||||
await sutProvider.GetDependency<IOrganizationApiKeyRepository>().Received(1)
|
|
||||||
.CreateAsync(Arg.Is<OrganizationApiKey>(orgApiKey =>
|
|
||||||
orgApiKey.OrganizationId == organization.Id));
|
|
||||||
|
|
||||||
await sutProvider.GetDependency<IApplicationCacheService>().Received(1)
|
|
||||||
.UpsertOrganizationAbilityAsync(organization);
|
|
||||||
|
|
||||||
await sutProvider.GetDependency<IOrganizationUserRepository>().DidNotReceiveWithAnyArgs().CreateAsync(default);
|
|
||||||
|
|
||||||
await sutProvider.GetDependency<ICollectionRepository>().Received(1)
|
|
||||||
.CreateAsync(Arg.Is<Collection>(c => c.Name == signup.CollectionName && c.OrganizationId == organization.Id), null, null);
|
|
||||||
|
|
||||||
await sutProvider.GetDependency<IReferenceEventService>().Received(1).RaiseEventAsync(Arg.Is<ReferenceEvent>(
|
|
||||||
re =>
|
|
||||||
re.Type == ReferenceEventType.Signup &&
|
|
||||||
re.PlanType == plan.Type));
|
|
||||||
}
|
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
[OrganizationInviteCustomize(InviteeUserType = OrganizationUserType.User,
|
[OrganizationInviteCustomize(InviteeUserType = OrganizationUserType.User,
|
||||||
InvitorUserType = OrganizationUserType.Owner), OrganizationCustomize, BitAutoData]
|
InvitorUserType = OrganizationUserType.Owner), OrganizationCustomize, BitAutoData]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user