1
0
mirror of https://github.com/bitwarden/server.git synced 2025-04-05 05:00:19 -05:00

Quick rename

This commit is contained in:
jrmccannon 2025-03-26 15:30:04 -05:00
parent d22cbb27e1
commit 27d6d0d731
No known key found for this signature in database
GPG Key ID: CF03F3DB01CE96A6
6 changed files with 41 additions and 35 deletions

View File

@ -46,6 +46,7 @@ public class InviteUsersValidator(
} }
var smSubscriptionUpdate = new SecretsManagerSubscriptionUpdate(request, subscriptionUpdate); var smSubscriptionUpdate = new SecretsManagerSubscriptionUpdate(request, subscriptionUpdate);
var secretsManagerValidationResult = SecretsManagerInviteUserValidation.Validate(smSubscriptionUpdate); var secretsManagerValidationResult = SecretsManagerInviteUserValidation.Validate(smSubscriptionUpdate);
if (secretsManagerValidationResult is Invalid<SecretsManagerSubscriptionUpdate> invalidSmSubscriptionUpdate) if (secretsManagerValidationResult is Invalid<SecretsManagerSubscriptionUpdate> invalidSmSubscriptionUpdate)
@ -56,9 +57,9 @@ public class InviteUsersValidator(
var provider = await providerRepository.GetByOrganizationIdAsync(request.InviteOrganization.OrganizationId); var provider = await providerRepository.GetByOrganizationIdAsync(request.InviteOrganization.OrganizationId);
if (provider is not null) if (provider is not null)
{ {
var providerValidationResult = InvitingUserOrganizationProviderValidation.Validate(ProviderDto.FromProviderEntity(provider)); var providerValidationResult = InvitingUserOrganizationProviderValidator.Validate(new InviteOrganizationProvider(provider));
if (providerValidationResult is Invalid<ProviderDto> invalidProviderValidation) if (providerValidationResult is Invalid<InviteOrganizationProvider> invalidProviderValidation)
{ {
return invalidProviderValidation.Map(request); return invalidProviderValidation.Map(request);
} }

View File

@ -2,12 +2,12 @@
namespace Bit.Core.AdminConsole.OrganizationFeatures.OrganizationUsers.InviteUsers.Validation.Provider; namespace Bit.Core.AdminConsole.OrganizationFeatures.OrganizationUsers.InviteUsers.Validation.Provider;
public record ProviderBillableSeatLimitError(ProviderDto InvalidRequest) : Error<ProviderDto>(Code, InvalidRequest) public record ProviderBillableSeatLimitError(InviteOrganizationProvider InvalidRequest) : Error<InviteOrganizationProvider>(Code, InvalidRequest)
{ {
public const string Code = "Seat limit has been reached. Please contact your provider to add more seats."; public const string Code = "Seat limit has been reached. Please contact your provider to add more seats.";
} }
public record ProviderResellerSeatLimitError(ProviderDto InvalidRequest) : Error<ProviderDto>(Code, InvalidRequest) public record ProviderResellerSeatLimitError(InviteOrganizationProvider InvalidRequest) : Error<InviteOrganizationProvider>(Code, InvalidRequest)
{ {
public const string Code = "Seat limit has been reached. Contact your provider to purchase additional seats."; public const string Code = "Seat limit has been reached. Contact your provider to purchase additional seats.";
} }

View File

@ -2,15 +2,18 @@
namespace Bit.Core.AdminConsole.OrganizationFeatures.OrganizationUsers.InviteUsers.Validation.Provider; namespace Bit.Core.AdminConsole.OrganizationFeatures.OrganizationUsers.InviteUsers.Validation.Provider;
public class ProviderDto public class InviteOrganizationProvider
{ {
public Guid ProviderId { get; init; } public Guid ProviderId { get; init; }
public ProviderType Type { get; init; } public ProviderType Type { get; init; }
public ProviderStatusType Status { get; init; } public ProviderStatusType Status { get; init; }
public bool Enabled { 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;
} }
} }

View File

@ -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<ProviderDto> Validate(ProviderDto provider)
{
if (provider is { Enabled: true })
{
if (provider.IsBillable())
{
return new Invalid<ProviderDto>(new ProviderBillableSeatLimitError(provider));
}
if (provider.Type == ProviderType.Reseller)
{
return new Invalid<ProviderDto>(new ProviderResellerSeatLimitError(provider));
}
}
return new Valid<ProviderDto>(provider);
}
}

View File

@ -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<InviteOrganizationProvider> Validate(InviteOrganizationProvider inviteOrganizationProvider)
{
if (inviteOrganizationProvider is not { Enabled: true })
{
return new Valid<InviteOrganizationProvider>(inviteOrganizationProvider);
}
if (inviteOrganizationProvider.IsBillable())
{
return new Invalid<InviteOrganizationProvider>(new ProviderBillableSeatLimitError(inviteOrganizationProvider));
}
if (inviteOrganizationProvider.Type == ProviderType.Reseller)
{
return new Invalid<InviteOrganizationProvider>(new ProviderResellerSeatLimitError(inviteOrganizationProvider));
}
return new Valid<InviteOrganizationProvider>(inviteOrganizationProvider);
}
}

View File

@ -29,8 +29,8 @@ public static class BillingExtensions
Status: ProviderStatusType.Billable Status: ProviderStatusType.Billable
}; };
public static bool IsBillable(this ProviderDto provider) => public static bool IsBillable(this InviteOrganizationProvider inviteOrganizationProvider) =>
provider is inviteOrganizationProvider is
{ {
Type: ProviderType.Msp or ProviderType.MultiOrganizationEnterprise, Type: ProviderType.Msp or ProviderType.MultiOrganizationEnterprise,
Status: ProviderStatusType.Billable Status: ProviderStatusType.Billable