1
0
mirror of https://github.com/bitwarden/server synced 2025-12-17 08:43:27 +00:00

installation validation and self host applied

This commit is contained in:
Kyle Spearrin
2017-08-15 16:11:08 -04:00
parent ee9ec680a9
commit dd288a7071
7 changed files with 51 additions and 38 deletions

View File

@@ -29,6 +29,7 @@ namespace Bit.Core.Services
private readonly IPushRegistrationService _pushRegistrationService;
private readonly IDeviceRepository _deviceRepository;
private readonly ILicensingService _licensingService;
private readonly IInstallationRepository _installationRepository;
private readonly StripePaymentService _stripePaymentService;
private readonly GlobalSettings _globalSettings;
@@ -44,6 +45,7 @@ namespace Bit.Core.Services
IPushRegistrationService pushRegistrationService,
IDeviceRepository deviceRepository,
ILicensingService licensingService,
IInstallationRepository installationRepository,
GlobalSettings globalSettings)
{
_organizationRepository = organizationRepository;
@@ -57,6 +59,7 @@ namespace Bit.Core.Services
_pushRegistrationService = pushRegistrationService;
_deviceRepository = deviceRepository;
_licensingService = licensingService;
_installationRepository = installationRepository;
_stripePaymentService = new StripePaymentService();
_globalSettings = globalSettings;
}
@@ -522,6 +525,7 @@ namespace Bit.Core.Services
UseGroups = plan.UseGroups,
UseDirectory = plan.UseDirectory,
UseTotp = plan.UseTotp,
SelfHost = plan.SelfHost,
Plan = plan.Name,
Gateway = GatewayType.Stripe,
GatewayCustomerId = customer?.Id,
@@ -563,6 +567,7 @@ namespace Bit.Core.Services
UseDirectory = license.UseDirectory,
UseTotp = license.UseTotp,
Plan = license.Plan,
SelfHost = license.SelfHost,
Gateway = null,
GatewayCustomerId = null,
GatewaySubscriptionId = null,
@@ -999,6 +1004,25 @@ namespace Bit.Core.Services
}
}
public async Task<OrganizationLicense> GenerateLicenseAsync(Guid organizationId, Guid installationId)
{
var organization = await _organizationRepository.GetByIdAsync(organizationId);
if(organization == null)
{
throw new NotFoundException();
}
var installation = await _installationRepository.GetByIdAsync(installationId);
if(installation == null || !installation.Enabled)
{
throw new BadRequestException("Invalid installation id");
}
var paymentService = new StripePaymentService();
var billingInfo = await paymentService.GetBillingAsync(organization);
return new OrganizationLicense(organization, billingInfo, installationId, _licensingService);
}
public async Task ImportAsync(Guid organizationId,
Guid importingUserId,
IEnumerable<ImportedGroup> groups,