1
0
mirror of https://github.com/bitwarden/server synced 2026-01-02 08:33:48 +00:00
Files
server/src/Core/OrganizationFeatures/OrganizationLicenses/Cloud/CloudGetOrganizationLicenseQuery.cs
Thomas Rittson 82908b1fb7 [EC-826] Merge license sync feature branch to master (#2587)
* [EC-634] Extract GenerateLicenseAsync to a query (#2373)

* [EC-637] Add license sync to server (#2453)

* [EC-1036] Show correct license sync date (#2626)

* Update method name per new pattern
2023-01-31 07:42:10 +10:00

39 lines
1.4 KiB
C#

using Bit.Core.Entities;
using Bit.Core.Exceptions;
using Bit.Core.Models.Business;
using Bit.Core.OrganizationFeatures.OrganizationLicenses.Interfaces;
using Bit.Core.Repositories;
using Bit.Core.Services;
namespace Bit.Core.OrganizationFeatures.OrganizationLicenses;
public class CloudGetOrganizationLicenseQuery : ICloudGetOrganizationLicenseQuery
{
private readonly IInstallationRepository _installationRepository;
private readonly IPaymentService _paymentService;
private readonly ILicensingService _licensingService;
public CloudGetOrganizationLicenseQuery(
IInstallationRepository installationRepository,
IPaymentService paymentService,
ILicensingService licensingService)
{
_installationRepository = installationRepository;
_paymentService = paymentService;
_licensingService = licensingService;
}
public async Task<OrganizationLicense> GetLicenseAsync(Organization organization, Guid installationId,
int? version = null)
{
var installation = await _installationRepository.GetByIdAsync(installationId);
if (installation is not { Enabled: true })
{
throw new BadRequestException("Invalid installation id");
}
var subInfo = await _paymentService.GetSubscriptionAsync(organization);
return new OrganizationLicense(organization, subInfo, installationId, _licensingService, version);
}
}