diff --git a/src/Core/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/Validation/InviteOrganizationUserValidation.cs b/src/Core/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/Validation/InviteOrganizationUserValidator.cs similarity index 92% rename from src/Core/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/Validation/InviteOrganizationUserValidation.cs rename to src/Core/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/Validation/InviteOrganizationUserValidator.cs index c74cd2de5f..c36c992c39 100644 --- a/src/Core/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/Validation/InviteOrganizationUserValidation.cs +++ b/src/Core/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/Validation/InviteOrganizationUserValidator.cs @@ -25,11 +25,6 @@ public class InviteUsersValidator( { public async Task> ValidateAsync(InviteUserOrganizationValidationRequest request) { - if (ValidateEnvironment(globalSettings) is Invalid invalidEnvironment) - { - return invalidEnvironment.Map(request); - } - var organizationValidationResult = InvitingUserOrganizationValidator.Validate(request.InviteOrganization); if (organizationValidationResult is Invalid organizationValidation) @@ -45,6 +40,11 @@ public class InviteUsersValidator( return invalidSubscriptionUpdate.Map(request); } + if (ValidateEnvironment(globalSettings, passwordManagerValidationResult as Valid) is Invalid invalidEnvironment) + { + return invalidEnvironment.Map(request); + } + var smSubscriptionUpdate = new SecretsManagerSubscriptionUpdate(request, subscriptionUpdate); var secretsManagerValidationResult = SecretsManagerInviteUserValidation.Validate(smSubscriptionUpdate); @@ -81,8 +81,8 @@ public class InviteUsersValidator( smSubscriptionUpdate)); } - public static ValidationResult ValidateEnvironment(IGlobalSettings globalSettings) => - globalSettings.SelfHosted + public static ValidationResult ValidateEnvironment(IGlobalSettings globalSettings, Valid subscriptionUpdate) => + globalSettings.SelfHosted && subscriptionUpdate?.Value.AdditionalSeats > 0 ? new Invalid(new CannotAutoScaleOnSelfHostError(globalSettings)) : new Valid(globalSettings); } diff --git a/src/Core/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/Validation/PasswordManager/PasswordManagerInviteUserValidator.cs b/src/Core/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/Validation/PasswordManager/PasswordManagerInviteUserValidator.cs index b3346aebf8..4d6940c6c7 100644 --- a/src/Core/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/Validation/PasswordManager/PasswordManagerInviteUserValidator.cs +++ b/src/Core/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/Validation/PasswordManager/PasswordManagerInviteUserValidator.cs @@ -4,7 +4,11 @@ namespace Bit.Core.AdminConsole.OrganizationFeatures.OrganizationUsers.InviteUse public static class PasswordManagerInviteUserValidator { - // NOTE This is only for validating adding users to an organization, not removing + /// + /// This is for validating if the organization can add additional users. + /// + /// + /// public static ValidationResult Validate(PasswordManagerSubscriptionUpdate subscriptionUpdate) { if (subscriptionUpdate.Seats is null)