mirror of
https://github.com/bitwarden/server
synced 2026-01-02 08:33:48 +00:00
Merge branch 'main' into auth/pm-22975/client-version-validator
This commit is contained in:
@@ -1,7 +1,5 @@
|
||||
using System.Globalization;
|
||||
using Bit.Billing.Constants;
|
||||
using Bit.Billing.Constants;
|
||||
using Bit.Billing.Jobs;
|
||||
using Bit.Core;
|
||||
using Bit.Core.AdminConsole.OrganizationFeatures.Organizations.Interfaces;
|
||||
using Bit.Core.AdminConsole.Repositories;
|
||||
using Bit.Core.AdminConsole.Services;
|
||||
@@ -134,11 +132,6 @@ public class SubscriptionUpdatedHandler : ISubscriptionUpdatedHandler
|
||||
}
|
||||
case StripeSubscriptionStatus.Active when providerId.HasValue:
|
||||
{
|
||||
var providerPortalTakeover = _featureService.IsEnabled(FeatureFlagKeys.PM21821_ProviderPortalTakeover);
|
||||
if (!providerPortalTakeover)
|
||||
{
|
||||
break;
|
||||
}
|
||||
var provider = await _providerRepository.GetByIdAsync(providerId.Value);
|
||||
if (provider != null)
|
||||
{
|
||||
@@ -321,13 +314,6 @@ public class SubscriptionUpdatedHandler : ISubscriptionUpdatedHandler
|
||||
Event parsedEvent,
|
||||
Subscription currentSubscription)
|
||||
{
|
||||
var providerPortalTakeover = _featureService.IsEnabled(FeatureFlagKeys.PM21821_ProviderPortalTakeover);
|
||||
|
||||
if (!providerPortalTakeover)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var provider = await _providerRepository.GetByIdAsync(providerId);
|
||||
if (provider == null)
|
||||
{
|
||||
@@ -343,22 +329,17 @@ public class SubscriptionUpdatedHandler : ISubscriptionUpdatedHandler
|
||||
{
|
||||
var previousSubscription = parsedEvent.Data.PreviousAttributes.ToObject<Subscription>() as Subscription;
|
||||
|
||||
var updateIsSubscriptionGoingUnpaid = previousSubscription is
|
||||
{
|
||||
Status:
|
||||
if (previousSubscription is
|
||||
{
|
||||
Status:
|
||||
StripeSubscriptionStatus.Trialing or
|
||||
StripeSubscriptionStatus.Active or
|
||||
StripeSubscriptionStatus.PastDue
|
||||
} && currentSubscription is
|
||||
{
|
||||
Status: StripeSubscriptionStatus.Unpaid,
|
||||
LatestInvoice.BillingReason: "subscription_cycle" or "subscription_create"
|
||||
};
|
||||
|
||||
var updateIsManualSuspensionViaMetadata = CheckForManualSuspensionViaMetadata(
|
||||
previousSubscription, currentSubscription);
|
||||
|
||||
if (updateIsSubscriptionGoingUnpaid || updateIsManualSuspensionViaMetadata)
|
||||
} && currentSubscription is
|
||||
{
|
||||
Status: StripeSubscriptionStatus.Unpaid,
|
||||
LatestInvoice.BillingReason: "subscription_cycle" or "subscription_create"
|
||||
})
|
||||
{
|
||||
if (currentSubscription.TestClock != null)
|
||||
{
|
||||
@@ -369,14 +350,6 @@ public class SubscriptionUpdatedHandler : ISubscriptionUpdatedHandler
|
||||
|
||||
var subscriptionUpdateOptions = new SubscriptionUpdateOptions { CancelAt = now.AddDays(7) };
|
||||
|
||||
if (updateIsManualSuspensionViaMetadata)
|
||||
{
|
||||
subscriptionUpdateOptions.Metadata = new Dictionary<string, string>
|
||||
{
|
||||
["suspended_provider_via_webhook_at"] = DateTime.UtcNow.ToString(CultureInfo.InvariantCulture)
|
||||
};
|
||||
}
|
||||
|
||||
await _stripeFacade.UpdateSubscription(currentSubscription.Id, subscriptionUpdateOptions);
|
||||
}
|
||||
}
|
||||
@@ -399,37 +372,4 @@ public class SubscriptionUpdatedHandler : ISubscriptionUpdatedHandler
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static bool CheckForManualSuspensionViaMetadata(
|
||||
Subscription? previousSubscription,
|
||||
Subscription currentSubscription)
|
||||
{
|
||||
/*
|
||||
* When metadata on a subscription is updated, we'll receive an event that has:
|
||||
* Previous Metadata: { newlyAddedKey: null }
|
||||
* Current Metadata: { newlyAddedKey: newlyAddedValue }
|
||||
*
|
||||
* As such, our check for a manual suspension must ensure that the 'previous_attributes' does contain the
|
||||
* 'metadata' property, but also that the "suspend_provider" key in that metadata is set to null.
|
||||
*
|
||||
* If we don't do this and instead do a null coalescing check on 'previous_attributes?.metadata?.TryGetValue',
|
||||
* we'll end up marking an event where 'previous_attributes.metadata' = null (which could be any subscription update
|
||||
* that does not update the metadata) the same as a manual suspension.
|
||||
*/
|
||||
const string key = "suspend_provider";
|
||||
|
||||
if (previousSubscription is not { Metadata: not null } ||
|
||||
!previousSubscription.Metadata.TryGetValue(key, out var previousValue))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (previousValue == null)
|
||||
{
|
||||
return !string.IsNullOrEmpty(
|
||||
currentSubscription.Metadata.TryGetValue(key, out var currentValue) ? currentValue : null);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,6 +35,7 @@ public static class PolicyServiceCollectionExtensions
|
||||
services.AddScoped<IPolicyValidator, MaximumVaultTimeoutPolicyValidator>();
|
||||
services.AddScoped<IPolicyValidator, UriMatchDefaultPolicyValidator>();
|
||||
services.AddScoped<IPolicyValidator, FreeFamiliesForEnterprisePolicyValidator>();
|
||||
services.AddScoped<IPolicyValidator, BlockClaimedDomainAccountCreationPolicyValidator>();
|
||||
services.AddScoped<IPolicyValidator, AutomaticUserConfirmationPolicyEventHandler>();
|
||||
}
|
||||
|
||||
|
||||
@@ -188,7 +188,6 @@ public static class FeatureFlagKeys
|
||||
|
||||
/* Billing Team */
|
||||
public const string TrialPayment = "PM-8163-trial-payment";
|
||||
public const string PM21821_ProviderPortalTakeover = "pm-21821-provider-portal-takeover";
|
||||
public const string PM22415_TaxIDWarnings = "pm-22415-tax-id-warnings";
|
||||
public const string PM25379_UseNewOrganizationMetadataStructure = "pm-25379-use-new-organization-metadata-structure";
|
||||
public const string PM24996ImplementUpgradeFromFreeDialog = "pm-24996-implement-upgrade-from-free-dialog";
|
||||
|
||||
Reference in New Issue
Block a user