From 65996ae0a925c88f660ac2a5adbc1cef072d23c9 Mon Sep 17 00:00:00 2001 From: jrmccannon Date: Fri, 28 Mar 2025 12:26:06 -0500 Subject: [PATCH] Renames for organization. --- ....cs => InviteUsersEnvironmentValidator.cs} | 4 +-- .../InviteOrganizationUserValidator.cs | 4 +-- ...cs => InviteUsersOrganizationValidator.cs} | 4 +-- ...=> InviteUsersPasswordManagerValidator.cs} | 25 +++++++++++-------- ...OrganizationServiceCollectionExtensions.cs | 6 ++--- .../InviteUserOrganizationValidationTests.cs | 6 ++--- ...PasswordManagerInviteUserValidatorTests.cs | 10 ++++---- 7 files changed, 32 insertions(+), 27 deletions(-) rename src/Core/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/Validation/GlobalSettings/{EnvironmentValidator.cs => InviteUsersEnvironmentValidator.cs} (77%) rename src/Core/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/Validation/Organization/{InviteUserOrganizationValidator.cs => InviteUsersOrganizationValidator.cs} (88%) rename src/Core/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/Validation/PasswordManager/{PasswordManagerInviteUserValidator.cs => InviteUsersPasswordManagerValidator.cs} (79%) diff --git a/src/Core/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/Validation/GlobalSettings/EnvironmentValidator.cs b/src/Core/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/Validation/GlobalSettings/InviteUsersEnvironmentValidator.cs similarity index 77% rename from src/Core/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/Validation/GlobalSettings/EnvironmentValidator.cs rename to src/Core/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/Validation/GlobalSettings/InviteUsersEnvironmentValidator.cs index 6f2b672806..fd0441753a 100644 --- a/src/Core/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/Validation/GlobalSettings/EnvironmentValidator.cs +++ b/src/Core/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/Validation/GlobalSettings/InviteUsersEnvironmentValidator.cs @@ -2,9 +2,9 @@ namespace Bit.Core.AdminConsole.OrganizationFeatures.OrganizationUsers.InviteUsers.Validation.GlobalSettings; -public interface IEnvironmentValidator : IValidator; +public interface IInviteUsersEnvironmentValidator : IValidator; -public class EnvironmentValidator : IEnvironmentValidator +public class InviteUsersEnvironmentValidator : IInviteUsersEnvironmentValidator { public Task> ValidateAsync(EnvironmentRequest value) => Task.FromResult>( diff --git a/src/Core/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/Validation/InviteOrganizationUserValidator.cs b/src/Core/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/Validation/InviteOrganizationUserValidator.cs index 455c8acca1..3adae0a8f0 100644 --- a/src/Core/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/Validation/InviteOrganizationUserValidator.cs +++ b/src/Core/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/Validation/InviteOrganizationUserValidator.cs @@ -12,14 +12,14 @@ public interface IInviteUsersValidator : IValidator> ValidateAsync(InviteUserOrganizationValidationRequest request) { var subscriptionUpdate = new PasswordManagerSubscriptionUpdate(request); - var passwordManagerValidationResult = await passwordManagerInviteUserValidator.ValidateAsync(subscriptionUpdate); + var passwordManagerValidationResult = await inviteUsersPasswordManagerValidator.ValidateAsync(subscriptionUpdate); if (passwordManagerValidationResult is Invalid invalidSubscriptionUpdate) { diff --git a/src/Core/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/Validation/Organization/InviteUserOrganizationValidator.cs b/src/Core/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/Validation/Organization/InviteUsersOrganizationValidator.cs similarity index 88% rename from src/Core/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/Validation/Organization/InviteUserOrganizationValidator.cs rename to src/Core/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/Validation/Organization/InviteUsersOrganizationValidator.cs index 14b75bb7ee..9e2ca8d9a6 100644 --- a/src/Core/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/Validation/Organization/InviteUserOrganizationValidator.cs +++ b/src/Core/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/Validation/Organization/InviteUsersOrganizationValidator.cs @@ -3,9 +3,9 @@ using Bit.Core.AdminConsole.Shared.Validation; namespace Bit.Core.AdminConsole.OrganizationFeatures.OrganizationUsers.InviteUsers.Validation.Organization; -public interface IInviteUserOrganizationValidator : IValidator; +public interface IInviteUsersOrganizationValidator : IValidator; -public class InviteUserOrganizationValidator : IInviteUserOrganizationValidator +public class InviteUsersOrganizationValidator : IInviteUsersOrganizationValidator { public Task> ValidateAsync(InviteOrganization inviteOrganization) { diff --git a/src/Core/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/Validation/PasswordManager/PasswordManagerInviteUserValidator.cs b/src/Core/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/Validation/PasswordManager/InviteUsersPasswordManagerValidator.cs similarity index 79% rename from src/Core/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/Validation/PasswordManager/PasswordManagerInviteUserValidator.cs rename to src/Core/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/Validation/PasswordManager/InviteUsersPasswordManagerValidator.cs index 7101c6671d..189645e594 100644 --- a/src/Core/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/Validation/PasswordManager/PasswordManagerInviteUserValidator.cs +++ b/src/Core/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/Validation/PasswordManager/InviteUsersPasswordManagerValidator.cs @@ -11,16 +11,16 @@ using Bit.Core.Settings; namespace Bit.Core.AdminConsole.OrganizationFeatures.OrganizationUsers.InviteUsers.Validation.PasswordManager; -public interface IPasswordManagerInviteUserValidator : IValidator; +public interface IInviteUsersPasswordManagerValidator : IValidator; -public class PasswordManagerInviteUserValidator( +public class InviteUsersPasswordManagerValidator( IGlobalSettings globalSettings, - IEnvironmentValidator environmentValidator, - IInviteUserOrganizationValidator inviteUserOrganizationValidator, + IInviteUsersEnvironmentValidator inviteUsersEnvironmentValidator, + IInviteUsersOrganizationValidator inviteUsersOrganizationValidator, IProviderRepository providerRepository, IPaymentService paymentService, IOrganizationRepository organizationRepository - ) : IPasswordManagerInviteUserValidator + ) : IInviteUsersPasswordManagerValidator { /// /// This is for validating if the organization can add additional users. @@ -34,13 +34,17 @@ public class PasswordManagerInviteUserValidator( return new Valid(subscriptionUpdate); } + if (subscriptionUpdate.PasswordManagerPlan.BaseSeats + subscriptionUpdate.SeatsRequiredToAdd <= 0) + { + return new Invalid(new PasswordManagerMustHaveSeatsError(subscriptionUpdate)); + } + if (subscriptionUpdate.NewUsersToAdd == 0) { return new Valid(subscriptionUpdate); } - if (subscriptionUpdate.UpdatedSeatTotal is not null && subscriptionUpdate.MaxAutoScaleSeats is not null && - subscriptionUpdate.UpdatedSeatTotal > subscriptionUpdate.MaxAutoScaleSeats) + if (subscriptionUpdate.MaxSeatsReached) { return new Invalid( 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( new PasswordManagerPlanOnlyAllowsMaxAdditionalSeatsError(subscriptionUpdate)); @@ -69,16 +73,17 @@ public class PasswordManagerInviteUserValidator( case Valid valid when valid.Value.SeatsRequiredToAdd is 0: return new Valid(request); + case Invalid invalid: return invalid; } - if (await environmentValidator.ValidateAsync(new EnvironmentRequest(globalSettings, request)) is Invalid invalidEnvironment) + if (await inviteUsersEnvironmentValidator.ValidateAsync(new EnvironmentRequest(globalSettings, request)) is Invalid invalidEnvironment) { return invalidEnvironment.Map(request); } - var organizationValidationResult = await inviteUserOrganizationValidator.ValidateAsync(request.InviteOrganization); + var organizationValidationResult = await inviteUsersOrganizationValidator.ValidateAsync(request.InviteOrganization); if (organizationValidationResult is Invalid organizationValidation) { diff --git a/src/Core/OrganizationFeatures/OrganizationServiceCollectionExtensions.cs b/src/Core/OrganizationFeatures/OrganizationServiceCollectionExtensions.cs index 4fe8ee9237..e579bcfa63 100644 --- a/src/Core/OrganizationFeatures/OrganizationServiceCollectionExtensions.cs +++ b/src/Core/OrganizationFeatures/OrganizationServiceCollectionExtensions.cs @@ -181,9 +181,9 @@ public static class OrganizationServiceCollectionExtensions services.AddScoped(); services.AddScoped(); - services.AddScoped(); - services.AddScoped(); - services.AddScoped(); + services.AddScoped(); + services.AddScoped(); + services.AddScoped(); } // TODO: move to OrganizationSubscriptionServiceCollectionExtensions when OrganizationUser methods are moved out of diff --git a/test/Core.Test/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/Validation/InviteUserOrganizationValidationTests.cs b/test/Core.Test/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/Validation/InviteUserOrganizationValidationTests.cs index b8d9d65e46..508b9f3cb0 100644 --- a/test/Core.Test/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/Validation/InviteUserOrganizationValidationTests.cs +++ b/test/Core.Test/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/Validation/InviteUserOrganizationValidationTests.cs @@ -14,7 +14,7 @@ public class InviteUserOrganizationValidationTests { [Theory] [BitAutoData] - public async Task Validate_WhenOrganizationIsFreeTier_ShouldReturnValidResponse(Organization organization, SutProvider sutProvider) + public async Task Validate_WhenOrganizationIsFreeTier_ShouldReturnValidResponse(Organization organization, SutProvider 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 sutProvider) + Organization organization, SutProvider 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 sutProvider) + Organization organization, SutProvider sutProvider) { organization.GatewaySubscriptionId = string.Empty; organization.Seats = 3; diff --git a/test/Core.Test/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/Validation/PasswordManagerInviteUserValidatorTests.cs b/test/Core.Test/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/Validation/PasswordManagerInviteUserValidatorTests.cs index 3b5efc242d..1d0c3ced2a 100644 --- a/test/Core.Test/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/Validation/PasswordManagerInviteUserValidatorTests.cs +++ b/test/Core.Test/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/Validation/PasswordManagerInviteUserValidatorTests.cs @@ -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 sutProvider) + SutProvider sutProvider) { organization.Seats = null; @@ -33,7 +33,7 @@ public class PasswordManagerInviteUserValidatorTests [Theory] [BitAutoData] public async Task Validate_NumberOfSeatsToAddMatchesSeatsAvailable_ShouldReturnValidResult(Organization organization, - SutProvider sutProvider) + SutProvider 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 sutProvider) + SutProvider 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 sutProvider) + SutProvider sutProvider) { organization.Seats = 8; organization.MaxAutoscaleSeats = 9;