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

[AC-2420] Fix customer discount ID and SM invite validation (#3966)

* Fix customer discount ID and SM update validation

* Replace constructor needed for autofixture
This commit is contained in:
Alex Morask 2024-04-18 11:11:37 -04:00 committed by GitHub
parent 49ed5af517
commit 9827ee5f6a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 17 additions and 25 deletions

View File

@ -43,20 +43,12 @@ public class SubscriptionResponseModel : ResponseModel
public DateTime? Expiration { get; set; } public DateTime? Expiration { get; set; }
} }
public class BillingCustomerDiscount public class BillingCustomerDiscount(SubscriptionInfo.BillingCustomerDiscount discount)
{ {
public BillingCustomerDiscount(SubscriptionInfo.BillingCustomerDiscount discount) public string Id { get; } = discount.Id;
{ public bool Active { get; } = discount.Active;
Id = discount.Id; public decimal? PercentOff { get; } = discount.PercentOff;
Active = discount.Active; public List<string> AppliesTo { get; } = discount.AppliesTo;
PercentOff = discount.PercentOff;
AppliesTo = discount.AppliesTo;
}
public string Id { get; }
public bool Active { get; }
public decimal? PercentOff { get; }
public List<string> AppliesTo { get; }
} }
public class BillingSubscription public class BillingSubscription

View File

@ -1037,7 +1037,6 @@ public class OrganizationService : IOrganizationService
{ {
smSubscriptionUpdate = new SecretsManagerSubscriptionUpdate(organization, true) smSubscriptionUpdate = new SecretsManagerSubscriptionUpdate(organization, true)
.AdjustSeats(additionalSmSeatsRequired); .AdjustSeats(additionalSmSeatsRequired);
await _updateSecretsManagerSubscriptionCommand.ValidateUpdate(smSubscriptionUpdate);
} }
var invitedAreAllOwners = invites.All(i => i.invite.Type == OrganizationUserType.Owner); var invitedAreAllOwners = invites.All(i => i.invite.Type == OrganizationUserType.Owner);
@ -1133,12 +1132,14 @@ public class OrganizationService : IOrganizationService
throw new BadRequestException("Cannot add seats. Cannot manage organization users."); throw new BadRequestException("Cannot add seats. Cannot manage organization users.");
} }
await AutoAddSeatsAsync(organization, newSeatsRequired, prorationDate);
if (additionalSmSeatsRequired > 0) if (additionalSmSeatsRequired > 0)
{ {
smSubscriptionUpdate.ProrationDate = prorationDate; smSubscriptionUpdate.ProrationDate = prorationDate;
await _updateSecretsManagerSubscriptionCommand.UpdateSubscriptionAsync(smSubscriptionUpdate); await _updateSecretsManagerSubscriptionCommand.UpdateSubscriptionAsync(smSubscriptionUpdate);
} }
await AutoAddSeatsAsync(organization, newSeatsRequired, prorationDate);
await SendInvitesAsync(orgUsers.Concat(limitedCollectionOrgUsers.Select(u => u.Item1)), organization); await SendInvitesAsync(orgUsers.Concat(limitedCollectionOrgUsers.Select(u => u.Item1)), organization);
await _referenceEventService.RaiseEventAsync( await _referenceEventService.RaiseEventAsync(

View File

@ -14,16 +14,16 @@ public class SubscriptionInfo
public BillingCustomerDiscount(Discount discount) public BillingCustomerDiscount(Discount discount)
{ {
Id = discount.Id; Id = discount.Coupon?.Id;
Active = discount.Start != null && discount.End == null; Active = discount.End == null;
PercentOff = discount.Coupon?.PercentOff; PercentOff = discount.Coupon?.PercentOff;
AppliesTo = discount.Coupon?.AppliesTo?.Products ?? new List<string>(); AppliesTo = discount.Coupon?.AppliesTo?.Products ?? [];
} }
public string Id { get; } public string Id { get; set; }
public bool Active { get; } public bool Active { get; set; }
public decimal? PercentOff { get; } public decimal? PercentOff { get; set; }
public List<string> AppliesTo { get; } public List<string> AppliesTo { get; set; }
} }
public class BillingSubscription public class BillingSubscription

View File

@ -5,5 +5,4 @@ namespace Bit.Core.OrganizationFeatures.OrganizationSubscriptions.Interface;
public interface IUpdateSecretsManagerSubscriptionCommand public interface IUpdateSecretsManagerSubscriptionCommand
{ {
Task UpdateSubscriptionAsync(SecretsManagerSubscriptionUpdate update); Task UpdateSubscriptionAsync(SecretsManagerSubscriptionUpdate update);
Task ValidateUpdate(SecretsManagerSubscriptionUpdate update);
} }

View File

@ -47,7 +47,7 @@ public class UpdateSecretsManagerSubscriptionCommand : IUpdateSecretsManagerSubs
public async Task UpdateSubscriptionAsync(SecretsManagerSubscriptionUpdate update) public async Task UpdateSubscriptionAsync(SecretsManagerSubscriptionUpdate update)
{ {
await ValidateUpdate(update); await ValidateUpdateAsync(update);
await FinalizeSubscriptionAdjustmentAsync(update); await FinalizeSubscriptionAdjustmentAsync(update);
@ -123,7 +123,7 @@ public class UpdateSecretsManagerSubscriptionCommand : IUpdateSecretsManagerSubs
} }
public async Task ValidateUpdate(SecretsManagerSubscriptionUpdate update) private async Task ValidateUpdateAsync(SecretsManagerSubscriptionUpdate update)
{ {
if (_globalSettings.SelfHosted) if (_globalSettings.SelfHosted)
{ {