diff --git a/src/Core/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/Validation/InviteOrganizationUserValidator.cs b/src/Core/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/Validation/InviteOrganizationUserValidator.cs index c2919253ca..6e52321460 100644 --- a/src/Core/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/Validation/InviteOrganizationUserValidator.cs +++ b/src/Core/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/Validation/InviteOrganizationUserValidator.cs @@ -82,7 +82,7 @@ public class InviteUsersValidator( } public static ValidationResult ValidateEnvironment(IGlobalSettings globalSettings, Valid subscriptionUpdate) => - globalSettings.SelfHosted && subscriptionUpdate?.Value.AdditionalSeats > 0 + globalSettings.SelfHosted && subscriptionUpdate?.Value.SeatsRequiredToAdd > 0 ? new Invalid(new CannotAutoScaleOnSelfHostError(globalSettings)) : new Valid(globalSettings); } diff --git a/src/Core/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/Validation/PasswordManager/PasswordManagerInviteUserValidator.cs b/src/Core/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/Validation/PasswordManager/PasswordManagerInviteUserValidator.cs index 4d6940c6c7..db72e7cd23 100644 --- a/src/Core/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/Validation/PasswordManager/PasswordManagerInviteUserValidator.cs +++ b/src/Core/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/Validation/PasswordManager/PasswordManagerInviteUserValidator.cs @@ -16,7 +16,7 @@ public static class PasswordManagerInviteUserValidator return new Valid(subscriptionUpdate); } - if (subscriptionUpdate.AdditionalSeats == 0) + if (subscriptionUpdate.NewUsersToAdd == 0) { return new Valid(subscriptionUpdate); } @@ -35,7 +35,7 @@ public static class PasswordManagerInviteUserValidator } // Apparently MaxAdditionalSeats is never set. Can probably be removed. - if (subscriptionUpdate.AdditionalSeats > subscriptionUpdate.PasswordManagerPlan.MaxAdditionalSeats) + if (subscriptionUpdate.NewUsersToAdd > subscriptionUpdate.PasswordManagerPlan.MaxAdditionalSeats) { return new Invalid( new PasswordManagerPlanOnlyAllowsMaxAdditionalSeatsError(subscriptionUpdate)); diff --git a/src/Core/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/Validation/PasswordManager/PasswordManagerSubscriptionUpdate.cs b/src/Core/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/Validation/PasswordManager/PasswordManagerSubscriptionUpdate.cs index 257c7b3217..f740be0f8f 100644 --- a/src/Core/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/Validation/PasswordManager/PasswordManagerSubscriptionUpdate.cs +++ b/src/Core/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/Validation/PasswordManager/PasswordManagerSubscriptionUpdate.cs @@ -7,22 +7,45 @@ namespace Bit.Core.AdminConsole.OrganizationFeatures.OrganizationUsers.InviteUse public class PasswordManagerSubscriptionUpdate { /// - /// Seats the organization has + /// Seats the organization is currently paying for /// public int? Seats { get; } + /// + /// Max number of seats that the organization can have + /// public int? MaxAutoScaleSeats { get; } + /// + /// Seats currently occupied by current users + /// public int OccupiedSeats { get; } - public int AdditionalSeats { get; } + /// + /// Users to add to the organization seats + /// + public int NewUsersToAdd { get; } + /// + /// Number of seats available for users + /// public int? AvailableSeats => Seats - OccupiedSeats; - public int SeatsRequiredToAdd => AdditionalSeats - AvailableSeats ?? 0; + /// + /// 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. + /// + public int SeatsRequiredToAdd => AvailableSeats.HasValue ? Math.Max(NewUsersToAdd - AvailableSeats.Value, 0) : 0; + /// + /// New total of seats for the organization + /// public int? UpdatedSeatTotal => Seats + SeatsRequiredToAdd; + /// + /// If the new seat total is equal to the organization's auto-scale seat count + /// public bool MaxSeatsReached => UpdatedSeatTotal.HasValue && MaxAutoScaleSeats.HasValue && UpdatedSeatTotal.Value == MaxAutoScaleSeats.Value; public Plan.PasswordManagerPlanFeatures PasswordManagerPlan { get; } @@ -30,22 +53,22 @@ public class PasswordManagerSubscriptionUpdate private PasswordManagerSubscriptionUpdate(int? organizationSeats, int? organizationAutoScaleSeatLimit, int currentSeats, - int seatsToAdd, + int newUsersToAdd, Plan.PasswordManagerPlanFeatures plan) { Seats = organizationSeats; MaxAutoScaleSeats = organizationAutoScaleSeatLimit; OccupiedSeats = currentSeats; - AdditionalSeats = seatsToAdd; + NewUsersToAdd = newUsersToAdd; PasswordManagerPlan = plan; } - public PasswordManagerSubscriptionUpdate(InviteOrganization inviteOrganization, int occupiedSeats, int seatsToAdd) : + public PasswordManagerSubscriptionUpdate(InviteOrganization inviteOrganization, int occupiedSeats, int newUsersToAdd) : this( organizationSeats: inviteOrganization.Seats, organizationAutoScaleSeatLimit: inviteOrganization.MaxAutoScaleSeats, currentSeats: occupiedSeats, - seatsToAdd: seatsToAdd, + newUsersToAdd: newUsersToAdd, plan: inviteOrganization.Plan.PasswordManager) { } @@ -54,7 +77,7 @@ public class PasswordManagerSubscriptionUpdate organizationSeats: validationRequest.InviteOrganization.Seats, organizationAutoScaleSeatLimit: validationRequest.InviteOrganization.MaxAutoScaleSeats, currentSeats: validationRequest.OccupiedPmSeats, - seatsToAdd: validationRequest.Invites.Length, + newUsersToAdd: validationRequest.Invites.Length, plan: validationRequest.InviteOrganization.Plan.PasswordManager) { } }