From de79d57d6ea96d3fc1d902151baa55fe856a117a Mon Sep 17 00:00:00 2001 From: Conner Turnbull <133619638+cturnbull-bitwarden@users.noreply.github.com> Date: Mon, 29 Jul 2024 09:06:10 -0400 Subject: [PATCH] [AC-2820] Updated org edit form scripts to dynamically update expected values (#4439) * Updated org edit form scripts to dynamically update expected values * Added script to update null values on organization table * Updated script to only add MaxStorageGb for premium tiers. Removed setting of seats since it's not a valid edge case * Updated GetPlansHelper() to not use annonymous properties --- .../Models/OrganizationEditModel.cs | 64 +++++++++++++++- .../Shared/_OrganizationFormScripts.cshtml | 75 +++++++------------ ...024-07-01_00_EnsureMaxGBAndSeatsAreSet.sql | 10 +++ 3 files changed, 97 insertions(+), 52 deletions(-) create mode 100644 util/Migrator/DbScripts/2024-07-01_00_EnsureMaxGBAndSeatsAreSet.sql diff --git a/src/Admin/AdminConsole/Models/OrganizationEditModel.cs b/src/Admin/AdminConsole/Models/OrganizationEditModel.cs index 5fdd2bcc3..56782e695 100644 --- a/src/Admin/AdminConsole/Models/OrganizationEditModel.cs +++ b/src/Admin/AdminConsole/Models/OrganizationEditModel.cs @@ -179,13 +179,69 @@ public class OrganizationEditModel : OrganizationViewModel * This is mapped manually below to provide some type safety in case the plan objects change * Add mappings for individual properties as you need them */ - public IEnumerable> GetPlansHelper() => + public object GetPlansHelper() => StaticStore.Plans .Where(p => p.SupportsSecretsManager) - .Select(p => new Dictionary + .Select(p => { - { "type", p.Type }, - { "baseServiceAccount", p.SecretsManager.BaseServiceAccount } + var plan = new + { + Type = p.Type, + Has2fa = p.Has2fa, + HasApi = p.HasApi, + HasGroups = p.HasGroups, + HasPolicies = p.HasPolicies, + HasSso = p.HasSso, + HasScim = p.HasScim, + HasDirectory = p.HasDirectory, + HasEvents = p.HasEvents, + HasResetPassword = p.HasResetPassword, + HasCustomPermissions = p.HasCustomPermissions, + PasswordManager = + new + { + StripePlanId = p.PasswordManager?.StripePlanId, + StripeSeatPlanId = p.PasswordManager?.StripeSeatPlanId, + StripeProviderPortalSeatPlanId = p.PasswordManager?.StripeProviderPortalSeatPlanId, + BasePrice = p.PasswordManager?.BasePrice, + SeatPrice = p.PasswordManager?.SeatPrice, + ProviderPortalSeatPrice = p.PasswordManager?.ProviderPortalSeatPrice, + AllowSeatAutoscale = p.PasswordManager?.AllowSeatAutoscale, + HasAdditionalSeatsOption = p.PasswordManager?.HasAdditionalSeatsOption, + MaxAdditionalSeats = p.PasswordManager?.MaxAdditionalSeats, + BaseSeats = p.PasswordManager?.BaseSeats, + HasPremiumAccessOption = p.PasswordManager?.HasPremiumAccessOption, + StripePremiumAccessPlanId = p.PasswordManager?.StripePremiumAccessPlanId, + PremiumAccessOptionPrice = p.PasswordManager?.PremiumAccessOptionPrice, + MaxSeats = p.PasswordManager?.MaxSeats, + BaseStorageGb = p.PasswordManager?.BaseStorageGb, + HasAdditionalStorageOption = p.PasswordManager?.HasAdditionalStorageOption, + AdditionalStoragePricePerGb = p.PasswordManager?.AdditionalStoragePricePerGb, + StripeStoragePlanId = p.PasswordManager?.StripeStoragePlanId, + MaxAdditionalStorage = p.PasswordManager?.MaxAdditionalStorage, + MaxCollections = p.PasswordManager?.MaxCollections + }, + SecretsManager = new + { + MaxServiceAccounts = p.SecretsManager?.MaxServiceAccounts, + AllowServiceAccountsAutoscale = p.SecretsManager?.AllowServiceAccountsAutoscale, + StripeServiceAccountPlanId = p.SecretsManager?.StripeServiceAccountPlanId, + AdditionalPricePerServiceAccount = p.SecretsManager?.AdditionalPricePerServiceAccount, + BaseServiceAccount = p.SecretsManager?.BaseServiceAccount, + MaxAdditionalServiceAccount = p.SecretsManager?.MaxAdditionalServiceAccount, + HasAdditionalServiceAccountOption = p.SecretsManager?.HasAdditionalServiceAccountOption, + StripeSeatPlanId = p.SecretsManager?.StripeSeatPlanId, + HasAdditionalSeatsOption = p.SecretsManager?.HasAdditionalSeatsOption, + BasePrice = p.SecretsManager?.BasePrice, + SeatPrice = p.SecretsManager?.SeatPrice, + BaseSeats = p.SecretsManager?.BaseSeats, + MaxSeats = p.SecretsManager?.MaxSeats, + MaxAdditionalSeats = p.SecretsManager?.MaxAdditionalSeats, + AllowSeatAutoscale = p.SecretsManager?.AllowSeatAutoscale, + MaxProjects = p.SecretsManager?.MaxProjects + } + }; + return plan; }); public Organization CreateOrganization(Provider provider, bool flexibleCollectionsV1Enabled) diff --git a/src/Admin/AdminConsole/Views/Shared/_OrganizationFormScripts.cshtml b/src/Admin/AdminConsole/Views/Shared/_OrganizationFormScripts.cshtml index 5e0b938da..4dd3c6e27 100644 --- a/src/Admin/AdminConsole/Views/Shared/_OrganizationFormScripts.cshtml +++ b/src/Admin/AdminConsole/Views/Shared/_OrganizationFormScripts.cshtml @@ -2,6 +2,7 @@ @using Bit.Admin.Utilities @using Bit.Core.Billing.Enums @using Bit.Core.Enums +@using Bit.Core.Utilities @model OrganizationEditModel