diff --git a/src/Api/Billing/Models/Responses/OrganizationMetadataResponse.cs b/src/Api/Billing/Models/Responses/OrganizationMetadataResponse.cs index b5f9ab2f5..ebaf7b548 100644 --- a/src/Api/Billing/Models/Responses/OrganizationMetadataResponse.cs +++ b/src/Api/Billing/Models/Responses/OrganizationMetadataResponse.cs @@ -4,10 +4,12 @@ namespace Bit.Api.Billing.Models.Responses; public record OrganizationMetadataResponse( bool IsEligibleForSelfHost, + bool IsManaged, bool IsOnSecretsManagerStandalone) { public static OrganizationMetadataResponse From(OrganizationMetadata metadata) => new( metadata.IsEligibleForSelfHost, + metadata.IsManaged, metadata.IsOnSecretsManagerStandalone); } diff --git a/src/Core/Billing/Models/OrganizationMetadata.cs b/src/Core/Billing/Models/OrganizationMetadata.cs index 136964d7c..6b31b51d0 100644 --- a/src/Core/Billing/Models/OrganizationMetadata.cs +++ b/src/Core/Billing/Models/OrganizationMetadata.cs @@ -2,9 +2,5 @@ public record OrganizationMetadata( bool IsEligibleForSelfHost, - bool IsOnSecretsManagerStandalone) -{ - public static OrganizationMetadata Default() => new( - IsEligibleForSelfHost: false, - IsOnSecretsManagerStandalone: false); -} + bool IsManaged, + bool IsOnSecretsManagerStandalone); diff --git a/src/Core/Billing/Services/Implementations/OrganizationBillingService.cs b/src/Core/Billing/Services/Implementations/OrganizationBillingService.cs index 7db886203..5956e3d85 100644 --- a/src/Core/Billing/Services/Implementations/OrganizationBillingService.cs +++ b/src/Core/Billing/Services/Implementations/OrganizationBillingService.cs @@ -1,5 +1,4 @@ using Bit.Core.AdminConsole.Entities; -using Bit.Core.AdminConsole.Repositories; using Bit.Core.Billing.Caches; using Bit.Core.Billing.Constants; using Bit.Core.Billing.Models; @@ -27,7 +26,6 @@ public class OrganizationBillingService( IGlobalSettings globalSettings, ILogger logger, IOrganizationRepository organizationRepository, - IProviderRepository providerRepository, ISetupIntentCache setupIntentCache, IStripeAdapter stripeAdapter, ISubscriberService subscriberService) : IOrganizationBillingService @@ -71,11 +69,11 @@ public class OrganizationBillingService( var subscription = await subscriberService.GetSubscription(organization); - var isEligibleForSelfHost = await IsEligibleForSelfHost(organization, subscription); - + var isEligibleForSelfHost = IsEligibleForSelfHost(organization); + var isManaged = organization.Status == OrganizationStatusType.Managed; var isOnSecretsManagerStandalone = IsOnSecretsManagerStandalone(organization, customer, subscription); - return new OrganizationMetadata(isEligibleForSelfHost, isOnSecretsManagerStandalone); + return new OrganizationMetadata(isEligibleForSelfHost, isManaged, isOnSecretsManagerStandalone); } public async Task UpdatePaymentMethod( @@ -339,26 +337,12 @@ public class OrganizationBillingService( return await stripeAdapter.SubscriptionCreateAsync(subscriptionCreateOptions); } - private async Task IsEligibleForSelfHost( - Organization organization, - Subscription? organizationSubscription) + private static bool IsEligibleForSelfHost( + Organization organization) { - if (organization.Status != OrganizationStatusType.Managed) - { - return organization.Plan.Contains("Families") || - organization.Plan.Contains("Enterprise") && IsActive(organizationSubscription); - } + var eligibleSelfHostPlans = StaticStore.Plans.Where(plan => plan.HasSelfHost).Select(plan => plan.Type); - var provider = await providerRepository.GetByOrganizationIdAsync(organization.Id); - - var providerSubscription = await subscriberService.GetSubscriptionOrThrow(provider); - - return organization.Plan.Contains("Enterprise") && IsActive(providerSubscription); - - bool IsActive(Subscription? subscription) => subscription?.Status is - StripeConstants.SubscriptionStatus.Active or - StripeConstants.SubscriptionStatus.Trialing or - StripeConstants.SubscriptionStatus.PastDue; + return eligibleSelfHostPlans.Contains(organization.PlanType); } private static bool IsOnSecretsManagerStandalone( diff --git a/test/Api.Test/Billing/Controllers/OrganizationBillingControllerTests.cs b/test/Api.Test/Billing/Controllers/OrganizationBillingControllerTests.cs index b46fd307e..eadf7e97b 100644 --- a/test/Api.Test/Billing/Controllers/OrganizationBillingControllerTests.cs +++ b/test/Api.Test/Billing/Controllers/OrganizationBillingControllerTests.cs @@ -52,16 +52,17 @@ public class OrganizationBillingControllerTests { sutProvider.GetDependency().AccessMembersTab(organizationId).Returns(true); sutProvider.GetDependency().GetMetadata(organizationId) - .Returns(new OrganizationMetadata(true, true)); + .Returns(new OrganizationMetadata(true, true, true)); var result = await sutProvider.Sut.GetMetadataAsync(organizationId); Assert.IsType>(result); - var organizationMetadataResponse = ((Ok)result).Value; + var response = ((Ok)result).Value; - Assert.True(organizationMetadataResponse.IsEligibleForSelfHost); - Assert.True(organizationMetadataResponse.IsOnSecretsManagerStandalone); + Assert.True(response.IsEligibleForSelfHost); + Assert.True(response.IsManaged); + Assert.True(response.IsOnSecretsManagerStandalone); } [Theory, BitAutoData]