mirror of
https://github.com/bitwarden/server.git
synced 2025-04-22 21:45:15 -05:00
Corrected the number sent to stripe. Corrected the test. (#5667)
This commit is contained in:
parent
dc758c5176
commit
159e4fe502
@ -159,13 +159,13 @@ public class InviteOrganizationUsersCommand(IEventService eventService,
|
|||||||
|
|
||||||
private async Task RevertPasswordManagerChangesAsync(Valid<InviteOrganizationUsersValidationRequest> validatedResult, Organization organization)
|
private async Task RevertPasswordManagerChangesAsync(Valid<InviteOrganizationUsersValidationRequest> validatedResult, Organization organization)
|
||||||
{
|
{
|
||||||
if (validatedResult.Value.PasswordManagerSubscriptionUpdate.SeatsRequiredToAdd > 0)
|
if (validatedResult.Value.PasswordManagerSubscriptionUpdate is { Seats: > 0, SeatsRequiredToAdd: > 0 })
|
||||||
{
|
{
|
||||||
// When reverting seats, we have to tell payments service that the seats are going back down by what we attempted to add.
|
|
||||||
// However, this might lead to a problem if we don't actually update stripe but throw any ways.
|
|
||||||
// stripe could not be updated, and then we would decrement the number of seats in stripe accidentally.
|
await paymentService.AdjustSeatsAsync(organization,
|
||||||
var seatsToRemove = validatedResult.Value.PasswordManagerSubscriptionUpdate.SeatsRequiredToAdd;
|
validatedResult.Value.InviteOrganization.Plan,
|
||||||
await paymentService.AdjustSeatsAsync(organization, validatedResult.Value.InviteOrganization.Plan, -seatsToRemove);
|
validatedResult.Value.PasswordManagerSubscriptionUpdate.Seats.Value);
|
||||||
|
|
||||||
organization.Seats = (short?)validatedResult.Value.PasswordManagerSubscriptionUpdate.Seats;
|
organization.Seats = (short?)validatedResult.Value.PasswordManagerSubscriptionUpdate.Seats;
|
||||||
|
|
||||||
@ -274,25 +274,25 @@ public class InviteOrganizationUsersCommand(IEventService eventService,
|
|||||||
|
|
||||||
private async Task AdjustPasswordManagerSeatsAsync(Valid<InviteOrganizationUsersValidationRequest> validatedResult, Organization organization)
|
private async Task AdjustPasswordManagerSeatsAsync(Valid<InviteOrganizationUsersValidationRequest> validatedResult, Organization organization)
|
||||||
{
|
{
|
||||||
if (validatedResult.Value.PasswordManagerSubscriptionUpdate.SeatsRequiredToAdd <= 0)
|
if (validatedResult.Value.PasswordManagerSubscriptionUpdate is { SeatsRequiredToAdd: > 0, UpdatedSeatTotal: > 0 })
|
||||||
{
|
{
|
||||||
return;
|
await paymentService.AdjustSeatsAsync(organization,
|
||||||
|
validatedResult.Value.InviteOrganization.Plan,
|
||||||
|
validatedResult.Value.PasswordManagerSubscriptionUpdate.UpdatedSeatTotal.Value);
|
||||||
|
|
||||||
|
organization.Seats = (short?)validatedResult.Value.PasswordManagerSubscriptionUpdate.UpdatedSeatTotal;
|
||||||
|
|
||||||
|
await organizationRepository.ReplaceAsync(organization); // could optimize this with only a property update
|
||||||
|
await applicationCacheService.UpsertOrganizationAbilityAsync(organization);
|
||||||
|
|
||||||
|
await referenceEventService.RaiseEventAsync(
|
||||||
|
new ReferenceEvent(ReferenceEventType.AdjustSeats, organization, currentContext)
|
||||||
|
{
|
||||||
|
PlanName = validatedResult.Value.InviteOrganization.Plan.Name,
|
||||||
|
PlanType = validatedResult.Value.InviteOrganization.Plan.Type,
|
||||||
|
Seats = validatedResult.Value.PasswordManagerSubscriptionUpdate.UpdatedSeatTotal,
|
||||||
|
PreviousSeats = validatedResult.Value.PasswordManagerSubscriptionUpdate.Seats
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
await paymentService.AdjustSeatsAsync(organization, validatedResult.Value.InviteOrganization.Plan, validatedResult.Value.PasswordManagerSubscriptionUpdate.SeatsRequiredToAdd);
|
|
||||||
|
|
||||||
organization.Seats = (short?)validatedResult.Value.PasswordManagerSubscriptionUpdate.UpdatedSeatTotal;
|
|
||||||
|
|
||||||
await organizationRepository.ReplaceAsync(organization); // could optimize this with only a property update
|
|
||||||
await applicationCacheService.UpsertOrganizationAbilityAsync(organization);
|
|
||||||
|
|
||||||
await referenceEventService.RaiseEventAsync(
|
|
||||||
new ReferenceEvent(ReferenceEventType.AdjustSeats, organization, currentContext)
|
|
||||||
{
|
|
||||||
PlanName = validatedResult.Value.InviteOrganization.Plan.Name,
|
|
||||||
PlanType = validatedResult.Value.InviteOrganization.Plan.Type,
|
|
||||||
Seats = validatedResult.Value.PasswordManagerSubscriptionUpdate.UpdatedSeatTotal,
|
|
||||||
PreviousSeats = validatedResult.Value.PasswordManagerSubscriptionUpdate.Seats
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -420,7 +420,7 @@ public class InviteOrganizationUserCommandTests
|
|||||||
Assert.IsType<Success<ScimInviteOrganizationUsersResponse>>(result);
|
Assert.IsType<Success<ScimInviteOrganizationUsersResponse>>(result);
|
||||||
|
|
||||||
await sutProvider.GetDependency<IPaymentService>()
|
await sutProvider.GetDependency<IPaymentService>()
|
||||||
.AdjustSeatsAsync(organization, inviteOrganization.Plan, passwordManagerUpdate.SeatsRequiredToAdd);
|
.AdjustSeatsAsync(organization, inviteOrganization.Plan, passwordManagerUpdate.UpdatedSeatTotal!.Value);
|
||||||
|
|
||||||
await orgRepository.Received(1).ReplaceAsync(Arg.Is<Organization>(x => x.Seats == passwordManagerUpdate.UpdatedSeatTotal));
|
await orgRepository.Received(1).ReplaceAsync(Arg.Is<Organization>(x => x.Seats == passwordManagerUpdate.UpdatedSeatTotal));
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user