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

PM-7999 | Reseller billing e-mail can be blank causing downstream errors for org creation (#4733)

This commit is contained in:
Jonas Hendrickx
2024-09-05 16:37:20 +02:00
committed by GitHub
parent d71916aee5
commit 64a7cba013
3 changed files with 64 additions and 17 deletions

View File

@ -162,27 +162,13 @@ public class ProvidersController : Controller
[SelfHosted(NotSelfHostedOnly = true)]
public async Task<IActionResult> Edit(Guid id)
{
var provider = await _providerRepository.GetByIdAsync(id);
var provider = await GetEditModel(id);
if (provider == null)
{
return RedirectToAction("Index");
}
var users = await _providerUserRepository.GetManyDetailsByProviderAsync(id);
var providerOrganizations = await _providerOrganizationRepository.GetManyDetailsByProviderAsync(id);
var isConsolidatedBillingEnabled = _featureService.IsEnabled(FeatureFlagKeys.EnableConsolidatedBilling);
if (!isConsolidatedBillingEnabled || !provider.IsBillable())
{
return View(new ProviderEditModel(provider, users, providerOrganizations, new List<ProviderPlan>()));
}
var providerPlans = await _providerPlanRepository.GetByProviderId(id);
return View(new ProviderEditModel(
provider, users, providerOrganizations,
providerPlans.ToList(), GetGatewayCustomerUrl(provider), GetGatewaySubscriptionUrl(provider)));
return View(provider);
}
[HttpPost]
@ -198,6 +184,20 @@ public class ProvidersController : Controller
return RedirectToAction("Index");
}
if (provider.Type != model.Type)
{
var oldModel = await GetEditModel(id);
ModelState.AddModelError(nameof(model.Type), "Provider type cannot be changed.");
return View(oldModel);
}
if (!ModelState.IsValid)
{
var oldModel = await GetEditModel(id);
ModelState[nameof(ProviderEditModel.BillingEmail)]!.RawValue = oldModel.BillingEmail;
return View(oldModel);
}
model.ToProvider(provider);
await _providerRepository.ReplaceAsync(provider);
@ -236,6 +236,32 @@ public class ProvidersController : Controller
return RedirectToAction("Edit", new { id });
}
private async Task<ProviderEditModel> GetEditModel(Guid id)
{
var provider = await _providerRepository.GetByIdAsync(id);
if (provider == null)
{
return null;
}
var users = await _providerUserRepository.GetManyDetailsByProviderAsync(id);
var providerOrganizations = await _providerOrganizationRepository.GetManyDetailsByProviderAsync(id);
var isConsolidatedBillingEnabled = _featureService.IsEnabled(FeatureFlagKeys.EnableConsolidatedBilling);
if (!isConsolidatedBillingEnabled || !provider.IsBillable())
{
return new ProviderEditModel(provider, users, providerOrganizations, new List<ProviderPlan>());
}
var providerPlans = await _providerPlanRepository.GetByProviderId(id);
return new ProviderEditModel(
provider, users, providerOrganizations,
providerPlans.ToList(), GetGatewayCustomerUrl(provider), GetGatewaySubscriptionUrl(provider));
}
[RequirePermission(Permission.Provider_ResendEmailInvite)]
public async Task<IActionResult> ResendInvite(Guid ownerId, Guid providerId)
{