mirror of
https://github.com/bitwarden/server.git
synced 2025-04-05 05:00:19 -05:00
Renames for organization.
This commit is contained in:
parent
f8b172ef32
commit
65996ae0a9
@ -2,9 +2,9 @@
|
||||
|
||||
namespace Bit.Core.AdminConsole.OrganizationFeatures.OrganizationUsers.InviteUsers.Validation.GlobalSettings;
|
||||
|
||||
public interface IEnvironmentValidator : IValidator<EnvironmentRequest>;
|
||||
public interface IInviteUsersEnvironmentValidator : IValidator<EnvironmentRequest>;
|
||||
|
||||
public class EnvironmentValidator : IEnvironmentValidator
|
||||
public class InviteUsersEnvironmentValidator : IInviteUsersEnvironmentValidator
|
||||
{
|
||||
public Task<ValidationResult<EnvironmentRequest>> ValidateAsync(EnvironmentRequest value) =>
|
||||
Task.FromResult<ValidationResult<EnvironmentRequest>>(
|
@ -12,14 +12,14 @@ public interface IInviteUsersValidator : IValidator<InviteUserOrganizationValida
|
||||
|
||||
public class InviteUsersValidator(
|
||||
IOrganizationRepository organizationRepository,
|
||||
IPasswordManagerInviteUserValidator passwordManagerInviteUserValidator,
|
||||
IInviteUsersPasswordManagerValidator inviteUsersPasswordManagerValidator,
|
||||
IUpdateSecretsManagerSubscriptionCommand secretsManagerSubscriptionCommand) : IInviteUsersValidator
|
||||
{
|
||||
public async Task<ValidationResult<InviteUserOrganizationValidationRequest>> ValidateAsync(InviteUserOrganizationValidationRequest request)
|
||||
{
|
||||
var subscriptionUpdate = new PasswordManagerSubscriptionUpdate(request);
|
||||
|
||||
var passwordManagerValidationResult = await passwordManagerInviteUserValidator.ValidateAsync(subscriptionUpdate);
|
||||
var passwordManagerValidationResult = await inviteUsersPasswordManagerValidator.ValidateAsync(subscriptionUpdate);
|
||||
|
||||
if (passwordManagerValidationResult is Invalid<PasswordManagerSubscriptionUpdate> invalidSubscriptionUpdate)
|
||||
{
|
||||
|
@ -3,9 +3,9 @@ using Bit.Core.AdminConsole.Shared.Validation;
|
||||
|
||||
namespace Bit.Core.AdminConsole.OrganizationFeatures.OrganizationUsers.InviteUsers.Validation.Organization;
|
||||
|
||||
public interface IInviteUserOrganizationValidator : IValidator<InviteOrganization>;
|
||||
public interface IInviteUsersOrganizationValidator : IValidator<InviteOrganization>;
|
||||
|
||||
public class InviteUserOrganizationValidator : IInviteUserOrganizationValidator
|
||||
public class InviteUsersOrganizationValidator : IInviteUsersOrganizationValidator
|
||||
{
|
||||
public Task<ValidationResult<InviteOrganization>> ValidateAsync(InviteOrganization inviteOrganization)
|
||||
{
|
@ -11,16 +11,16 @@ using Bit.Core.Settings;
|
||||
|
||||
namespace Bit.Core.AdminConsole.OrganizationFeatures.OrganizationUsers.InviteUsers.Validation.PasswordManager;
|
||||
|
||||
public interface IPasswordManagerInviteUserValidator : IValidator<PasswordManagerSubscriptionUpdate>;
|
||||
public interface IInviteUsersPasswordManagerValidator : IValidator<PasswordManagerSubscriptionUpdate>;
|
||||
|
||||
public class PasswordManagerInviteUserValidator(
|
||||
public class InviteUsersPasswordManagerValidator(
|
||||
IGlobalSettings globalSettings,
|
||||
IEnvironmentValidator environmentValidator,
|
||||
IInviteUserOrganizationValidator inviteUserOrganizationValidator,
|
||||
IInviteUsersEnvironmentValidator inviteUsersEnvironmentValidator,
|
||||
IInviteUsersOrganizationValidator inviteUsersOrganizationValidator,
|
||||
IProviderRepository providerRepository,
|
||||
IPaymentService paymentService,
|
||||
IOrganizationRepository organizationRepository
|
||||
) : IPasswordManagerInviteUserValidator
|
||||
) : IInviteUsersPasswordManagerValidator
|
||||
{
|
||||
/// <summary>
|
||||
/// This is for validating if the organization can add additional users.
|
||||
@ -34,13 +34,17 @@ public class PasswordManagerInviteUserValidator(
|
||||
return new Valid<PasswordManagerSubscriptionUpdate>(subscriptionUpdate);
|
||||
}
|
||||
|
||||
if (subscriptionUpdate.PasswordManagerPlan.BaseSeats + subscriptionUpdate.SeatsRequiredToAdd <= 0)
|
||||
{
|
||||
return new Invalid<PasswordManagerSubscriptionUpdate>(new PasswordManagerMustHaveSeatsError(subscriptionUpdate));
|
||||
}
|
||||
|
||||
if (subscriptionUpdate.NewUsersToAdd == 0)
|
||||
{
|
||||
return new Valid<PasswordManagerSubscriptionUpdate>(subscriptionUpdate);
|
||||
}
|
||||
|
||||
if (subscriptionUpdate.UpdatedSeatTotal is not null && subscriptionUpdate.MaxAutoScaleSeats is not null &&
|
||||
subscriptionUpdate.UpdatedSeatTotal > subscriptionUpdate.MaxAutoScaleSeats)
|
||||
if (subscriptionUpdate.MaxSeatsReached)
|
||||
{
|
||||
return new Invalid<PasswordManagerSubscriptionUpdate>(
|
||||
new PasswordManagerSeatLimitHasBeenReachedError(subscriptionUpdate));
|
||||
@ -53,7 +57,7 @@ public class PasswordManagerInviteUserValidator(
|
||||
}
|
||||
|
||||
// Apparently MaxAdditionalSeats is never set. Can probably be removed.
|
||||
if (subscriptionUpdate.NewUsersToAdd > subscriptionUpdate.PasswordManagerPlan.MaxAdditionalSeats)
|
||||
if (subscriptionUpdate.UpdatedSeatTotal - subscriptionUpdate.PasswordManagerPlan.BaseSeats > subscriptionUpdate.PasswordManagerPlan.MaxAdditionalSeats)
|
||||
{
|
||||
return new Invalid<PasswordManagerSubscriptionUpdate>(
|
||||
new PasswordManagerPlanOnlyAllowsMaxAdditionalSeatsError(subscriptionUpdate));
|
||||
@ -69,16 +73,17 @@ public class PasswordManagerInviteUserValidator(
|
||||
case Valid<PasswordManagerSubscriptionUpdate> valid
|
||||
when valid.Value.SeatsRequiredToAdd is 0:
|
||||
return new Valid<PasswordManagerSubscriptionUpdate>(request);
|
||||
|
||||
case Invalid<PasswordManagerSubscriptionUpdate> invalid:
|
||||
return invalid;
|
||||
}
|
||||
|
||||
if (await environmentValidator.ValidateAsync(new EnvironmentRequest(globalSettings, request)) is Invalid<EnvironmentRequest> invalidEnvironment)
|
||||
if (await inviteUsersEnvironmentValidator.ValidateAsync(new EnvironmentRequest(globalSettings, request)) is Invalid<EnvironmentRequest> invalidEnvironment)
|
||||
{
|
||||
return invalidEnvironment.Map(request);
|
||||
}
|
||||
|
||||
var organizationValidationResult = await inviteUserOrganizationValidator.ValidateAsync(request.InviteOrganization);
|
||||
var organizationValidationResult = await inviteUsersOrganizationValidator.ValidateAsync(request.InviteOrganization);
|
||||
|
||||
if (organizationValidationResult is Invalid<InviteOrganization> organizationValidation)
|
||||
{
|
@ -181,9 +181,9 @@ public static class OrganizationServiceCollectionExtensions
|
||||
services.AddScoped<ISendOrganizationInvitesCommand, SendOrganizationInvitesCommand>();
|
||||
|
||||
services.AddScoped<IInviteUsersValidator, InviteUsersValidator>();
|
||||
services.AddScoped<IInviteUserOrganizationValidator, InviteUserOrganizationValidator>();
|
||||
services.AddScoped<IPasswordManagerInviteUserValidator, PasswordManagerInviteUserValidator>();
|
||||
services.AddScoped<IEnvironmentValidator, EnvironmentValidator>();
|
||||
services.AddScoped<IInviteUsersOrganizationValidator, InviteUsersOrganizationValidator>();
|
||||
services.AddScoped<IInviteUsersPasswordManagerValidator, InviteUsersPasswordManagerValidator>();
|
||||
services.AddScoped<IInviteUsersEnvironmentValidator, InviteUsersEnvironmentValidator>();
|
||||
}
|
||||
|
||||
// TODO: move to OrganizationSubscriptionServiceCollectionExtensions when OrganizationUser methods are moved out of
|
||||
|
@ -14,7 +14,7 @@ public class InviteUserOrganizationValidationTests
|
||||
{
|
||||
[Theory]
|
||||
[BitAutoData]
|
||||
public async Task Validate_WhenOrganizationIsFreeTier_ShouldReturnValidResponse(Organization organization, SutProvider<InviteUserOrganizationValidator> sutProvider)
|
||||
public async Task Validate_WhenOrganizationIsFreeTier_ShouldReturnValidResponse(Organization organization, SutProvider<InviteUsersOrganizationValidator> sutProvider)
|
||||
{
|
||||
var inviteOrganization = new InviteOrganization(organization, new FreePlan());
|
||||
|
||||
@ -26,7 +26,7 @@ public class InviteUserOrganizationValidationTests
|
||||
[Theory]
|
||||
[BitAutoData]
|
||||
public async Task Validate_WhenOrganizationDoesNotHavePaymentMethod_ShouldReturnInvalidResponseWithPaymentMethodMessage(
|
||||
Organization organization, SutProvider<InviteUserOrganizationValidator> sutProvider)
|
||||
Organization organization, SutProvider<InviteUsersOrganizationValidator> sutProvider)
|
||||
{
|
||||
organization.GatewayCustomerId = string.Empty;
|
||||
organization.Seats = 3;
|
||||
@ -42,7 +42,7 @@ public class InviteUserOrganizationValidationTests
|
||||
[Theory]
|
||||
[BitAutoData]
|
||||
public async Task Validate_WhenOrganizationDoesNotHaveSubscription_ShouldReturnInvalidResponseWithSubscriptionMessage(
|
||||
Organization organization, SutProvider<InviteUserOrganizationValidator> sutProvider)
|
||||
Organization organization, SutProvider<InviteUsersOrganizationValidator> sutProvider)
|
||||
{
|
||||
organization.GatewaySubscriptionId = string.Empty;
|
||||
organization.Seats = 3;
|
||||
|
@ -12,12 +12,12 @@ namespace Bit.Core.Test.AdminConsole.OrganizationFeatures.OrganizationUsers.Invi
|
||||
|
||||
|
||||
[SutProviderCustomize]
|
||||
public class PasswordManagerInviteUserValidatorTests
|
||||
public class InviteUsersPasswordManagerValidatorTests
|
||||
{
|
||||
[Theory]
|
||||
[BitAutoData]
|
||||
public async Task Validate_OrganizationDoesNotHaveSeatsLimit_ShouldReturnValidResult(Organization organization,
|
||||
SutProvider<PasswordManagerInviteUserValidator> sutProvider)
|
||||
SutProvider<InviteUsersPasswordManagerValidator> sutProvider)
|
||||
{
|
||||
organization.Seats = null;
|
||||
|
||||
@ -33,7 +33,7 @@ public class PasswordManagerInviteUserValidatorTests
|
||||
[Theory]
|
||||
[BitAutoData]
|
||||
public async Task Validate_NumberOfSeatsToAddMatchesSeatsAvailable_ShouldReturnValidResult(Organization organization,
|
||||
SutProvider<PasswordManagerInviteUserValidator> sutProvider)
|
||||
SutProvider<InviteUsersPasswordManagerValidator> sutProvider)
|
||||
{
|
||||
organization.Seats = 8;
|
||||
organization.PlanType = PlanType.EnterpriseAnnually;
|
||||
@ -52,7 +52,7 @@ public class PasswordManagerInviteUserValidatorTests
|
||||
[Theory]
|
||||
[BitAutoData]
|
||||
public async Task Validate_NumberOfSeatsToAddIsGreaterThanMaxSeatsAllowed_ShouldBeInvalidWithSeatLimitMessage(Organization organization,
|
||||
SutProvider<PasswordManagerInviteUserValidator> sutProvider)
|
||||
SutProvider<InviteUsersPasswordManagerValidator> sutProvider)
|
||||
{
|
||||
organization.Seats = 4;
|
||||
organization.MaxAutoscaleSeats = 4;
|
||||
@ -73,7 +73,7 @@ public class PasswordManagerInviteUserValidatorTests
|
||||
[Theory]
|
||||
[BitAutoData]
|
||||
public async Task Validate_GivenThePlanDoesNotAllowAdditionalSeats_ShouldBeInvalidMessageOfPlanNotAllowingSeats(Organization organization,
|
||||
SutProvider<PasswordManagerInviteUserValidator> sutProvider)
|
||||
SutProvider<InviteUsersPasswordManagerValidator> sutProvider)
|
||||
{
|
||||
organization.Seats = 8;
|
||||
organization.MaxAutoscaleSeats = 9;
|
||||
|
Loading…
x
Reference in New Issue
Block a user