mirror of
https://github.com/bitwarden/server.git
synced 2025-04-05 05:00:19 -05:00
Renamed dto and added ctor
This commit is contained in:
parent
46ee99a5a1
commit
cb2bc574e3
@ -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<ValidationResult<InviteUserOrganizationValidationRequest>> ValidateAsync(InviteUserOrganizationValidationRequest request);
|
||||
@ -28,40 +29,44 @@ public class InviteUsersValidation(
|
||||
return new Invalid<InviteUserOrganizationValidationRequest>(invalidEnvironment.ErrorMessageString);
|
||||
}
|
||||
|
||||
if (InvitingUserOrganizationValidation.Validate(request.InviteOrganization) is Invalid<InviteOrganization> organizationValidation)
|
||||
var organizationValidationResult = InvitingUserOrganizationValidation.Validate(request.InviteOrganization);
|
||||
|
||||
if (organizationValidationResult is Invalid<InviteOrganization> organizationValidation)
|
||||
{
|
||||
return new Invalid<InviteUserOrganizationValidationRequest>(organizationValidation.ErrorMessageString);
|
||||
}
|
||||
|
||||
var subscriptionUpdate = PasswordManagerSubscriptionUpdate.Create(request);
|
||||
var passwordManagerValidationResult = PasswordManagerInviteUserValidation.Validate(subscriptionUpdate);
|
||||
|
||||
if (PasswordManagerInviteUserValidation.Validate(subscriptionUpdate) is
|
||||
Invalid<PasswordManagerSubscriptionUpdate> invalidSubscriptionUpdate)
|
||||
if (passwordManagerValidationResult is Invalid<PasswordManagerSubscriptionUpdate> invalidSubscriptionUpdate)
|
||||
{
|
||||
return new Invalid<InviteUserOrganizationValidationRequest>(invalidSubscriptionUpdate.ErrorMessageString);
|
||||
}
|
||||
|
||||
var smSubscriptionUpdate = SecretsManagerSubscriptionUpdate.Create(request, subscriptionUpdate);
|
||||
var secretsManagerValidationResult = SecretsManagerInviteUserValidation.Validate(smSubscriptionUpdate);
|
||||
|
||||
if (SecretsManagerInviteUserValidation.Validate(smSubscriptionUpdate) is
|
||||
Invalid<SecretsManagerSubscriptionUpdate> invalidSmSubscriptionUpdate)
|
||||
if (secretsManagerValidationResult is Invalid<SecretsManagerSubscriptionUpdate> invalidSmSubscriptionUpdate)
|
||||
{
|
||||
return new Invalid<InviteUserOrganizationValidationRequest>(invalidSmSubscriptionUpdate.ErrorMessageString);
|
||||
}
|
||||
|
||||
var provider = await providerRepository.GetByOrganizationIdAsync(request.InviteOrganization.OrganizationId);
|
||||
|
||||
if (provider is not null &&
|
||||
InvitingUserOrganizationProviderValidation.Validate(ProviderDto.FromProviderEntity(provider)) is
|
||||
Invalid<ProviderDto> invalidProviderValidation)
|
||||
if (provider is not null)
|
||||
{
|
||||
return new Invalid<InviteUserOrganizationValidationRequest>(invalidProviderValidation.ErrorMessageString);
|
||||
var providerValidationResult = InvitingUserOrganizationProviderValidation.Validate(ProviderDto.FromProviderEntity(provider));
|
||||
|
||||
if (providerValidationResult is Invalid<ProviderDto> invalidProviderValidation)
|
||||
{
|
||||
return new Invalid<InviteUserOrganizationValidationRequest>(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<PaymentSubscriptionDto> invalidPaymentValidation)
|
||||
if (paymentValidationResult is Invalid<PaymentsSubscription> invalidPaymentValidation)
|
||||
{
|
||||
return new Invalid<InviteUserOrganizationValidationRequest>(invalidPaymentValidation.ErrorMessageString);
|
||||
}
|
||||
|
@ -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
|
||||
};
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user