1
0
mirror of https://github.com/bitwarden/server synced 2025-12-27 21:53:24 +00:00

Resolved an issue where autoscaling always happened (#5765)

This commit is contained in:
Conner Turnbull
2025-05-02 12:53:06 -04:00
committed by GitHub
parent cd3f16948b
commit 077d0fa6d7
4 changed files with 145 additions and 4 deletions

View File

@@ -15,7 +15,8 @@ public class CreateSponsorshipCommand(
ICurrentContext currentContext,
IOrganizationSponsorshipRepository organizationSponsorshipRepository,
IUserService userService,
IOrganizationService organizationService) : ICreateSponsorshipCommand
IOrganizationService organizationService,
IOrganizationUserRepository organizationUserRepository) : ICreateSponsorshipCommand
{
public async Task<OrganizationSponsorship> CreateSponsorshipAsync(
Organization sponsoringOrganization,
@@ -82,14 +83,26 @@ public class CreateSponsorshipCommand(
if (existingOrgSponsorship != null)
{
// Replace existing invalid offer with our new sponsorship offer
sponsorship.Id = existingOrgSponsorship.Id;
}
}
if (isAdminInitiated && sponsoringOrganization.Seats.HasValue)
{
await organizationService.AutoAddSeatsAsync(sponsoringOrganization, 1);
var occupiedSeats = await organizationUserRepository.GetOccupiedSeatCountByOrganizationIdAsync(sponsoringOrganization.Id);
var availableSeats = sponsoringOrganization.Seats.Value - occupiedSeats;
if (availableSeats <= 0)
{
var newSeatsRequired = 1;
var (canScale, failureReason) = await organizationService.CanScaleAsync(sponsoringOrganization, newSeatsRequired);
if (!canScale)
{
throw new BadRequestException(failureReason);
}
await organizationService.AutoAddSeatsAsync(sponsoringOrganization, newSeatsRequired);
}
}
try