1
0
mirror of https://github.com/bitwarden/server.git synced 2025-05-22 12:04:27 -05:00

Resolve the repeated condition

Signed-off-by: Cy Okeke <cokeke@bitwarden.com>
This commit is contained in:
Cy Okeke 2025-05-22 13:25:41 +01:00
parent d23373b776
commit f90c692c40
No known key found for this signature in database
GPG Key ID: 88B341B55C84B45C

View File

@ -258,27 +258,20 @@ public class OrganizationsController : Controller
if (model.PlanType.HasValue)
{
var freePlan = await _pricingClient.GetPlanOrThrow(model.PlanType.Value);
if (organization.PlanType != PlanType.Free &&
model.PlanType.Value == PlanType.Free &&
model.Seats.HasValue &&
model.Seats.Value > freePlan.PasswordManager.MaxSeats)
var isDowngradingToFree = organization.PlanType != PlanType.Free && model.PlanType.Value == PlanType.Free;
switch (isDowngradingToFree)
{
TempData["Error"] = $"Organizations with more than {freePlan.PasswordManager.MaxSeats} seats cannot be downgraded to the Free plan";
return RedirectToAction("Edit", new { id });
}
if (organization.PlanType != PlanType.Free && model.PlanType.Value == PlanType.Free && 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 });
}
if (organization.PlanType != PlanType.Free && model.PlanType.Value == PlanType.Free)
{
model.MaxStorageGb = null;
model.ExpirationDate = null;
model.Enabled = true;
case true when 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 });
case true when 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 });
case true:
model.MaxStorageGb = null;
model.ExpirationDate = null;
model.Enabled = true;
break;
}
}