From cb2bc574e334df708afbb42734f908060b368b11 Mon Sep 17 00:00:00 2001 From: jrmccannon Date: Fri, 7 Mar 2025 09:03:43 -0600 Subject: [PATCH] Renamed dto and added ctor --- .../InviteOrganizationUserValidation.cs | 29 +++++++++++-------- .../Models/PaymentSubscriptionDto.cs | 18 ------------ .../Validation/Models/PaymentsSubscription.cs | 19 ++++++++++++ 3 files changed, 36 insertions(+), 30 deletions(-) delete mode 100644 src/Core/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/Validation/Models/PaymentSubscriptionDto.cs create mode 100644 src/Core/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/Validation/Models/PaymentsSubscription.cs diff --git a/src/Core/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/Validation/InviteOrganizationUserValidation.cs b/src/Core/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/Validation/InviteOrganizationUserValidation.cs index 76811d60f4..3dcb63f1c5 100644 --- a/src/Core/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/Validation/InviteOrganizationUserValidation.cs +++ b/src/Core/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/Validation/InviteOrganizationUserValidation.cs @@ -10,6 +10,7 @@ using SecretsManagerSubscriptionUpdate = Bit.Core.AdminConsole.OrganizationFeatu namespace Bit.Core.AdminConsole.OrganizationFeatures.OrganizationUsers.InviteUsers.Validation; +// TODO move into own file ... and change name to validator public interface IInviteUsersValidation { Task> ValidateAsync(InviteUserOrganizationValidationRequest request); @@ -28,40 +29,44 @@ public class InviteUsersValidation( return new Invalid(invalidEnvironment.ErrorMessageString); } - if (InvitingUserOrganizationValidation.Validate(request.InviteOrganization) is Invalid organizationValidation) + var organizationValidationResult = InvitingUserOrganizationValidation.Validate(request.InviteOrganization); + + if (organizationValidationResult is Invalid organizationValidation) { return new Invalid(organizationValidation.ErrorMessageString); } var subscriptionUpdate = PasswordManagerSubscriptionUpdate.Create(request); + var passwordManagerValidationResult = PasswordManagerInviteUserValidation.Validate(subscriptionUpdate); - if (PasswordManagerInviteUserValidation.Validate(subscriptionUpdate) is - Invalid invalidSubscriptionUpdate) + if (passwordManagerValidationResult is Invalid invalidSubscriptionUpdate) { return new Invalid(invalidSubscriptionUpdate.ErrorMessageString); } var smSubscriptionUpdate = SecretsManagerSubscriptionUpdate.Create(request, subscriptionUpdate); + var secretsManagerValidationResult = SecretsManagerInviteUserValidation.Validate(smSubscriptionUpdate); - if (SecretsManagerInviteUserValidation.Validate(smSubscriptionUpdate) is - Invalid invalidSmSubscriptionUpdate) + if (secretsManagerValidationResult is Invalid invalidSmSubscriptionUpdate) { return new Invalid(invalidSmSubscriptionUpdate.ErrorMessageString); } var provider = await providerRepository.GetByOrganizationIdAsync(request.InviteOrganization.OrganizationId); - - if (provider is not null && - InvitingUserOrganizationProviderValidation.Validate(ProviderDto.FromProviderEntity(provider)) is - Invalid invalidProviderValidation) + if (provider is not null) { - return new Invalid(invalidProviderValidation.ErrorMessageString); + var providerValidationResult = InvitingUserOrganizationProviderValidation.Validate(ProviderDto.FromProviderEntity(provider)); + + if (providerValidationResult is Invalid invalidProviderValidation) + { + return new Invalid(invalidProviderValidation.ErrorMessageString); + } } var paymentSubscription = await paymentService.GetSubscriptionAsync(await organizationRepository.GetByIdAsync(request.InviteOrganization.OrganizationId)); + var paymentValidationResult = InviteUserPaymentValidation.Validate(new PaymentsSubscription(paymentSubscription, request.InviteOrganization)); - if (InviteUserPaymentValidation.Validate(PaymentSubscriptionDto.FromSubscriptionInfo(paymentSubscription, request.InviteOrganization)) is - Invalid invalidPaymentValidation) + if (paymentValidationResult is Invalid invalidPaymentValidation) { return new Invalid(invalidPaymentValidation.ErrorMessageString); } diff --git a/src/Core/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/Validation/Models/PaymentSubscriptionDto.cs b/src/Core/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/Validation/Models/PaymentSubscriptionDto.cs deleted file mode 100644 index b9b5aa54b2..0000000000 --- a/src/Core/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/Validation/Models/PaymentSubscriptionDto.cs +++ /dev/null @@ -1,18 +0,0 @@ -using Bit.Core.AdminConsole.Models.Business; -using Bit.Core.Billing.Enums; -using Bit.Core.Models.Business; - -namespace Bit.Core.AdminConsole.OrganizationFeatures.OrganizationUsers.InviteUsers.Validation.Models; - -public class PaymentSubscriptionDto -{ - public ProductTierType ProductTierType { get; init; } - public string SubscriptionStatus { get; init; } - - public static PaymentSubscriptionDto FromSubscriptionInfo(SubscriptionInfo subscriptionInfo, InviteOrganization inviteOrganization) => - new() - { - SubscriptionStatus = subscriptionInfo?.Subscription?.Status ?? string.Empty, - ProductTierType = inviteOrganization.Plan.ProductTier - }; -} diff --git a/src/Core/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/Validation/Models/PaymentsSubscription.cs b/src/Core/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/Validation/Models/PaymentsSubscription.cs new file mode 100644 index 0000000000..dea35c4ddd --- /dev/null +++ b/src/Core/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/Validation/Models/PaymentsSubscription.cs @@ -0,0 +1,19 @@ +using Bit.Core.AdminConsole.Models.Business; +using Bit.Core.Billing.Enums; +using Bit.Core.Models.Business; + +namespace Bit.Core.AdminConsole.OrganizationFeatures.OrganizationUsers.InviteUsers.Validation.Models; + +public class PaymentsSubscription +{ + public ProductTierType ProductTierType { get; init; } + public string SubscriptionStatus { get; init; } + + public PaymentsSubscription() { } + + public PaymentsSubscription(SubscriptionInfo subscriptionInfo, InviteOrganization inviteOrganization) + { + SubscriptionStatus = subscriptionInfo?.Subscription?.Status ?? string.Empty; + ProductTierType = inviteOrganization.Plan.ProductTier; + } +}