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

Removed unused classes

This commit is contained in:
jrmccannon 2025-03-28 09:09:44 -05:00
parent 46d36b1ef8
commit b933007f09
No known key found for this signature in database
GPG Key ID: CF03F3DB01CE96A6
4 changed files with 0 additions and 360 deletions

View File

@ -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.";
}

View File

@ -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)
};
}

View File

@ -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)
{ }
}

View File

@ -1,194 +0,0 @@
using Bit.Core.AdminConsole.Entities;
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.AdminConsole.OrganizationFeatures.OrganizationUsers.InviteUsers.Validation.SecretsManager;
using Bit.Core.AdminConsole.Shared.Validation;
using Bit.Core.Billing.Enums;
using Bit.Core.Billing.Models.StaticStore.Plans;
using Bit.Core.Enums;
using Bit.Core.Models.Data;
using Bit.Test.Common.AutoFixture.Attributes;
using Xunit;
namespace Bit.Core.Test.AdminConsole.OrganizationFeatures.OrganizationUsers.InviteUsers.Validation;
[SutProviderCustomize]
public class SecretsManagerInviteUserValidationTests
{
[Theory]
[BitAutoData]
public void Validate_GivenOrganizationDoesNotHaveSecretsManagerAndNotTryingToAddSecretsManagerUser_ThenTheRequestIsValid(
Organization organization)
{
organization.UseSecretsManager = false;
var organizationDto = new InviteOrganization(organization, new FreePlan());
var subscriptionUpdate = new PasswordManagerSubscriptionUpdate(organizationDto, 0, 0);
var request = new InviteUserOrganizationValidationRequest
{
Invites = [new OrganizationUserInvite("test@email.com", "", false)],
InviteOrganization = organizationDto,
PerformedBy = Guid.Empty,
PerformedAt = default,
OccupiedPmSeats = 0,
OccupiedSmSeats = 0
};
var update = new SecretsManagerSubscriptionUpdate(request, subscriptionUpdate);
var result = SecretsManagerInviteUserValidation.Validate(update);
Assert.IsType<Valid<SecretsManagerSubscriptionUpdate>>(result);
}
[Theory]
[BitAutoData]
public void Validate_GivenOrganizationDoesNotHaveSecretsManagerAndTryingToAddSecretsManagerUser_ThenShouldReturnInvalidMessage(
Organization organization)
{
organization.UseSecretsManager = false;
var organizationDto = new InviteOrganization(organization, new FreePlan());
var subscriptionUpdate = new PasswordManagerSubscriptionUpdate(organizationDto, 0, 0);
var invite = new OrganizationUserInvite(
email: "email@test.com",
assignedCollections: [],
groups: [],
type: OrganizationUserType.User,
permissions: new Permissions(),
externalId: string.Empty,
accessSecretsManager: true);
var request = new InviteUserOrganizationValidationRequest
{
Invites = [invite],
InviteOrganization = organizationDto,
PerformedBy = Guid.Empty,
PerformedAt = default,
OccupiedPmSeats = 0,
OccupiedSmSeats = 0
};
var update = new SecretsManagerSubscriptionUpdate(request, subscriptionUpdate);
var result = SecretsManagerInviteUserValidation.Validate(update);
Assert.IsType<Invalid<SecretsManagerSubscriptionUpdate>>(result);
Assert.Equal(OrganizationNoSecretsManagerError.Code, (result as Invalid<SecretsManagerSubscriptionUpdate>)!.ErrorMessageString);
}
[Theory]
[BitAutoData]
public void Validate_GivenOrganizationHasSecretsManagerWithoutASeatLimit_ThenShouldBeAllowedToAddSecretsManagerUsers(
Organization organization)
{
organization.SmSeats = null;
organization.UseSecretsManager = true;
var organizationDto = new InviteOrganization(organization, new FreePlan());
var subscriptionUpdate = new PasswordManagerSubscriptionUpdate(organizationDto, 0, 0);
var request = new InviteUserOrganizationValidationRequest
{
Invites = [new OrganizationUserInvite(
email: "email@test.com",
assignedCollections: [],
groups: [],
type: OrganizationUserType.User,
permissions: new Permissions(),
externalId: string.Empty,
accessSecretsManager: true)],
InviteOrganization = organizationDto,
PerformedBy = Guid.Empty,
PerformedAt = default,
OccupiedPmSeats = 0,
OccupiedSmSeats = 0
};
var update = new SecretsManagerSubscriptionUpdate(request, subscriptionUpdate);
var result = SecretsManagerInviteUserValidation.Validate(update);
Assert.IsType<Valid<SecretsManagerSubscriptionUpdate>>(result);
}
[Theory]
[BitAutoData]
public void Validate_GivenOrganizationPlanDoesNotAllowAdditionalSeats_ThenShouldNotBeAllowedToAddSecretsManagerUsers(
Organization organization)
{
organization.SmSeats = 4;
organization.MaxAutoscaleSmSeats = 4;
organization.UseSecretsManager = true;
organization.PlanType = PlanType.EnterpriseAnnually;
var organizationDto = new InviteOrganization(organization, new Enterprise2023Plan(isAnnual: true));
var subscriptionUpdate = new PasswordManagerSubscriptionUpdate(organizationDto, 0, 0);
var request = new InviteUserOrganizationValidationRequest
{
Invites = [new OrganizationUserInvite(
email: "email@test.com",
assignedCollections: [],
groups: [],
type: OrganizationUserType.User,
permissions: new Permissions(),
externalId: string.Empty,
accessSecretsManager: true)],
InviteOrganization = organizationDto,
PerformedBy = Guid.Empty,
PerformedAt = default,
OccupiedPmSeats = 0,
OccupiedSmSeats = 4
};
var update = new SecretsManagerSubscriptionUpdate(request, subscriptionUpdate);
var result = SecretsManagerInviteUserValidation.Validate(update);
Assert.IsType<Invalid<SecretsManagerSubscriptionUpdate>>(result);
Assert.Equal(SecretsManagerSeatLimitReachedError.Code, (result as Invalid<SecretsManagerSubscriptionUpdate>)!.ErrorMessageString);
}
[Theory]
[BitAutoData]
public void Validate_GivenPasswordManagerSeatsAreTheSameAsSecretsManagerSeats_WhenAttemptingToAddASecretManagerSeatOnly_ThenShouldNotBeAllowedToAddSecretsManagerUsers(
Organization organization)
{
organization.Seats = 0;
organization.SmSeats = 4;
organization.MaxAutoscaleSmSeats = 5;
organization.UseSecretsManager = true;
organization.PlanType = PlanType.EnterpriseAnnually;
var inviteOrganization = new InviteOrganization(organization, new Enterprise2023Plan(isAnnual: true));
var subscriptionUpdate = new PasswordManagerSubscriptionUpdate(inviteOrganization, 0, 0);
var request = new InviteUserOrganizationValidationRequest
{
Invites = [new OrganizationUserInvite(
email: "email@test.com",
assignedCollections: [],
groups: [],
type: OrganizationUserType.User,
permissions: new Permissions(),
externalId: string.Empty,
accessSecretsManager: true)],
InviteOrganization = inviteOrganization,
PerformedBy = Guid.Empty,
PerformedAt = default,
OccupiedPmSeats = 0,
OccupiedSmSeats = 4
};
var update = new SecretsManagerSubscriptionUpdate(request, subscriptionUpdate);
var result = SecretsManagerInviteUserValidation.Validate(update);
Assert.IsType<Invalid<SecretsManagerSubscriptionUpdate>>(result);
Assert.Equal(SecretsManagerCannotExceedPasswordManagerError.Code, (result as Invalid<SecretsManagerSubscriptionUpdate>)!.ErrorMessageString);
}
}