diff --git a/src/Core/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/Validation/InviteOrganizationUserValidator.cs b/src/Core/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/Validation/InviteOrganizationUserValidator.cs index 00568c9c31..f0ce1dbaa1 100644 --- a/src/Core/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/Validation/InviteOrganizationUserValidator.cs +++ b/src/Core/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/Validation/InviteOrganizationUserValidator.cs @@ -46,6 +46,7 @@ public class InviteUsersValidator( } var smSubscriptionUpdate = new SecretsManagerSubscriptionUpdate(request, subscriptionUpdate); + var secretsManagerValidationResult = SecretsManagerInviteUserValidation.Validate(smSubscriptionUpdate); if (secretsManagerValidationResult is Invalid invalidSmSubscriptionUpdate) @@ -56,9 +57,9 @@ public class InviteUsersValidator( var provider = await providerRepository.GetByOrganizationIdAsync(request.InviteOrganization.OrganizationId); if (provider is not null) { - var providerValidationResult = InvitingUserOrganizationProviderValidation.Validate(ProviderDto.FromProviderEntity(provider)); + var providerValidationResult = InvitingUserOrganizationProviderValidator.Validate(new InviteOrganizationProvider(provider)); - if (providerValidationResult is Invalid invalidProviderValidation) + if (providerValidationResult is Invalid invalidProviderValidation) { return invalidProviderValidation.Map(request); } diff --git a/src/Core/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/Validation/Provider/Errors.cs b/src/Core/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/Validation/Provider/Errors.cs index d40211c8a6..104ce5cc7e 100644 --- a/src/Core/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/Validation/Provider/Errors.cs +++ b/src/Core/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/Validation/Provider/Errors.cs @@ -2,12 +2,12 @@ namespace Bit.Core.AdminConsole.OrganizationFeatures.OrganizationUsers.InviteUsers.Validation.Provider; -public record ProviderBillableSeatLimitError(ProviderDto InvalidRequest) : Error(Code, InvalidRequest) +public record ProviderBillableSeatLimitError(InviteOrganizationProvider InvalidRequest) : Error(Code, InvalidRequest) { public const string Code = "Seat limit has been reached. Please contact your provider to add more seats."; } -public record ProviderResellerSeatLimitError(ProviderDto InvalidRequest) : Error(Code, InvalidRequest) +public record ProviderResellerSeatLimitError(InviteOrganizationProvider InvalidRequest) : Error(Code, InvalidRequest) { public const string Code = "Seat limit has been reached. Contact your provider to purchase additional seats."; } diff --git a/src/Core/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/Validation/Provider/ProviderDto.cs b/src/Core/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/Validation/Provider/InviteOrganizationProvider.cs similarity index 58% rename from src/Core/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/Validation/Provider/ProviderDto.cs rename to src/Core/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/Validation/Provider/InviteOrganizationProvider.cs index 05bb487e07..b52218307d 100644 --- a/src/Core/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/Validation/Provider/ProviderDto.cs +++ b/src/Core/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/Validation/Provider/InviteOrganizationProvider.cs @@ -2,15 +2,18 @@ namespace Bit.Core.AdminConsole.OrganizationFeatures.OrganizationUsers.InviteUsers.Validation.Provider; -public class ProviderDto +public class InviteOrganizationProvider { public Guid ProviderId { get; init; } public ProviderType Type { get; init; } public ProviderStatusType Status { get; init; } public bool Enabled { get; init; } - public static ProviderDto FromProviderEntity(Entities.Provider.Provider provider) + public InviteOrganizationProvider(Entities.Provider.Provider provider) { - return new ProviderDto { ProviderId = provider.Id, Type = provider.Type, Status = provider.Status, Enabled = provider.Enabled }; + ProviderId = provider.Id; + Type = provider.Type; + Status = provider.Status; + Enabled = provider.Enabled; } } diff --git a/src/Core/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/Validation/Provider/InvitingUserOrganizationProviderValidation.cs b/src/Core/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/Validation/Provider/InvitingUserOrganizationProviderValidation.cs deleted file mode 100644 index 95907676df..0000000000 --- a/src/Core/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/Validation/Provider/InvitingUserOrganizationProviderValidation.cs +++ /dev/null @@ -1,26 +0,0 @@ -using Bit.Core.AdminConsole.Enums.Provider; -using Bit.Core.AdminConsole.Shared.Validation; -using Bit.Core.Billing.Extensions; - -namespace Bit.Core.AdminConsole.OrganizationFeatures.OrganizationUsers.InviteUsers.Validation.Provider; - -public static class InvitingUserOrganizationProviderValidation -{ - public static ValidationResult Validate(ProviderDto provider) - { - if (provider is { Enabled: true }) - { - if (provider.IsBillable()) - { - return new Invalid(new ProviderBillableSeatLimitError(provider)); - } - - if (provider.Type == ProviderType.Reseller) - { - return new Invalid(new ProviderResellerSeatLimitError(provider)); - } - } - - return new Valid(provider); - } -} diff --git a/src/Core/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/Validation/Provider/InvitingUserOrganizationProviderValidator.cs b/src/Core/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/Validation/Provider/InvitingUserOrganizationProviderValidator.cs new file mode 100644 index 0000000000..f84b25f76f --- /dev/null +++ b/src/Core/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/Validation/Provider/InvitingUserOrganizationProviderValidator.cs @@ -0,0 +1,28 @@ +using Bit.Core.AdminConsole.Enums.Provider; +using Bit.Core.AdminConsole.Shared.Validation; +using Bit.Core.Billing.Extensions; + +namespace Bit.Core.AdminConsole.OrganizationFeatures.OrganizationUsers.InviteUsers.Validation.Provider; + +public static class InvitingUserOrganizationProviderValidator +{ + public static ValidationResult Validate(InviteOrganizationProvider inviteOrganizationProvider) + { + if (inviteOrganizationProvider is not { Enabled: true }) + { + return new Valid(inviteOrganizationProvider); + } + + if (inviteOrganizationProvider.IsBillable()) + { + return new Invalid(new ProviderBillableSeatLimitError(inviteOrganizationProvider)); + } + + if (inviteOrganizationProvider.Type == ProviderType.Reseller) + { + return new Invalid(new ProviderResellerSeatLimitError(inviteOrganizationProvider)); + } + + return new Valid(inviteOrganizationProvider); + } +} diff --git a/src/Core/Billing/Extensions/BillingExtensions.cs b/src/Core/Billing/Extensions/BillingExtensions.cs index a94e690e59..4fb97e1db7 100644 --- a/src/Core/Billing/Extensions/BillingExtensions.cs +++ b/src/Core/Billing/Extensions/BillingExtensions.cs @@ -29,8 +29,8 @@ public static class BillingExtensions Status: ProviderStatusType.Billable }; - public static bool IsBillable(this ProviderDto provider) => - provider is + public static bool IsBillable(this InviteOrganizationProvider inviteOrganizationProvider) => + inviteOrganizationProvider is { Type: ProviderType.Msp or ProviderType.MultiOrganizationEnterprise, Status: ProviderStatusType.Billable