1
0
mirror of https://github.com/bitwarden/server.git synced 2025-07-01 08:02:49 -05:00

[AC-358] Server changes for self host subscription page changes (#2826)

* [AC-358] Add constant for grace period length

* [AC-358] Add SubscriptionExpiration to OrganizationLicense.cs and increment Current_License_File_Version

* [AC-358] Update org subscription response model

- Add new SelfHostSubscriptionExpiration field that does not include a grace period
- Add optional License argument to constructor for self host responses
- Use the License, if available, to populate the expiration/subscription expiration fields
- Maintain backwards compatability by falling back to organization expiration date

* [AC-358] Read organization license file for self hosted subscription response

* [AC-358] Decrement current license file version and add comment documenting why

* [AC-358] Clarify name for new expiration without grace period field
This commit is contained in:
Shane Melton
2023-05-15 07:38:41 -07:00
committed by GitHub
parent 8d3fe12170
commit bfd3f85bb0
5 changed files with 52 additions and 7 deletions

View File

@ -50,6 +50,7 @@ public class OrganizationsController : Controller
private readonly ICloudGetOrganizationLicenseQuery _cloudGetOrganizationLicenseQuery;
private readonly IFeatureService _featureService;
private readonly GlobalSettings _globalSettings;
private readonly ILicensingService _licensingService;
public OrganizationsController(
IOrganizationRepository organizationRepository,
@ -69,7 +70,8 @@ public class OrganizationsController : Controller
IUpdateOrganizationLicenseCommand updateOrganizationLicenseCommand,
ICloudGetOrganizationLicenseQuery cloudGetOrganizationLicenseQuery,
IFeatureService featureService,
GlobalSettings globalSettings)
GlobalSettings globalSettings,
ILicensingService licensingService)
{
_organizationRepository = organizationRepository;
_organizationUserRepository = organizationUserRepository;
@ -89,6 +91,7 @@ public class OrganizationsController : Controller
_cloudGetOrganizationLicenseQuery = cloudGetOrganizationLicenseQuery;
_featureService = featureService;
_globalSettings = globalSettings;
_licensingService = licensingService;
}
[HttpGet("{id}")]
@ -156,10 +159,14 @@ public class OrganizationsController : Controller
return new OrganizationSubscriptionResponseModel(organization, subscriptionInfo, hideSensitiveData);
}
else
if (_globalSettings.SelfHosted)
{
return new OrganizationSubscriptionResponseModel(organization);
var orgLicense = await _licensingService.ReadOrganizationLicenseAsync(organization);
return new OrganizationSubscriptionResponseModel(organization, orgLicense);
}
return new OrganizationSubscriptionResponseModel(organization);
}
[HttpGet("{id}/license")]

View File

@ -3,6 +3,7 @@ using Bit.Core.Enums;
using Bit.Core.Models.Api;
using Bit.Core.Models.Business;
using Bit.Core.Utilities;
using Constants = Bit.Core.Constants;
namespace Bit.Api.Models.Response.Organizations;
@ -108,9 +109,32 @@ public class OrganizationSubscriptionResponseModel : OrganizationResponseModel
}
}
public OrganizationSubscriptionResponseModel(Organization organization, OrganizationLicense license) :
this(organization)
{
if (license != null)
{
// License expiration should always include grace period - See OrganizationLicense.cs
Expiration = license.Expires;
// Use license.ExpirationWithoutGracePeriod if available, otherwise assume license expiration minus grace period
ExpirationWithoutGracePeriod = license.ExpirationWithoutGracePeriod ??
license.Expires?.AddDays(-Constants
.OrganizationSelfHostSubscriptionGracePeriodDays);
}
}
public string StorageName { get; set; }
public double? StorageGb { get; set; }
public BillingSubscription Subscription { get; set; }
public BillingSubscriptionUpcomingInvoice UpcomingInvoice { get; set; }
/// <summary>
/// Date when a self-hosted organization's subscription expires, without any grace period.
/// </summary>
public DateTime? ExpirationWithoutGracePeriod { get; set; }
/// <summary>
/// Date when a self-hosted organization expires (includes grace period).
/// </summary>
public DateTime? Expiration { get; set; }
}