mirror of
https://github.com/bitwarden/server.git
synced 2025-06-13 06:20:48 -05:00
[PM-20416]Downgraded paid org cannot upgrade from Free (#5748)
* enable the downgrade of free org * resolve the free org update issue Signed-off-by: Cy Okeke <cokeke@bitwarden.com> * Retain the canceled subscriptionId Signed-off-by: Cy Okeke <cokeke@bitwarden.com> * resolve the pr coments * Refactor the code base on the pr comment Signed-off-by: Cy Okeke <cokeke@bitwarden.com> * Resolve the pr comments Signed-off-by: Cy Okeke <cokeke@bitwarden.com> * Resolve the pr comment Signed-off-by: Cy Okeke <cokeke@bitwarden.com> * Resolve the failing test Signed-off-by: Cy Okeke <cokeke@bitwarden.com> * Resolve the repeated condition Signed-off-by: Cy Okeke <cokeke@bitwarden.com> * apply the condition suggestion Signed-off-by: Cy Okeke <cokeke@bitwarden.com> * Add the missing MaxCollection --------- Signed-off-by: Cy Okeke <cokeke@bitwarden.com>
This commit is contained in:
parent
84e5ea1265
commit
fbdd62fadd
@ -242,10 +242,32 @@ public class OrganizationsController : Controller
|
||||
Seats = organization.Seats
|
||||
};
|
||||
|
||||
if (model.PlanType.HasValue)
|
||||
{
|
||||
var freePlan = await _pricingClient.GetPlanOrThrow(model.PlanType.Value);
|
||||
var isDowngradingToFree = organization.PlanType != PlanType.Free && model.PlanType.Value == PlanType.Free;
|
||||
if (isDowngradingToFree)
|
||||
{
|
||||
if (model.Seats.HasValue && model.Seats.Value > freePlan.PasswordManager.MaxSeats)
|
||||
{
|
||||
TempData["Error"] = $"Organizations with more than {freePlan.PasswordManager.MaxSeats} seats cannot be downgraded to the Free plan";
|
||||
return RedirectToAction("Edit", new { id });
|
||||
}
|
||||
|
||||
if (model.MaxCollections > freePlan.PasswordManager.MaxCollections)
|
||||
{
|
||||
TempData["Error"] = $"Organizations with more than {freePlan.PasswordManager.MaxCollections} collections cannot be downgraded to the Free plan. Your organization currently has {organization.MaxCollections} collections.";
|
||||
return RedirectToAction("Edit", new { id });
|
||||
}
|
||||
|
||||
model.MaxStorageGb = null;
|
||||
model.ExpirationDate = null;
|
||||
model.Enabled = true;
|
||||
}
|
||||
}
|
||||
|
||||
UpdateOrganization(organization, model);
|
||||
|
||||
var plan = await _pricingClient.GetPlanOrThrow(organization.PlanType);
|
||||
|
||||
if (organization.UseSecretsManager && !plan.SupportsSecretsManager)
|
||||
{
|
||||
TempData["Error"] = "Plan does not support Secrets Manager";
|
||||
|
@ -4,6 +4,7 @@ using Bit.Api.AdminConsole.Models.Request.Organizations;
|
||||
using Bit.Api.Billing.Models.Requests;
|
||||
using Bit.Api.Billing.Models.Responses;
|
||||
using Bit.Api.Billing.Queries.Organizations;
|
||||
using Bit.Core.Billing.Enums;
|
||||
using Bit.Core.Billing.Models;
|
||||
using Bit.Core.Billing.Models.Sales;
|
||||
using Bit.Core.Billing.Pricing;
|
||||
@ -280,17 +281,36 @@ public class OrganizationBillingController(
|
||||
}
|
||||
|
||||
var organization = await organizationRepository.GetByIdAsync(organizationId);
|
||||
|
||||
if (organization == null)
|
||||
{
|
||||
return Error.NotFound();
|
||||
}
|
||||
var existingPlan = organization.PlanType;
|
||||
var organizationSignup = model.ToOrganizationSignup(user);
|
||||
var sale = OrganizationSale.From(organization, organizationSignup);
|
||||
var plan = await pricingClient.GetPlanOrThrow(model.PlanType);
|
||||
sale.Organization.PlanType = plan.Type;
|
||||
sale.Organization.Plan = plan.Name;
|
||||
sale.SubscriptionSetup.SkipTrial = true;
|
||||
if (existingPlan == PlanType.Free && organization.GatewaySubscriptionId is not null)
|
||||
{
|
||||
sale.Organization.UseTotp = plan.HasTotp;
|
||||
sale.Organization.UseGroups = plan.HasGroups;
|
||||
sale.Organization.UseDirectory = plan.HasDirectory;
|
||||
sale.Organization.SelfHost = plan.HasSelfHost;
|
||||
sale.Organization.UsersGetPremium = plan.UsersGetPremium;
|
||||
sale.Organization.UseEvents = plan.HasEvents;
|
||||
sale.Organization.Use2fa = plan.Has2fa;
|
||||
sale.Organization.UseApi = plan.HasApi;
|
||||
sale.Organization.UsePolicies = plan.HasPolicies;
|
||||
sale.Organization.UseSso = plan.HasSso;
|
||||
sale.Organization.UseResetPassword = plan.HasResetPassword;
|
||||
sale.Organization.UseKeyConnector = plan.HasKeyConnector;
|
||||
sale.Organization.UseScim = plan.HasScim;
|
||||
sale.Organization.UseCustomPermissions = plan.HasCustomPermissions;
|
||||
sale.Organization.UseOrganizationDomains = plan.HasOrganizationDomains;
|
||||
sale.Organization.MaxCollections = plan.PasswordManager.MaxCollections;
|
||||
}
|
||||
|
||||
if (organizationSignup.PaymentMethodType == null || string.IsNullOrEmpty(organizationSignup.PaymentToken))
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user