mirror of
https://github.com/bitwarden/server.git
synced 2025-02-07 00:21:32 +01:00
[PM-12526] Can Reduce Org's PM seats to be lower than SM seats (#4796)
This commit is contained in:
parent
c94a084c86
commit
84f7cd262c
@ -358,6 +358,11 @@ public class OrganizationService : IOrganizationService
|
||||
}
|
||||
}
|
||||
|
||||
if (organization.UseSecretsManager && organization.Seats + seatAdjustment < organization.SmSeats)
|
||||
{
|
||||
throw new BadRequestException("You cannot have more Secrets Manager seats than Password Manager seats.");
|
||||
}
|
||||
|
||||
var paymentIntentClientSecret = await _paymentService.AdjustSeatsAsync(organization, plan, additionalSeats);
|
||||
await _referenceEventService.RaiseEventAsync(
|
||||
new ReferenceEvent(ReferenceEventType.AdjustSeats, organization, _currentContext)
|
||||
@ -1186,12 +1191,7 @@ public class OrganizationService : IOrganizationService
|
||||
var currentOrganization = await _organizationRepository.GetByIdAsync(organization.Id);
|
||||
|
||||
// Revert autoscaling
|
||||
if (initialSeatCount.HasValue && currentOrganization.Seats.HasValue && currentOrganization.Seats.Value != initialSeatCount.Value)
|
||||
{
|
||||
await AdjustSeatsAsync(organization, initialSeatCount.Value - currentOrganization.Seats.Value);
|
||||
}
|
||||
|
||||
// Revert SmSeat autoscaling
|
||||
// Do this first so that SmSeats never exceed PM seats (due to current billing requirements)
|
||||
if (initialSmSeatCount.HasValue && currentOrganization.SmSeats.HasValue &&
|
||||
currentOrganization.SmSeats.Value != initialSmSeatCount.Value)
|
||||
{
|
||||
@ -1202,6 +1202,11 @@ public class OrganizationService : IOrganizationService
|
||||
await _updateSecretsManagerSubscriptionCommand.UpdateSubscriptionAsync(smSubscriptionUpdateRevert);
|
||||
}
|
||||
|
||||
if (initialSeatCount.HasValue && currentOrganization.Seats.HasValue && currentOrganization.Seats.Value != initialSeatCount.Value)
|
||||
{
|
||||
await AdjustSeatsAsync(organization, initialSeatCount.Value - currentOrganization.Seats.Value);
|
||||
}
|
||||
|
||||
exceptions.Add(e);
|
||||
}
|
||||
|
||||
|
@ -1866,6 +1866,20 @@ OrganizationUserInvite invite, SutProvider<OrganizationService> sutProvider)
|
||||
await Assert.ThrowsAsync<NotFoundException>(() => sutProvider.Sut.UpdateSubscription(organizationId, 0, null));
|
||||
}
|
||||
|
||||
[Theory, SecretsManagerOrganizationCustomize]
|
||||
[BitAutoData("You cannot have more Secrets Manager seats than Password Manager seats.", -1)]
|
||||
public async Task UpdateSubscription_PmSeatAdjustmentLessThanSmSeats_Throws(string expectedMessage,
|
||||
int seatAdjustment, Organization organization, SutProvider<OrganizationService> sutProvider)
|
||||
{
|
||||
organization.Seats = 100;
|
||||
organization.SmSeats = 100;
|
||||
|
||||
sutProvider.GetDependency<IOrganizationRepository>().GetByIdAsync(organization.Id).Returns(organization);
|
||||
|
||||
var actual = await Assert.ThrowsAsync<BadRequestException>(() => sutProvider.Sut.UpdateSubscription(organization.Id, seatAdjustment, null));
|
||||
Assert.Contains(expectedMessage, actual.Message);
|
||||
}
|
||||
|
||||
[Theory, PaidOrganizationCustomize]
|
||||
[BitAutoData(0, 100, null, true, "")]
|
||||
[BitAutoData(0, 100, 100, true, "")]
|
||||
|
Loading…
Reference in New Issue
Block a user