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

[PM-14365][Defect] Member of trialing org cannot log in app (#4967)

* changes to include subscription status metadata

Signed-off-by: Cy Okeke <cokeke@bitwarden.com>

* Fix the failing test

Signed-off-by: Cy Okeke <cokeke@bitwarden.com>

* Resolve the failing test

Signed-off-by: Cy Okeke <cokeke@bitwarden.com>

---------

Signed-off-by: Cy Okeke <cokeke@bitwarden.com>
This commit is contained in:
cyprain-okeke 2024-11-01 17:55:59 +01:00 committed by GitHub
parent f149f247d5
commit fc719efee9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 23 additions and 9 deletions

View File

@ -5,11 +5,13 @@ namespace Bit.Api.Billing.Models.Responses;
public record OrganizationMetadataResponse( public record OrganizationMetadataResponse(
bool IsEligibleForSelfHost, bool IsEligibleForSelfHost,
bool IsManaged, bool IsManaged,
bool IsOnSecretsManagerStandalone) bool IsOnSecretsManagerStandalone,
bool IsSubscriptionUnpaid)
{ {
public static OrganizationMetadataResponse From(OrganizationMetadata metadata) public static OrganizationMetadataResponse From(OrganizationMetadata metadata)
=> new( => new(
metadata.IsEligibleForSelfHost, metadata.IsEligibleForSelfHost,
metadata.IsManaged, metadata.IsManaged,
metadata.IsOnSecretsManagerStandalone); metadata.IsOnSecretsManagerStandalone,
metadata.IsSubscriptionUnpaid);
} }

View File

@ -3,4 +3,5 @@
public record OrganizationMetadata( public record OrganizationMetadata(
bool IsEligibleForSelfHost, bool IsEligibleForSelfHost,
bool IsManaged, bool IsManaged,
bool IsOnSecretsManagerStandalone); bool IsOnSecretsManagerStandalone,
bool IsSubscriptionUnpaid);

View File

@ -62,18 +62,18 @@ public class OrganizationBillingService(
return null; return null;
} }
var customer = await subscriberService.GetCustomer(organization, new CustomerGetOptions var customer = await subscriberService.GetCustomer(organization,
{ new CustomerGetOptions { Expand = ["discount.coupon.applies_to"] });
Expand = ["discount.coupon.applies_to"]
});
var subscription = await subscriberService.GetSubscription(organization); var subscription = await subscriberService.GetSubscription(organization);
var isEligibleForSelfHost = IsEligibleForSelfHost(organization); var isEligibleForSelfHost = IsEligibleForSelfHost(organization);
var isManaged = organization.Status == OrganizationStatusType.Managed; var isManaged = organization.Status == OrganizationStatusType.Managed;
var isOnSecretsManagerStandalone = IsOnSecretsManagerStandalone(organization, customer, subscription); var isOnSecretsManagerStandalone = IsOnSecretsManagerStandalone(organization, customer, subscription);
var isSubscriptionUnpaid = IsSubscriptionUnpaid(subscription);
return new OrganizationMetadata(isEligibleForSelfHost, isManaged, isOnSecretsManagerStandalone); return new OrganizationMetadata(isEligibleForSelfHost, isManaged, isOnSecretsManagerStandalone,
isSubscriptionUnpaid);
} }
public async Task UpdatePaymentMethod( public async Task UpdatePaymentMethod(
@ -376,5 +376,16 @@ public class OrganizationBillingService(
return subscriptionProductIds.Intersect(couponAppliesTo ?? []).Any(); return subscriptionProductIds.Intersect(couponAppliesTo ?? []).Any();
} }
private static bool IsSubscriptionUnpaid(Subscription subscription)
{
if (subscription == null)
{
return false;
}
return subscription.Status == "unpaid";
}
#endregion #endregion
} }

View File

@ -52,7 +52,7 @@ public class OrganizationBillingControllerTests
{ {
sutProvider.GetDependency<ICurrentContext>().AccessMembersTab(organizationId).Returns(true); sutProvider.GetDependency<ICurrentContext>().AccessMembersTab(organizationId).Returns(true);
sutProvider.GetDependency<IOrganizationBillingService>().GetMetadata(organizationId) sutProvider.GetDependency<IOrganizationBillingService>().GetMetadata(organizationId)
.Returns(new OrganizationMetadata(true, true, true)); .Returns(new OrganizationMetadata(true, true, true, true));
var result = await sutProvider.Sut.GetMetadataAsync(organizationId); var result = await sutProvider.Sut.GetMetadataAsync(organizationId);