mirror of
https://github.com/bitwarden/server.git
synced 2025-04-05 05:00:19 -05:00
Dto rename. Moved from static methods to ctors
This commit is contained in:
parent
cb2bc574e3
commit
4317276f5d
@ -36,7 +36,7 @@ public class InviteUsersValidation(
|
||||
return new Invalid<InviteUserOrganizationValidationRequest>(organizationValidation.ErrorMessageString);
|
||||
}
|
||||
|
||||
var subscriptionUpdate = PasswordManagerSubscriptionUpdate.Create(request);
|
||||
var subscriptionUpdate = new PasswordManagerSubscriptionUpdate(request);
|
||||
var passwordManagerValidationResult = PasswordManagerInviteUserValidation.Validate(subscriptionUpdate);
|
||||
|
||||
if (passwordManagerValidationResult is Invalid<PasswordManagerSubscriptionUpdate> invalidSubscriptionUpdate)
|
||||
@ -44,7 +44,7 @@ public class InviteUsersValidation(
|
||||
return new Invalid<InviteUserOrganizationValidationRequest>(invalidSubscriptionUpdate.ErrorMessageString);
|
||||
}
|
||||
|
||||
var smSubscriptionUpdate = SecretsManagerSubscriptionUpdate.Create(request, subscriptionUpdate);
|
||||
var smSubscriptionUpdate = new SecretsManagerSubscriptionUpdate(request, subscriptionUpdate);
|
||||
var secretsManagerValidationResult = SecretsManagerInviteUserValidation.Validate(smSubscriptionUpdate);
|
||||
|
||||
if (secretsManagerValidationResult is Invalid<SecretsManagerSubscriptionUpdate> invalidSmSubscriptionUpdate)
|
||||
|
@ -6,18 +6,18 @@ namespace Bit.Core.AdminConsole.OrganizationFeatures.OrganizationUsers.InviteUse
|
||||
|
||||
public static class InviteUserPaymentValidation
|
||||
{
|
||||
public static ValidationResult<PaymentSubscriptionDto> Validate(PaymentSubscriptionDto subscription)
|
||||
public static ValidationResult<PaymentsSubscription> Validate(PaymentsSubscription subscription)
|
||||
{
|
||||
if (subscription.ProductTierType is ProductTierType.Free)
|
||||
{
|
||||
return new Valid<PaymentSubscriptionDto>(subscription);
|
||||
return new Valid<PaymentsSubscription>(subscription);
|
||||
}
|
||||
|
||||
if (subscription.SubscriptionStatus == StripeConstants.SubscriptionStatus.Canceled)
|
||||
{
|
||||
return new Invalid<PaymentSubscriptionDto>(InviteUserValidationErrorMessages.CancelledSubscriptionError);
|
||||
return new Invalid<PaymentsSubscription>(InviteUserValidationErrorMessages.CancelledSubscriptionError);
|
||||
}
|
||||
|
||||
return new Valid<PaymentSubscriptionDto>(subscription);
|
||||
return new Valid<PaymentsSubscription>(subscription);
|
||||
}
|
||||
}
|
||||
|
@ -40,23 +40,21 @@ public class PasswordManagerSubscriptionUpdate
|
||||
PasswordManagerPlan = plan;
|
||||
}
|
||||
|
||||
public static PasswordManagerSubscriptionUpdate Create(InviteOrganization inviteOrganization, int occupiedSeats, int seatsToAdd)
|
||||
{
|
||||
return new PasswordManagerSubscriptionUpdate(
|
||||
inviteOrganization.Seats,
|
||||
inviteOrganization.MaxAutoScaleSeats,
|
||||
occupiedSeats,
|
||||
seatsToAdd,
|
||||
inviteOrganization.Plan.PasswordManager);
|
||||
}
|
||||
public PasswordManagerSubscriptionUpdate(InviteOrganization inviteOrganization, int occupiedSeats, int seatsToAdd) :
|
||||
this(
|
||||
organizationSeats: inviteOrganization.Seats,
|
||||
organizationAutoScaleSeatLimit: inviteOrganization.MaxAutoScaleSeats,
|
||||
currentSeats: occupiedSeats,
|
||||
seatsToAdd: seatsToAdd,
|
||||
plan: inviteOrganization.Plan.PasswordManager)
|
||||
{ }
|
||||
|
||||
public static PasswordManagerSubscriptionUpdate Create(InviteUserOrganizationValidationRequest validationRequest)
|
||||
{
|
||||
return new PasswordManagerSubscriptionUpdate(
|
||||
validationRequest.InviteOrganization.Seats,
|
||||
validationRequest.InviteOrganization.MaxAutoScaleSeats,
|
||||
validationRequest.OccupiedPmSeats,
|
||||
validationRequest.Invites.Length,
|
||||
validationRequest.InviteOrganization.Plan.PasswordManager);
|
||||
}
|
||||
public PasswordManagerSubscriptionUpdate(InviteUserOrganizationValidationRequest validationRequest) :
|
||||
this(
|
||||
organizationSeats: validationRequest.InviteOrganization.Seats,
|
||||
organizationAutoScaleSeatLimit: validationRequest.InviteOrganization.MaxAutoScaleSeats,
|
||||
currentSeats: validationRequest.OccupiedPmSeats,
|
||||
seatsToAdd: validationRequest.Invites.Length,
|
||||
plan: validationRequest.InviteOrganization.Plan.PasswordManager)
|
||||
{ }
|
||||
}
|
||||
|
@ -34,25 +34,26 @@ public class SecretsManagerSubscriptionUpdate
|
||||
SecretsManagerPlan = plan;
|
||||
}
|
||||
|
||||
public static SecretsManagerSubscriptionUpdate Create(InviteOrganization inviteOrganization, int occupiedSeats, int seatsToAdd, int passwordManagerSeatTotal)
|
||||
{
|
||||
return new SecretsManagerSubscriptionUpdate(inviteOrganization.UseSecretsManager,
|
||||
inviteOrganization.SmSeats,
|
||||
inviteOrganization.SmMaxAutoScaleSeats,
|
||||
occupiedSeats,
|
||||
seatsToAdd,
|
||||
passwordManagerSeatTotal,
|
||||
inviteOrganization.Plan.SecretsManager);
|
||||
}
|
||||
public SecretsManagerSubscriptionUpdate(InviteOrganization inviteOrganization, int occupiedSeats, int seatsToAdd, int passwordManagerSeatTotal) :
|
||||
this(
|
||||
useSecretsManger: inviteOrganization.UseSecretsManager,
|
||||
organizationSeats: inviteOrganization.SmSeats,
|
||||
organizationAutoScaleSeatLimit: inviteOrganization.SmMaxAutoScaleSeats,
|
||||
currentSeats: occupiedSeats,
|
||||
seatsToAdd: seatsToAdd,
|
||||
passwordManagerUpdatedSeatTotal: passwordManagerSeatTotal,
|
||||
plan: inviteOrganization.Plan.SecretsManager)
|
||||
{ }
|
||||
|
||||
public static SecretsManagerSubscriptionUpdate Create(InviteUserOrganizationValidationRequest refined, PasswordManagerSubscriptionUpdate passwordManagerSubscriptionUpdate)
|
||||
{
|
||||
return new SecretsManagerSubscriptionUpdate(refined.InviteOrganization.UseSecretsManager,
|
||||
refined.InviteOrganization.SmSeats,
|
||||
refined.InviteOrganization.SmMaxAutoScaleSeats,
|
||||
refined.OccupiedSmSeats,
|
||||
refined.Invites.Count(x => x.AccessSecretsManager),
|
||||
passwordManagerSubscriptionUpdate.UpdatedSeatTotal,
|
||||
refined.InviteOrganization.Plan.SecretsManager);
|
||||
}
|
||||
public SecretsManagerSubscriptionUpdate(InviteUserOrganizationValidationRequest request,
|
||||
PasswordManagerSubscriptionUpdate passwordManagerSubscriptionUpdate) :
|
||||
this(
|
||||
useSecretsManger: request.InviteOrganization.UseSecretsManager,
|
||||
organizationSeats: request.InviteOrganization.SmSeats,
|
||||
organizationAutoScaleSeatLimit: request.InviteOrganization.SmMaxAutoScaleSeats,
|
||||
currentSeats: request.OccupiedSmSeats,
|
||||
seatsToAdd: request.Invites.Count(x => x.AccessSecretsManager),
|
||||
passwordManagerUpdatedSeatTotal: passwordManagerSubscriptionUpdate.UpdatedSeatTotal,
|
||||
plan: request.InviteOrganization.Plan.SecretsManager)
|
||||
{ }
|
||||
}
|
||||
|
@ -7,6 +7,7 @@ using Bit.Core.AdminConsole.Models.Business;
|
||||
using Bit.Core.AdminConsole.Models.Data.Organizations.Policies;
|
||||
using Bit.Core.AdminConsole.OrganizationFeatures.OrganizationUsers.Interfaces;
|
||||
using Bit.Core.AdminConsole.OrganizationFeatures.OrganizationUsers.InviteUsers;
|
||||
using Bit.Core.AdminConsole.OrganizationFeatures.OrganizationUsers.InviteUsers.Models;
|
||||
using Bit.Core.AdminConsole.Repositories;
|
||||
using Bit.Core.AdminConsole.Services;
|
||||
using Bit.Core.Auth.Enums;
|
||||
@ -35,6 +36,7 @@ using Bit.Core.Tools.Services;
|
||||
using Bit.Core.Utilities;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Stripe;
|
||||
using OrganizationUserInvite = Bit.Core.Models.Business.OrganizationUserInvite;
|
||||
|
||||
namespace Bit.Core.Services;
|
||||
|
||||
|
@ -20,8 +20,8 @@ public static class InviteUserOrganizationValidationRequestHelpers
|
||||
PerformedAt = request.PerformedAt,
|
||||
OccupiedPmSeats = 0,
|
||||
OccupiedSmSeats = 0,
|
||||
PasswordManagerSubscriptionUpdate = PasswordManagerSubscriptionUpdate.Create(inviteOrganization, 0, 0),
|
||||
SecretsManagerSubscriptionUpdate = SecretsManagerSubscriptionUpdate.Create(inviteOrganization, 0, 0, 0)
|
||||
PasswordManagerSubscriptionUpdate = new PasswordManagerSubscriptionUpdate(inviteOrganization, 0, 0),
|
||||
SecretsManagerSubscriptionUpdate = new SecretsManagerSubscriptionUpdate(inviteOrganization, 0, 0, 0)
|
||||
};
|
||||
|
||||
public static InviteUserOrganizationValidationRequest WithPasswordManagerUpdate(this InviteUserOrganizationValidationRequest request, PasswordManagerSubscriptionUpdate passwordManagerSubscriptionUpdate) =>
|
||||
|
@ -218,7 +218,7 @@ public class InviteOrganizationUserCommandTests
|
||||
sutProvider.GetDependency<IInviteUsersValidation>()
|
||||
.ValidateAsync(Arg.Any<InviteUserOrganizationValidationRequest>())
|
||||
.Returns(new Valid<InviteUserOrganizationValidationRequest>(GetInviteValidationRequestMock(request, organizationDto)
|
||||
.WithPasswordManagerUpdate(PasswordManagerSubscriptionUpdate.Create(organizationDto, organization.Seats.Value, 1))));
|
||||
.WithPasswordManagerUpdate(new PasswordManagerSubscriptionUpdate(organizationDto, organization.Seats.Value, 1))));
|
||||
|
||||
// Act
|
||||
var result = await sutProvider.Sut.InviteScimOrganizationUserAsync(request);
|
||||
@ -260,7 +260,7 @@ public class InviteOrganizationUserCommandTests
|
||||
timeProvider.GetUtcNow(),
|
||||
externalId);
|
||||
|
||||
var passwordManagerUpdate = PasswordManagerSubscriptionUpdate.Create(organizationDto, organization.Seats.Value, 1);
|
||||
var passwordManagerUpdate = new PasswordManagerSubscriptionUpdate(organizationDto, organization.Seats.Value, 1);
|
||||
|
||||
var orgUserRepository = sutProvider.GetDependency<IOrganizationUserRepository>();
|
||||
|
||||
@ -323,7 +323,7 @@ public class InviteOrganizationUserCommandTests
|
||||
timeProvider.GetUtcNow(),
|
||||
externalId);
|
||||
|
||||
var secretsManagerSubscriptionUpdate = SecretsManagerSubscriptionUpdate.Create(
|
||||
var secretsManagerSubscriptionUpdate = new SecretsManagerSubscriptionUpdate(
|
||||
organizationDto,
|
||||
organization.SmSeats.Value,
|
||||
1,
|
||||
|
@ -1,5 +1,6 @@
|
||||
using Bit.Core.AdminConsole.Entities;
|
||||
using Bit.Core.AdminConsole.OrganizationFeatures.OrganizationUsers.InviteUsers;
|
||||
using Bit.Core.AdminConsole.OrganizationFeatures.OrganizationUsers.InviteUsers.Models;
|
||||
using Bit.Core.AdminConsole.Repositories;
|
||||
using Bit.Core.Auth.Entities;
|
||||
using Bit.Core.Auth.Models.Business.Tokenables;
|
||||
|
@ -17,37 +17,37 @@ public class InviteUserPaymentValidationTests
|
||||
{
|
||||
organization.PlanType = PlanType.Free;
|
||||
|
||||
var result = InviteUserPaymentValidation.Validate(new PaymentSubscriptionDto
|
||||
var result = InviteUserPaymentValidation.Validate(new PaymentsSubscription
|
||||
{
|
||||
SubscriptionStatus = StripeConstants.SubscriptionStatus.Active,
|
||||
ProductTierType = new InviteOrganization(organization).Plan.ProductTier
|
||||
});
|
||||
|
||||
Assert.IsType<Valid<PaymentSubscriptionDto>>(result);
|
||||
Assert.IsType<Valid<PaymentsSubscription>>(result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenSubscriptionIsCanceled_ReturnsInvalidResponse()
|
||||
{
|
||||
var result = InviteUserPaymentValidation.Validate(new PaymentSubscriptionDto
|
||||
var result = InviteUserPaymentValidation.Validate(new PaymentsSubscription
|
||||
{
|
||||
SubscriptionStatus = StripeConstants.SubscriptionStatus.Canceled,
|
||||
ProductTierType = ProductTierType.Enterprise
|
||||
});
|
||||
|
||||
Assert.IsType<Invalid<PaymentSubscriptionDto>>(result);
|
||||
Assert.IsType<Invalid<PaymentsSubscription>>(result);
|
||||
Assert.Equal(InviteUserValidationErrorMessages.CancelledSubscriptionError, result.ErrorMessageString);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenSubscriptionIsActive_ReturnsValidResponse()
|
||||
{
|
||||
var result = InviteUserPaymentValidation.Validate(new PaymentSubscriptionDto
|
||||
var result = InviteUserPaymentValidation.Validate(new PaymentsSubscription
|
||||
{
|
||||
SubscriptionStatus = StripeConstants.SubscriptionStatus.Active,
|
||||
ProductTierType = ProductTierType.Enterprise
|
||||
});
|
||||
|
||||
Assert.IsType<Valid<PaymentSubscriptionDto>>(result);
|
||||
Assert.IsType<Valid<PaymentsSubscription>>(result);
|
||||
}
|
||||
}
|
||||
|
@ -19,7 +19,7 @@ public class PasswordManagerInviteUserValidationTests
|
||||
|
||||
var organizationDto = new InviteOrganization(organization);
|
||||
|
||||
var subscriptionUpdate = PasswordManagerSubscriptionUpdate.Create(organizationDto, 0, 0);
|
||||
var subscriptionUpdate = new PasswordManagerSubscriptionUpdate(organizationDto, 0, 0);
|
||||
|
||||
var result = PasswordManagerInviteUserValidation.Validate(subscriptionUpdate);
|
||||
|
||||
@ -37,7 +37,7 @@ public class PasswordManagerInviteUserValidationTests
|
||||
|
||||
var organizationDto = new InviteOrganization(organization);
|
||||
|
||||
var subscriptionUpdate = PasswordManagerSubscriptionUpdate.Create(organizationDto, seatsOccupiedByUsers, additionalSeats);
|
||||
var subscriptionUpdate = new PasswordManagerSubscriptionUpdate(organizationDto, seatsOccupiedByUsers, additionalSeats);
|
||||
|
||||
var result = PasswordManagerInviteUserValidation.Validate(subscriptionUpdate);
|
||||
|
||||
@ -56,7 +56,7 @@ public class PasswordManagerInviteUserValidationTests
|
||||
|
||||
var organizationDto = new InviteOrganization(organization);
|
||||
|
||||
var subscriptionUpdate = PasswordManagerSubscriptionUpdate.Create(organizationDto, seatsOccupiedByUsers, additionalSeats);
|
||||
var subscriptionUpdate = new PasswordManagerSubscriptionUpdate(organizationDto, seatsOccupiedByUsers, additionalSeats);
|
||||
|
||||
var result = PasswordManagerInviteUserValidation.Validate(subscriptionUpdate);
|
||||
|
||||
@ -75,7 +75,7 @@ public class PasswordManagerInviteUserValidationTests
|
||||
|
||||
var organizationDto = new InviteOrganization(organization);
|
||||
|
||||
var subscriptionUpdate = PasswordManagerSubscriptionUpdate.Create(organizationDto, seatsOccupiedByUsers, additionalSeats);
|
||||
var subscriptionUpdate = new PasswordManagerSubscriptionUpdate(organizationDto, seatsOccupiedByUsers, additionalSeats);
|
||||
|
||||
var result = PasswordManagerInviteUserValidation.Validate(subscriptionUpdate);
|
||||
|
||||
|
@ -22,7 +22,7 @@ public class SecretsManagerInviteUserValidationTests
|
||||
organization.UseSecretsManager = false;
|
||||
|
||||
var organizationDto = new InviteOrganization(organization);
|
||||
var subscriptionUpdate = PasswordManagerSubscriptionUpdate.Create(organizationDto, 0, 0);
|
||||
var subscriptionUpdate = new PasswordManagerSubscriptionUpdate(organizationDto, 0, 0);
|
||||
|
||||
var request = new InviteUserOrganizationValidationRequest
|
||||
{
|
||||
@ -34,7 +34,7 @@ public class SecretsManagerInviteUserValidationTests
|
||||
OccupiedSmSeats = 0
|
||||
};
|
||||
|
||||
var update = SecretsManagerSubscriptionUpdate.Create(request, subscriptionUpdate);
|
||||
var update = new SecretsManagerSubscriptionUpdate(request, subscriptionUpdate);
|
||||
|
||||
var result = SecretsManagerInviteUserValidation.Validate(update);
|
||||
|
||||
@ -49,7 +49,7 @@ public class SecretsManagerInviteUserValidationTests
|
||||
organization.UseSecretsManager = false;
|
||||
|
||||
var organizationDto = new InviteOrganization(organization);
|
||||
var subscriptionUpdate = PasswordManagerSubscriptionUpdate.Create(organizationDto, 0, 0);
|
||||
var subscriptionUpdate = new PasswordManagerSubscriptionUpdate(organizationDto, 0, 0);
|
||||
|
||||
var invite = OrganizationUserInvite.Create(["email@test.com"], [], OrganizationUserType.User, new Permissions(), string.Empty, true);
|
||||
|
||||
@ -63,7 +63,7 @@ public class SecretsManagerInviteUserValidationTests
|
||||
OccupiedSmSeats = 0
|
||||
};
|
||||
|
||||
var update = SecretsManagerSubscriptionUpdate.Create(request, subscriptionUpdate);
|
||||
var update = new SecretsManagerSubscriptionUpdate(request, subscriptionUpdate);
|
||||
|
||||
var result = SecretsManagerInviteUserValidation.Validate(update);
|
||||
|
||||
@ -80,7 +80,7 @@ public class SecretsManagerInviteUserValidationTests
|
||||
organization.UseSecretsManager = true;
|
||||
|
||||
var organizationDto = new InviteOrganization(organization);
|
||||
var subscriptionUpdate = PasswordManagerSubscriptionUpdate.Create(organizationDto, 0, 0);
|
||||
var subscriptionUpdate = new PasswordManagerSubscriptionUpdate(organizationDto, 0, 0);
|
||||
|
||||
var request = new InviteUserOrganizationValidationRequest
|
||||
{
|
||||
@ -92,7 +92,7 @@ public class SecretsManagerInviteUserValidationTests
|
||||
OccupiedSmSeats = 0
|
||||
};
|
||||
|
||||
var update = SecretsManagerSubscriptionUpdate.Create(request, subscriptionUpdate);
|
||||
var update = new SecretsManagerSubscriptionUpdate(request, subscriptionUpdate);
|
||||
|
||||
var result = SecretsManagerInviteUserValidation.Validate(update);
|
||||
|
||||
@ -110,7 +110,7 @@ public class SecretsManagerInviteUserValidationTests
|
||||
organization.PlanType = PlanType.EnterpriseAnnually;
|
||||
|
||||
var organizationDto = new InviteOrganization(organization);
|
||||
var subscriptionUpdate = PasswordManagerSubscriptionUpdate.Create(organizationDto, 0, 0);
|
||||
var subscriptionUpdate = new PasswordManagerSubscriptionUpdate(organizationDto, 0, 0);
|
||||
|
||||
var request = new InviteUserOrganizationValidationRequest
|
||||
{
|
||||
@ -122,7 +122,7 @@ public class SecretsManagerInviteUserValidationTests
|
||||
OccupiedSmSeats = 4
|
||||
};
|
||||
|
||||
var update = SecretsManagerSubscriptionUpdate.Create(request, subscriptionUpdate);
|
||||
var update = new SecretsManagerSubscriptionUpdate(request, subscriptionUpdate);
|
||||
|
||||
var result = SecretsManagerInviteUserValidation.Validate(update);
|
||||
|
||||
@ -141,7 +141,7 @@ public class SecretsManagerInviteUserValidationTests
|
||||
organization.PlanType = PlanType.EnterpriseAnnually;
|
||||
|
||||
var organizationDto = new InviteOrganization(organization);
|
||||
var subscriptionUpdate = PasswordManagerSubscriptionUpdate.Create(organizationDto, 0, 0);
|
||||
var subscriptionUpdate = new PasswordManagerSubscriptionUpdate(organizationDto, 0, 0);
|
||||
|
||||
var request = new InviteUserOrganizationValidationRequest
|
||||
{
|
||||
@ -153,7 +153,7 @@ public class SecretsManagerInviteUserValidationTests
|
||||
OccupiedSmSeats = 4
|
||||
};
|
||||
|
||||
var update = SecretsManagerSubscriptionUpdate.Create(request, subscriptionUpdate);
|
||||
var update = new SecretsManagerSubscriptionUpdate(request, subscriptionUpdate);
|
||||
|
||||
var result = SecretsManagerInviteUserValidation.Validate(update);
|
||||
|
||||
|
@ -4,6 +4,7 @@ using Bit.Core.AdminConsole.Enums;
|
||||
using Bit.Core.AdminConsole.Enums.Provider;
|
||||
using Bit.Core.AdminConsole.OrganizationFeatures.OrganizationUsers.Interfaces;
|
||||
using Bit.Core.AdminConsole.OrganizationFeatures.OrganizationUsers.InviteUsers;
|
||||
using Bit.Core.AdminConsole.OrganizationFeatures.OrganizationUsers.InviteUsers.Models;
|
||||
using Bit.Core.AdminConsole.Repositories;
|
||||
using Bit.Core.AdminConsole.Services;
|
||||
using Bit.Core.Auth.Models.Business.Tokenables;
|
||||
|
Loading…
x
Reference in New Issue
Block a user