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

implement the seat decrease error message

This commit is contained in:
Cy Okeke 2025-05-19 16:11:10 +01:00
parent b3f7265129
commit f62a3e2735
No known key found for this signature in database
GPG Key ID: 88B341B55C84B45C

View File

@ -342,11 +342,15 @@ public class OrganizationService : IOrganizationService
if (!organization.Seats.HasValue || organization.Seats.Value > newSeatTotal)
{
var occupiedSeats = await _organizationUserRepository.GetOccupiedSeatCountByOrganizationIdAsync(organization.Id);
if (occupiedSeats > newSeatTotal)
var totalConsumedSeats = await _organizationUserRepository.GetOccupiedSeatCountByOrganizationIdAsync(organization.Id);
var organizationUsers = await _organizationUserRepository.GetManyByOrganizationAsync(organization.Id, null);
var organizationUserOccupiedSeats = organizationUsers.Where(user => user.Status >= 0).Count();
var sponsoredFamiliesOccupiedSeats = totalConsumedSeats - organizationUserOccupiedSeats;
if (totalConsumedSeats > newSeatTotal)
{
throw new BadRequestException($"Your organization currently has {occupiedSeats} seats filled. " +
$"Your new plan only has ({newSeatTotal}) seats. Remove some users.");
throw new BadRequestException($"Your organization has {organizationUserOccupiedSeats} members and {sponsoredFamiliesOccupiedSeats} sponsored families. " +
$"To decrease the seat count below {totalConsumedSeats}, you must remove members or sponsorships.");
}
}