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