mirror of
https://github.com/bitwarden/server.git
synced 2024-11-21 12:05:42 +01:00
[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
This commit is contained in:
parent
54bd5fa894
commit
de79d57d6e
@ -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<Dictionary<string, object>> GetPlansHelper() =>
|
||||
public object GetPlansHelper() =>
|
||||
StaticStore.Plans
|
||||
.Where(p => p.SupportsSecretsManager)
|
||||
.Select(p => new Dictionary<string, object>
|
||||
.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)
|
||||
|
@ -2,6 +2,7 @@
|
||||
@using Bit.Admin.Utilities
|
||||
@using Bit.Core.Billing.Enums
|
||||
@using Bit.Core.Enums
|
||||
@using Bit.Core.Utilities
|
||||
@model OrganizationEditModel
|
||||
|
||||
<script>
|
||||
@ -53,55 +54,33 @@
|
||||
})();
|
||||
|
||||
function togglePlanFeatures(planType) {
|
||||
switch(planType) {
|
||||
case '@((byte)PlanType.TeamsMonthly2019)':
|
||||
case '@((byte)PlanType.TeamsAnnually2019)':
|
||||
case '@((byte)PlanType.TeamsMonthly2020)':
|
||||
case '@((byte)PlanType.TeamsAnnually2020)':
|
||||
case '@((byte)PlanType.TeamsMonthly2023)':
|
||||
case '@((byte)PlanType.TeamsAnnually2023)':
|
||||
case '@((byte)PlanType.TeamsMonthly)':
|
||||
case '@((byte)PlanType.TeamsAnnually)':
|
||||
case '@((byte)PlanType.TeamsStarter2023)':
|
||||
case '@((byte)PlanType.TeamsStarter)':
|
||||
document.getElementById('@(nameof(Model.UsePolicies))').checked = false;
|
||||
document.getElementById('@(nameof(Model.UseSso))').checked = false;
|
||||
document.getElementById('@(nameof(Model.UseGroups))').checked = true;
|
||||
document.getElementById('@(nameof(Model.UseDirectory))').checked = true;
|
||||
document.getElementById('@(nameof(Model.UseEvents))').checked = true;
|
||||
document.getElementById('@(nameof(Model.UsersGetPremium))').checked = true;
|
||||
document.getElementById('@(nameof(Model.UseCustomPermissions))').checked = false;
|
||||
document.getElementById('@(nameof(Model.UseTotp))').checked = true;
|
||||
document.getElementById('@(nameof(Model.Use2fa))').checked = true;
|
||||
document.getElementById('@(nameof(Model.UseApi))').checked = true;
|
||||
document.getElementById('@(nameof(Model.SelfHost))').checked = false;
|
||||
document.getElementById('@(nameof(Model.UseResetPassword))').checked = false;
|
||||
document.getElementById('@(nameof(Model.UseScim))').checked = false;
|
||||
break;
|
||||
const plan = getPlan(planType);
|
||||
|
||||
case '@((byte)PlanType.EnterpriseMonthly2019)':
|
||||
case '@((byte)PlanType.EnterpriseAnnually2019)':
|
||||
case '@((byte)PlanType.EnterpriseMonthly2020)':
|
||||
case '@((byte)PlanType.EnterpriseAnnually2020)':
|
||||
case '@((byte)PlanType.EnterpriseMonthly2023)':
|
||||
case '@((byte)PlanType.EnterpriseAnnually2023)':
|
||||
case '@((byte)PlanType.EnterpriseMonthly)':
|
||||
case '@((byte)PlanType.EnterpriseAnnually)':
|
||||
document.getElementById('@(nameof(Model.UsePolicies))').checked = true;
|
||||
document.getElementById('@(nameof(Model.UseSso))').checked = true;
|
||||
document.getElementById('@(nameof(Model.UseGroups))').checked = true;
|
||||
document.getElementById('@(nameof(Model.UseDirectory))').checked = true;
|
||||
document.getElementById('@(nameof(Model.UseEvents))').checked = true;
|
||||
document.getElementById('@(nameof(Model.UsersGetPremium))').checked = true;
|
||||
document.getElementById('@(nameof(Model.UseCustomPermissions))').checked = true;
|
||||
document.getElementById('@(nameof(Model.UseTotp))').checked = true;
|
||||
document.getElementById('@(nameof(Model.Use2fa))').checked = true;
|
||||
document.getElementById('@(nameof(Model.UseApi))').checked = true;
|
||||
document.getElementById('@(nameof(Model.SelfHost))').checked = true;
|
||||
document.getElementById('@(nameof(Model.UseResetPassword))').checked = true;
|
||||
document.getElementById('@(nameof(Model.UseScim))').checked = true;
|
||||
break;
|
||||
if (!plan) {
|
||||
return;
|
||||
}
|
||||
|
||||
console.log(plan);
|
||||
|
||||
document.getElementById('@(nameof(Model.SelfHost))').checked = plan.hasSelfHost;
|
||||
|
||||
document.getElementById('@(nameof(Model.Use2fa))').checked = plan.has2fa;
|
||||
document.getElementById('@(nameof(Model.UseApi))').checked = plan.hasApi;
|
||||
document.getElementById('@(nameof(Model.UseGroups))').checked = plan.hasGroups;
|
||||
document.getElementById('@(nameof(Model.UsePolicies))').checked = plan.hasPolicies;
|
||||
document.getElementById('@(nameof(Model.UseSso))').checked = plan.hasSso;
|
||||
document.getElementById('@(nameof(Model.UseScim))').checked = plan.hasScim;
|
||||
document.getElementById('@(nameof(Model.UseDirectory))').checked = plan.hasDirectory;
|
||||
document.getElementById('@(nameof(Model.UseEvents))').checked = plan.hasEvents;
|
||||
document.getElementById('@(nameof(Model.UseResetPassword))').checked = plan.hasResetPassword;
|
||||
document.getElementById('@(nameof(Model.UseCustomPermissions))').checked = plan.hasCustomPermissions;
|
||||
// use key connector is intentionally omitted
|
||||
|
||||
document.getElementById('@(nameof(Model.UseTotp))').checked = plan.hasTotp;
|
||||
document.getElementById('@(nameof(Model.UsersGetPremium))').checked = plan.usersGetPremium;
|
||||
|
||||
document.getElementById('@(nameof(Model.MaxStorageGb))').value = plan.passwordManager.baseStorageGb || 1;
|
||||
document.getElementById('@(nameof(Model.Seats))').value = plan.passwordManager.baseSeats || 1;
|
||||
}
|
||||
|
||||
function unlinkProvider(id) {
|
||||
@ -134,7 +113,7 @@
|
||||
document.getElementById('@(nameof(Model.SmSeats))').value = Math.max(@Model.OccupiedSmSeatsCount, 1);
|
||||
|
||||
// Service accounts
|
||||
const baseServiceAccounts = getPlan(planType)?.baseServiceAccount ?? 0;
|
||||
const baseServiceAccounts = getPlan(planType)?.secretsManager?.baseServiceAccount ?? 0;
|
||||
if (planType !== '@((byte)PlanType.Free)' && @Model.ServiceAccountsCount > baseServiceAccounts) {
|
||||
document.getElementById('@(nameof(Model.SmServiceAccounts))').value = @Model.ServiceAccountsCount;
|
||||
} else {
|
||||
|
@ -0,0 +1,10 @@
|
||||
UPDATE
|
||||
[dbo].[Organization]
|
||||
SET
|
||||
[MaxStorageGb] = ISNULL([MaxStorageGb], 1)
|
||||
WHERE
|
||||
[MaxStorageGb] IS NULL
|
||||
AND [PlanType] NOT IN (
|
||||
0, --Free
|
||||
6 --Custom
|
||||
)
|
Loading…
Reference in New Issue
Block a user