1
0
mirror of https://github.com/bitwarden/server.git synced 2025-07-01 16:12:49 -05:00

api endpoints for seats, upgrade, and cancel org

This commit is contained in:
Kyle Spearrin
2017-04-10 11:49:53 -04:00
parent f8baf3abb3
commit ce93d4b07e
5 changed files with 76 additions and 6 deletions

View File

@ -175,7 +175,7 @@ namespace Bit.Core.Services
}
}
public async Task UpgradePlanAsync(Guid organizationId, PlanType plan, short additionalSeats)
public async Task UpgradePlanAsync(Guid organizationId, PlanType plan, int additionalSeats)
{
var organization = await _organizationRepository.GetByIdAsync(organizationId);
if(organization == null)
@ -300,7 +300,7 @@ namespace Bit.Core.Services
}
}
public async Task AdjustAdditionalSeatsAsync(Guid organizationId, short additionalSeats)
public async Task AdjustSeatsAsync(Guid organizationId, int seatAdjustment)
{
var organization = await _organizationRepository.GetByIdAsync(organizationId);
if(organization == null)
@ -329,20 +329,26 @@ namespace Bit.Core.Services
throw new BadRequestException("Plan does not allow additional seats.");
}
var newSeatTotal = organization.Seats + seatAdjustment;
if(plan.BaseSeats > newSeatTotal)
{
throw new BadRequestException($"Plan has a minimum of {plan.BaseSeats} seats.");
}
var additionalSeats = newSeatTotal - plan.BaseSeats;
if(plan.MaxAdditionalSeats.HasValue && additionalSeats > plan.MaxAdditionalSeats.Value)
{
throw new BadRequestException($"Organization plan allows a maximum of " +
$"{plan.MaxAdditionalSeats.Value} additional seats.");
}
var planNewSeats = (short)(plan.BaseSeats + additionalSeats);
if(!organization.Seats.HasValue || organization.Seats.Value > planNewSeats)
if(!organization.Seats.HasValue || organization.Seats.Value > newSeatTotal)
{
var userCount = await _organizationUserRepository.GetCountByOrganizationIdAsync(organization.Id);
if(userCount >= planNewSeats)
if(userCount > newSeatTotal)
{
throw new BadRequestException($"Your organization currently has {userCount} seats filled. Your new plan " +
$"only has ({planNewSeats}) seats. Remove some users.");
$"only has ({newSeatTotal}) seats. Remove some users.");
}
}