Skip to content

Commit e615bf4

Browse files
authored
Merge branch 'main' into SM-1592-API
2 parents d23c582 + de90108 commit e615bf4

File tree

7 files changed

+140
-107
lines changed

7 files changed

+140
-107
lines changed

src/Core/Billing/Organizations/Queries/GetOrganizationMetadataQuery.cs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,6 @@ public class GetOrganizationMetadataQuery(
2222
{
2323
public async Task<OrganizationMetadata?> Run(Organization organization)
2424
{
25-
if (organization == null)
26-
{
27-
return null;
28-
}
29-
3025
if (globalSettings.SelfHosted)
3126
{
3227
return OrganizationMetadata.Default;
@@ -42,10 +37,12 @@ public class GetOrganizationMetadataQuery(
4237
};
4338
}
4439

45-
var customer = await subscriberService.GetCustomer(organization,
46-
new CustomerGetOptions { Expand = ["discount.coupon.applies_to"] });
40+
var customer = await subscriberService.GetCustomer(organization);
4741

48-
var subscription = await subscriberService.GetSubscription(organization);
42+
var subscription = await subscriberService.GetSubscription(organization, new SubscriptionGetOptions
43+
{
44+
Expand = ["discounts.coupon.applies_to"]
45+
});
4946

5047
if (customer == null || subscription == null)
5148
{
@@ -79,16 +76,17 @@ private async Task<bool> IsOnSecretsManagerStandalone(
7976
return false;
8077
}
8178

82-
var hasCoupon = customer.Discount?.Coupon?.Id == StripeConstants.CouponIDs.SecretsManagerStandalone;
79+
var coupon = subscription.Discounts?.FirstOrDefault(discount =>
80+
discount.Coupon?.Id == StripeConstants.CouponIDs.SecretsManagerStandalone)?.Coupon;
8381

84-
if (!hasCoupon)
82+
if (coupon == null)
8583
{
8684
return false;
8785
}
8886

8987
var subscriptionProductIds = subscription.Items.Data.Select(item => item.Plan.ProductId);
9088

91-
var couponAppliesTo = customer.Discount?.Coupon?.AppliesTo?.Products;
89+
var couponAppliesTo = coupon.AppliesTo?.Products;
9290

9391
return subscriptionProductIds.Intersect(couponAppliesTo ?? []).Any();
9492
}

src/Core/Billing/Organizations/Services/OrganizationBillingService.cs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,12 @@ public async Task Finalize(OrganizationSale sale)
7979
};
8080
}
8181

82-
var customer = await subscriberService.GetCustomer(organization,
83-
new CustomerGetOptions { Expand = ["discount.coupon.applies_to"] });
82+
var customer = await subscriberService.GetCustomer(organization);
8483

85-
var subscription = await subscriberService.GetSubscription(organization);
84+
var subscription = await subscriberService.GetSubscription(organization, new SubscriptionGetOptions
85+
{
86+
Expand = ["discounts.coupon.applies_to"]
87+
});
8688

8789
if (customer == null || subscription == null)
8890
{
@@ -542,16 +544,17 @@ private async Task<bool> IsOnSecretsManagerStandalone(
542544
return false;
543545
}
544546

545-
var hasCoupon = customer.Discount?.Coupon?.Id == StripeConstants.CouponIDs.SecretsManagerStandalone;
547+
var coupon = subscription.Discounts?.FirstOrDefault(discount =>
548+
discount.Coupon?.Id == StripeConstants.CouponIDs.SecretsManagerStandalone)?.Coupon;
546549

547-
if (!hasCoupon)
550+
if (coupon == null)
548551
{
549552
return false;
550553
}
551554

552555
var subscriptionProductIds = subscription.Items.Data.Select(item => item.Plan.ProductId);
553556

554-
var couponAppliesTo = customer.Discount?.Coupon?.AppliesTo?.Products;
557+
var couponAppliesTo = coupon.AppliesTo?.Products;
555558

556559
return subscriptionProductIds.Intersect(couponAppliesTo ?? []).Any();
557560
}

src/Core/Constants.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ public static class FeatureFlagKeys
252252
public const string PM22136_SdkCipherEncryption = "pm-22136-sdk-cipher-encryption";
253253
public const string PM23904_RiskInsightsForPremium = "pm-23904-risk-insights-for-premium";
254254
public const string PM25083_AutofillConfirmFromSearch = "pm-25083-autofill-confirm-from-search";
255+
public const string VaultLoadingSkeletons = "pm-25081-vault-skeleton-loaders";
255256

256257
/* Innovation Team */
257258
public const string ArchiveVaultItems = "pm-19148-innovation-archive";

src/Sql/dbo/Vault/Stored Procedures/Cipher/Cipher_CreateWithCollections.sql

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,10 @@ BEGIN
2323

2424
DECLARE @UpdateCollectionsSuccess INT
2525
EXEC @UpdateCollectionsSuccess = [dbo].[Cipher_UpdateCollections] @Id, @UserId, @OrganizationId, @CollectionIds
26+
27+
-- Bump the account revision date AFTER collections are assigned.
28+
IF @UpdateCollectionsSuccess = 0
29+
BEGIN
30+
EXEC [dbo].[User_BumpAccountRevisionDateByCipherId] @Id, @OrganizationId
31+
END
2632
END

test/Core.Test/Billing/Organizations/Queries/GetOrganizationMetadataQueryTests.cs

Lines changed: 57 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,6 @@ namespace Bit.Core.Test.Billing.Organizations.Queries;
2121
[SutProviderCustomize]
2222
public class GetOrganizationMetadataQueryTests
2323
{
24-
[Theory, BitAutoData]
25-
public async Task Run_NullOrganization_ReturnsNull(
26-
SutProvider<GetOrganizationMetadataQuery> sutProvider)
27-
{
28-
var result = await sutProvider.Sut.Run(null);
29-
30-
Assert.Null(result);
31-
}
32-
3324
[Theory, BitAutoData]
3425
public async Task Run_SelfHosted_ReturnsDefault(
3526
Organization organization,
@@ -74,8 +65,7 @@ public async Task Run_NullCustomer_ReturnsDefaultWithOccupiedSeats(
7465
.Returns(new OrganizationSeatCounts { Users = 5, Sponsored = 0 });
7566

7667
sutProvider.GetDependency<ISubscriberService>()
77-
.GetCustomer(organization, Arg.Is<CustomerGetOptions>(options =>
78-
options.Expand.Contains("discount.coupon.applies_to")))
68+
.GetCustomer(organization)
7969
.ReturnsNull();
8070

8171
var result = await sutProvider.Sut.Run(organization);
@@ -100,12 +90,12 @@ public async Task Run_NullSubscription_ReturnsDefaultWithOccupiedSeats(
10090
.Returns(new OrganizationSeatCounts { Users = 7, Sponsored = 0 });
10191

10292
sutProvider.GetDependency<ISubscriberService>()
103-
.GetCustomer(organization, Arg.Is<CustomerGetOptions>(options =>
104-
options.Expand.Contains("discount.coupon.applies_to")))
93+
.GetCustomer(organization)
10594
.Returns(customer);
10695

10796
sutProvider.GetDependency<ISubscriberService>()
108-
.GetSubscription(organization)
97+
.GetSubscription(organization, Arg.Is<SubscriptionGetOptions>(options =>
98+
options.Expand.Contains("discounts.coupon.applies_to")))
10999
.ReturnsNull();
110100

111101
var result = await sutProvider.Sut.Run(organization);
@@ -124,23 +114,24 @@ public async Task Run_WithSecretsManagerStandaloneCoupon_ReturnsMetadataWithFlag
124114
organization.PlanType = PlanType.EnterpriseAnnually;
125115

126116
var productId = "product_123";
127-
var customer = new Customer
117+
var customer = new Customer();
118+
119+
var subscription = new Subscription
128120
{
129-
Discount = new Discount
130-
{
131-
Coupon = new Coupon
121+
Discounts =
122+
[
123+
new Discount
132124
{
133-
Id = StripeConstants.CouponIDs.SecretsManagerStandalone,
134-
AppliesTo = new CouponAppliesTo
125+
Coupon = new Coupon
135126
{
136-
Products = [productId]
127+
Id = StripeConstants.CouponIDs.SecretsManagerStandalone,
128+
AppliesTo = new CouponAppliesTo
129+
{
130+
Products = [productId]
131+
}
137132
}
138133
}
139-
}
140-
};
141-
142-
var subscription = new Subscription
143-
{
134+
],
144135
Items = new StripeList<SubscriptionItem>
145136
{
146137
Data =
@@ -162,12 +153,12 @@ public async Task Run_WithSecretsManagerStandaloneCoupon_ReturnsMetadataWithFlag
162153
.Returns(new OrganizationSeatCounts { Users = 15, Sponsored = 0 });
163154

164155
sutProvider.GetDependency<ISubscriberService>()
165-
.GetCustomer(organization, Arg.Is<CustomerGetOptions>(options =>
166-
options.Expand.Contains("discount.coupon.applies_to")))
156+
.GetCustomer(organization)
167157
.Returns(customer);
168158

169159
sutProvider.GetDependency<ISubscriberService>()
170-
.GetSubscription(organization)
160+
.GetSubscription(organization, Arg.Is<SubscriptionGetOptions>(options =>
161+
options.Expand.Contains("discounts.coupon.applies_to")))
171162
.Returns(subscription);
172163

173164
sutProvider.GetDependency<IPricingClient>()
@@ -189,13 +180,11 @@ public async Task Run_WithoutSecretsManagerStandaloneCoupon_ReturnsMetadataWitho
189180
organization.GatewaySubscriptionId = "sub_123";
190181
organization.PlanType = PlanType.TeamsAnnually;
191182

192-
var customer = new Customer
193-
{
194-
Discount = null
195-
};
183+
var customer = new Customer();
196184

197185
var subscription = new Subscription
198186
{
187+
Discounts = null,
199188
Items = new StripeList<SubscriptionItem>
200189
{
201190
Data =
@@ -217,12 +206,12 @@ public async Task Run_WithoutSecretsManagerStandaloneCoupon_ReturnsMetadataWitho
217206
.Returns(new OrganizationSeatCounts { Users = 20, Sponsored = 0 });
218207

219208
sutProvider.GetDependency<ISubscriberService>()
220-
.GetCustomer(organization, Arg.Is<CustomerGetOptions>(options =>
221-
options.Expand.Contains("discount.coupon.applies_to")))
209+
.GetCustomer(organization)
222210
.Returns(customer);
223211

224212
sutProvider.GetDependency<ISubscriberService>()
225-
.GetSubscription(organization)
213+
.GetSubscription(organization, Arg.Is<SubscriptionGetOptions>(options =>
214+
options.Expand.Contains("discounts.coupon.applies_to")))
226215
.Returns(subscription);
227216

228217
sutProvider.GetDependency<IPricingClient>()
@@ -244,23 +233,24 @@ public async Task Run_CouponDoesNotApplyToSubscriptionProducts_ReturnsFalseForSt
244233
organization.GatewaySubscriptionId = "sub_123";
245234
organization.PlanType = PlanType.EnterpriseAnnually;
246235

247-
var customer = new Customer
236+
var customer = new Customer();
237+
238+
var subscription = new Subscription
248239
{
249-
Discount = new Discount
250-
{
251-
Coupon = new Coupon
240+
Discounts =
241+
[
242+
new Discount
252243
{
253-
Id = StripeConstants.CouponIDs.SecretsManagerStandalone,
254-
AppliesTo = new CouponAppliesTo
244+
Coupon = new Coupon
255245
{
256-
Products = ["different_product_id"]
246+
Id = StripeConstants.CouponIDs.SecretsManagerStandalone,
247+
AppliesTo = new CouponAppliesTo
248+
{
249+
Products = ["different_product_id"]
250+
}
257251
}
258252
}
259-
}
260-
};
261-
262-
var subscription = new Subscription
263-
{
253+
],
264254
Items = new StripeList<SubscriptionItem>
265255
{
266256
Data =
@@ -282,12 +272,12 @@ public async Task Run_CouponDoesNotApplyToSubscriptionProducts_ReturnsFalseForSt
282272
.Returns(new OrganizationSeatCounts { Users = 12, Sponsored = 0 });
283273

284274
sutProvider.GetDependency<ISubscriberService>()
285-
.GetCustomer(organization, Arg.Is<CustomerGetOptions>(options =>
286-
options.Expand.Contains("discount.coupon.applies_to")))
275+
.GetCustomer(organization)
287276
.Returns(customer);
288277

289278
sutProvider.GetDependency<ISubscriberService>()
290-
.GetSubscription(organization)
279+
.GetSubscription(organization, Arg.Is<SubscriptionGetOptions>(options =>
280+
options.Expand.Contains("discounts.coupon.applies_to")))
291281
.Returns(subscription);
292282

293283
sutProvider.GetDependency<IPricingClient>()
@@ -310,23 +300,24 @@ public async Task Run_PlanDoesNotSupportSecretsManager_ReturnsFalseForStandalone
310300
organization.PlanType = PlanType.FamiliesAnnually;
311301

312302
var productId = "product_123";
313-
var customer = new Customer
303+
var customer = new Customer();
304+
305+
var subscription = new Subscription
314306
{
315-
Discount = new Discount
316-
{
317-
Coupon = new Coupon
307+
Discounts =
308+
[
309+
new Discount
318310
{
319-
Id = StripeConstants.CouponIDs.SecretsManagerStandalone,
320-
AppliesTo = new CouponAppliesTo
311+
Coupon = new Coupon
321312
{
322-
Products = [productId]
313+
Id = StripeConstants.CouponIDs.SecretsManagerStandalone,
314+
AppliesTo = new CouponAppliesTo
315+
{
316+
Products = [productId]
317+
}
323318
}
324319
}
325-
}
326-
};
327-
328-
var subscription = new Subscription
329-
{
320+
],
330321
Items = new StripeList<SubscriptionItem>
331322
{
332323
Data =
@@ -348,12 +339,12 @@ public async Task Run_PlanDoesNotSupportSecretsManager_ReturnsFalseForStandalone
348339
.Returns(new OrganizationSeatCounts { Users = 8, Sponsored = 0 });
349340

350341
sutProvider.GetDependency<ISubscriberService>()
351-
.GetCustomer(organization, Arg.Is<CustomerGetOptions>(options =>
352-
options.Expand.Contains("discount.coupon.applies_to")))
342+
.GetCustomer(organization)
353343
.Returns(customer);
354344

355345
sutProvider.GetDependency<ISubscriberService>()
356-
.GetSubscription(organization)
346+
.GetSubscription(organization, Arg.Is<SubscriptionGetOptions>(options =>
347+
options.Expand.Contains("discounts.coupon.applies_to")))
357348
.Returns(subscription);
358349

359350
sutProvider.GetDependency<IPricingClient>()

0 commit comments

Comments
 (0)