1
0
mirror of https://github.com/bitwarden/server synced 2025-12-21 02:33:30 +00:00

[AC-2774] Consolidated issues for Consolidated Billing (#4201)

* Add BaseProviderController, update some endpoints to ServiceUser permissions

* Prevent service user from scaling provider seats above seat minimum

* Expand invoice response to include DueDate
This commit is contained in:
Alex Morask
2024-06-24 11:15:47 -04:00
committed by GitHub
parent 4a06c82c8d
commit fa62b36d44
9 changed files with 318 additions and 284 deletions

View File

@@ -0,0 +1,50 @@
using Bit.Core;
using Bit.Core.AdminConsole.Entities.Provider;
using Bit.Core.AdminConsole.Repositories;
using Bit.Core.Billing.Extensions;
using Bit.Core.Context;
using Bit.Core.Services;
using Microsoft.AspNetCore.Mvc;
namespace Bit.Api.Billing.Controllers;
public abstract class BaseProviderController(
ICurrentContext currentContext,
IFeatureService featureService,
IProviderRepository providerRepository) : Controller
{
protected Task<(Provider, IResult)> TryGetBillableProviderForAdminOperation(
Guid providerId) => TryGetBillableProviderAsync(providerId, currentContext.ProviderProviderAdmin);
protected Task<(Provider, IResult)> TryGetBillableProviderForServiceUserOperation(
Guid providerId) => TryGetBillableProviderAsync(providerId, currentContext.ProviderUser);
private async Task<(Provider, IResult)> TryGetBillableProviderAsync(
Guid providerId,
Func<Guid, bool> checkAuthorization)
{
if (!featureService.IsEnabled(FeatureFlagKeys.EnableConsolidatedBilling))
{
return (null, TypedResults.NotFound());
}
var provider = await providerRepository.GetByIdAsync(providerId);
if (provider == null)
{
return (null, TypedResults.NotFound());
}
if (!checkAuthorization(providerId))
{
return (null, TypedResults.Unauthorized());
}
if (!provider.IsBillable())
{
return (null, TypedResults.Unauthorized());
}
return (provider, null);
}
}