1
0
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:
Jonas Hendrickx 2024-10-01 11:08:10 +02:00 committed by GitHub
parent c94a084c86
commit 84f7cd262c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 25 additions and 6 deletions

View File

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

View File

@ -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, "")]