mirror of
https://github.com/bitwarden/server.git
synced 2025-07-18 08:00:59 -05: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:
@ -1,5 +1,4 @@
|
||||
using Bit.Api.Billing.Models.Requests;
|
||||
using Bit.Core;
|
||||
using Bit.Core.AdminConsole.Repositories;
|
||||
using Bit.Core.AdminConsole.Services;
|
||||
using Bit.Core.Billing.Services;
|
||||
@ -22,16 +21,18 @@ public class ProviderClientsController(
|
||||
IProviderOrganizationRepository providerOrganizationRepository,
|
||||
IProviderRepository providerRepository,
|
||||
IProviderService providerService,
|
||||
IUserService userService) : Controller
|
||||
IUserService userService) : BaseProviderController(currentContext, featureService, providerRepository)
|
||||
{
|
||||
[HttpPost]
|
||||
public async Task<IResult> CreateAsync(
|
||||
[FromRoute] Guid providerId,
|
||||
[FromBody] CreateClientOrganizationRequestBody requestBody)
|
||||
{
|
||||
if (!featureService.IsEnabled(FeatureFlagKeys.EnableConsolidatedBilling))
|
||||
var (provider, result) = await TryGetBillableProviderForAdminOperation(providerId);
|
||||
|
||||
if (provider == null)
|
||||
{
|
||||
return TypedResults.NotFound();
|
||||
return result;
|
||||
}
|
||||
|
||||
var user = await userService.GetUserByPrincipalAsync(User);
|
||||
@ -41,18 +42,6 @@ public class ProviderClientsController(
|
||||
return TypedResults.Unauthorized();
|
||||
}
|
||||
|
||||
if (!currentContext.ManageProviderOrganizations(providerId))
|
||||
{
|
||||
return TypedResults.Unauthorized();
|
||||
}
|
||||
|
||||
var provider = await providerRepository.GetByIdAsync(providerId);
|
||||
|
||||
if (provider == null)
|
||||
{
|
||||
return TypedResults.NotFound();
|
||||
}
|
||||
|
||||
var organizationSignup = new OrganizationSignup
|
||||
{
|
||||
Name = requestBody.Name,
|
||||
@ -103,21 +92,16 @@ public class ProviderClientsController(
|
||||
[FromRoute] Guid providerOrganizationId,
|
||||
[FromBody] UpdateClientOrganizationRequestBody requestBody)
|
||||
{
|
||||
if (!featureService.IsEnabled(FeatureFlagKeys.EnableConsolidatedBilling))
|
||||
{
|
||||
return TypedResults.NotFound();
|
||||
}
|
||||
var (provider, result) = await TryGetBillableProviderForServiceUserOperation(providerId);
|
||||
|
||||
if (!currentContext.ProviderProviderAdmin(providerId))
|
||||
if (provider == null)
|
||||
{
|
||||
return TypedResults.Unauthorized();
|
||||
return result;
|
||||
}
|
||||
|
||||
var provider = await providerRepository.GetByIdAsync(providerId);
|
||||
|
||||
var providerOrganization = await providerOrganizationRepository.GetByIdAsync(providerOrganizationId);
|
||||
|
||||
if (provider == null || providerOrganization == null)
|
||||
if (providerOrganization == null)
|
||||
{
|
||||
return TypedResults.NotFound();
|
||||
}
|
||||
|
Reference in New Issue
Block a user