mirror of
https://github.com/bitwarden/server.git
synced 2025-07-19 08:30:59 -05:00
Removed unused classes
This commit is contained in:
@ -1,32 +0,0 @@
|
||||
using Bit.Core.AdminConsole.Errors;
|
||||
|
||||
namespace Bit.Core.AdminConsole.OrganizationFeatures.OrganizationUsers.InviteUsers.Validation.SecretsManager;
|
||||
|
||||
public record OrganizationNoSecretsManagerError(SecretsManagerSubscriptionUpdate InvalidRequest)
|
||||
: Error<SecretsManagerSubscriptionUpdate>(Code, InvalidRequest)
|
||||
{
|
||||
public const string Code = "Organization has no access to Secrets Manager";
|
||||
}
|
||||
|
||||
public record SecretsManagerAdditionalSeatLimitReachedError(SecretsManagerSubscriptionUpdate InvalidRequest)
|
||||
: Error<SecretsManagerSubscriptionUpdate>(GetErrorMessage(InvalidRequest), InvalidRequest)
|
||||
{
|
||||
public const string Code = "You have reached the maximum number of Secrets Manager seats ({0}) for this plan.";
|
||||
|
||||
public static string GetErrorMessage(SecretsManagerSubscriptionUpdate invalidRequest) =>
|
||||
string.Format(Code,
|
||||
invalidRequest.SecretsManagerPlan.BaseSeats +
|
||||
invalidRequest.SecretsManagerPlan.MaxAdditionalSeats.GetValueOrDefault());
|
||||
}
|
||||
|
||||
public record SecretsManagerSeatLimitReachedError(SecretsManagerSubscriptionUpdate InvalidRequest)
|
||||
: Error<SecretsManagerSubscriptionUpdate>(Code, InvalidRequest)
|
||||
{
|
||||
public const string Code = "Secrets Manager seat limit has been reached.";
|
||||
}
|
||||
|
||||
public record SecretsManagerCannotExceedPasswordManagerError(SecretsManagerSubscriptionUpdate InvalidRequest)
|
||||
: Error<SecretsManagerSubscriptionUpdate>(Code, InvalidRequest)
|
||||
{
|
||||
public const string Code = "You cannot have more Secrets Manager seats than Password Manager seats.";
|
||||
}
|
@ -1,43 +0,0 @@
|
||||
using Bit.Core.AdminConsole.Shared.Validation;
|
||||
|
||||
namespace Bit.Core.AdminConsole.OrganizationFeatures.OrganizationUsers.InviteUsers.Validation.SecretsManager;
|
||||
|
||||
public static class SecretsManagerInviteUserValidation
|
||||
{
|
||||
public static ValidationResult<SecretsManagerSubscriptionUpdate> Validate(
|
||||
SecretsManagerSubscriptionUpdate subscriptionUpdate) =>
|
||||
subscriptionUpdate switch
|
||||
{
|
||||
{ UseSecretsManger: false, NewUsersToAdd: > 0 } =>
|
||||
new Invalid<SecretsManagerSubscriptionUpdate>(
|
||||
new OrganizationNoSecretsManagerError(subscriptionUpdate)),
|
||||
|
||||
{ UseSecretsManger: false, NewUsersToAdd: 0 } or { UseSecretsManger: true, Seats: null } =>
|
||||
new Valid<SecretsManagerSubscriptionUpdate>(subscriptionUpdate),
|
||||
|
||||
{ UseSecretsManger: true, SecretsManagerPlan.HasAdditionalSeatsOption: false } =>
|
||||
new Invalid<SecretsManagerSubscriptionUpdate>(
|
||||
new SecretsManagerAdditionalSeatLimitReachedError(subscriptionUpdate)),
|
||||
|
||||
{ UseSecretsManger: true, SecretsManagerPlan.MaxAdditionalSeats: var planMaxSeats }
|
||||
when planMaxSeats < subscriptionUpdate.NewUsersToAdd =>
|
||||
new Invalid<SecretsManagerSubscriptionUpdate>(
|
||||
new SecretsManagerAdditionalSeatLimitReachedError(subscriptionUpdate)),
|
||||
|
||||
{ UseSecretsManger: true, UpdatedSeatTotal: var updateSeatTotal, MaxAutoScaleSeats: var maxAutoScaleSeats }
|
||||
when updateSeatTotal > maxAutoScaleSeats =>
|
||||
new Invalid<SecretsManagerSubscriptionUpdate>(
|
||||
new SecretsManagerSeatLimitReachedError(subscriptionUpdate)),
|
||||
|
||||
{
|
||||
UseSecretsManger: true,
|
||||
PasswordManagerUpdatedSeatTotal: var passwordManagerUpdatedSeatTotal,
|
||||
UpdatedSeatTotal: var secretsManagerUpdatedSeatTotal
|
||||
}
|
||||
when passwordManagerUpdatedSeatTotal < secretsManagerUpdatedSeatTotal =>
|
||||
new Invalid<SecretsManagerSubscriptionUpdate>(
|
||||
new SecretsManagerCannotExceedPasswordManagerError(subscriptionUpdate)),
|
||||
|
||||
_ => new Valid<SecretsManagerSubscriptionUpdate>(subscriptionUpdate)
|
||||
};
|
||||
}
|
@ -1,91 +0,0 @@
|
||||
using Bit.Core.AdminConsole.Models.Business;
|
||||
using Bit.Core.AdminConsole.OrganizationFeatures.OrganizationUsers.InviteUsers.Models;
|
||||
using Bit.Core.AdminConsole.OrganizationFeatures.OrganizationUsers.InviteUsers.Validation.PasswordManager;
|
||||
using Bit.Core.Models.StaticStore;
|
||||
|
||||
namespace Bit.Core.AdminConsole.OrganizationFeatures.OrganizationUsers.InviteUsers.Validation.SecretsManager;
|
||||
|
||||
public class SecretsManagerSubscriptionUpdate
|
||||
{
|
||||
public bool UseSecretsManger { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Seats the organization has
|
||||
/// </summary>
|
||||
public int? Seats { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Max number of seats that the organization can have
|
||||
/// </summary>
|
||||
public int? MaxAutoScaleSeats { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Seats currently occupied by current users
|
||||
/// </summary>
|
||||
public int OccupiedSeats { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Users to add to the organization seats
|
||||
/// </summary>
|
||||
public int NewUsersToAdd { get; }
|
||||
|
||||
public int? PasswordManagerUpdatedSeatTotal { get; }
|
||||
public Plan.SecretsManagerPlanFeatures SecretsManagerPlan { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Number of seats available for users
|
||||
/// </summary>
|
||||
public int? AvailableSeats => Seats - OccupiedSeats;
|
||||
|
||||
/// <summary>
|
||||
/// Number of seats to scale the organization to.
|
||||
///
|
||||
/// If Organization has no seat limit (Seats is null), then there are no new seats to add.
|
||||
/// </summary>
|
||||
public int SeatsRequiredToAdd => AvailableSeats.HasValue ? Math.Max(NewUsersToAdd - AvailableSeats.Value, 0) : 0;
|
||||
|
||||
/// <summary>
|
||||
/// New total of seats for the organization
|
||||
/// </summary>
|
||||
public int? UpdatedSeatTotal => Seats + SeatsRequiredToAdd;
|
||||
|
||||
private SecretsManagerSubscriptionUpdate(bool useSecretsManger,
|
||||
int? organizationSeats,
|
||||
int? organizationAutoScaleSeatLimit,
|
||||
int currentSeats,
|
||||
int seatsToAdd,
|
||||
int? passwordManagerUpdatedSeatTotal,
|
||||
Plan.SecretsManagerPlanFeatures plan)
|
||||
{
|
||||
UseSecretsManger = useSecretsManger;
|
||||
Seats = organizationSeats;
|
||||
MaxAutoScaleSeats = organizationAutoScaleSeatLimit;
|
||||
OccupiedSeats = currentSeats;
|
||||
NewUsersToAdd = seatsToAdd;
|
||||
PasswordManagerUpdatedSeatTotal = passwordManagerUpdatedSeatTotal;
|
||||
SecretsManagerPlan = plan;
|
||||
}
|
||||
|
||||
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 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)
|
||||
{ }
|
||||
}
|
Reference in New Issue
Block a user