From d23373b776015bae21ad33a85e1eb9cb1cb9a056 Mon Sep 17 00:00:00 2001 From: Cy Okeke Date: Wed, 21 May 2025 09:50:15 +0100 Subject: [PATCH] Resolve the failing test Signed-off-by: Cy Okeke --- .../Controllers/OrganizationsController.cs | 37 +++++++++++-------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/src/Admin/AdminConsole/Controllers/OrganizationsController.cs b/src/Admin/AdminConsole/Controllers/OrganizationsController.cs index 8516ee4887..ad2e8b735b 100644 --- a/src/Admin/AdminConsole/Controllers/OrganizationsController.cs +++ b/src/Admin/AdminConsole/Controllers/OrganizationsController.cs @@ -255,24 +255,31 @@ public class OrganizationsController : Controller Seats = organization.Seats }; - var freePlan = await _pricingClient.GetPlanOrThrow(model.PlanType.Value); - if (organization.PlanType != PlanType.Free && model.PlanType == PlanType.Free && model.Seats > freePlan.PasswordManager.MaxSeats) + if (model.PlanType.HasValue) { - TempData["Error"] = $"Organizations with more than {freePlan.PasswordManager.MaxSeats} seats cannot be downgraded to the Free plan"; - return RedirectToAction("Edit", new { id }); - } + var freePlan = await _pricingClient.GetPlanOrThrow(model.PlanType.Value); - if (organization.PlanType != PlanType.Free && model.PlanType == 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.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 (organization.PlanType != PlanType.Free && model.PlanType == PlanType.Free) - { - model.MaxStorageGb = null; - model.ExpirationDate = null; - model.Enabled = true; + 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; + } } UpdateOrganization(organization, model);