2022-06-29 19:46:41 -04:00
|
|
|
|
using System.ComponentModel.DataAnnotations;
|
2023-10-20 06:37:46 +10:00
|
|
|
|
using Bit.Core.AdminConsole.Entities;
|
2022-01-11 10:40:51 +01:00
|
|
|
|
using Bit.Core.Entities;
|
2023-04-14 11:13:16 +01:00
|
|
|
|
using Bit.Core.Entities.Provider;
|
2018-03-22 21:10:10 -04:00
|
|
|
|
using Bit.Core.Enums;
|
2023-04-14 11:13:16 +01:00
|
|
|
|
using Bit.Core.Enums.Provider;
|
2019-02-25 10:39:04 -05:00
|
|
|
|
using Bit.Core.Models.Business;
|
2022-05-10 17:12:09 -04:00
|
|
|
|
using Bit.Core.Models.Data.Organizations.OrganizationUsers;
|
2021-02-22 15:35:16 -06:00
|
|
|
|
using Bit.Core.Settings;
|
2018-03-22 17:33:22 -04:00
|
|
|
|
using Bit.Core.Utilities;
|
2023-03-02 13:23:38 -05:00
|
|
|
|
using Bit.Core.Vault.Entities;
|
2023-04-14 11:13:16 +01:00
|
|
|
|
using Bit.SharedWeb.Utilities;
|
2018-03-22 14:29:33 -04:00
|
|
|
|
|
|
|
|
|
|
namespace Bit.Admin.Models;
|
2022-08-29 16:06:55 -04:00
|
|
|
|
|
2018-03-22 14:29:33 -04:00
|
|
|
|
public class OrganizationEditModel : OrganizationViewModel
|
|
|
|
|
|
{
|
2018-03-22 17:33:22 -04:00
|
|
|
|
public OrganizationEditModel() { }
|
|
|
|
|
|
|
2023-04-14 11:13:16 +01:00
|
|
|
|
public OrganizationEditModel(Provider provider)
|
|
|
|
|
|
{
|
|
|
|
|
|
Provider = provider;
|
|
|
|
|
|
BillingEmail = provider.Type == ProviderType.Reseller ? provider.BillingEmail : string.Empty;
|
|
|
|
|
|
PlanType = Core.Enums.PlanType.TeamsMonthly;
|
|
|
|
|
|
Plan = Core.Enums.PlanType.TeamsMonthly.GetDisplayAttribute()?.GetName();
|
2023-08-04 17:44:33 +01:00
|
|
|
|
LicenseKey = RandomLicenseKey;
|
2023-04-14 11:13:16 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public OrganizationEditModel(Organization org, Provider provider, IEnumerable<OrganizationUserUserDetails> orgUsers,
|
2018-03-22 14:29:33 -04:00
|
|
|
|
IEnumerable<Cipher> ciphers, IEnumerable<Collection> collections, IEnumerable<Group> groups,
|
2020-01-15 15:00:54 -05:00
|
|
|
|
IEnumerable<Policy> policies, BillingInfo billingInfo, IEnumerable<OrganizationConnection> connections,
|
2023-08-16 09:03:17 +10:00
|
|
|
|
GlobalSettings globalSettings, int secrets, int projects, int serviceAccounts, int occupiedSmSeats)
|
2023-08-05 07:51:12 +10:00
|
|
|
|
: base(org, provider, connections, orgUsers, ciphers, collections, groups, policies, secrets, projects,
|
2023-08-16 09:03:17 +10:00
|
|
|
|
serviceAccounts, occupiedSmSeats)
|
2022-08-29 15:53:48 -04:00
|
|
|
|
{
|
2018-03-22 14:29:33 -04:00
|
|
|
|
BillingInfo = billingInfo;
|
|
|
|
|
|
BraintreeMerchantId = globalSettings.Braintree.MerchantId;
|
|
|
|
|
|
|
|
|
|
|
|
Name = org.Name;
|
2019-02-25 10:39:04 -05:00
|
|
|
|
BusinessName = org.BusinessName;
|
2023-04-14 11:13:16 +01:00
|
|
|
|
BillingEmail = provider?.Type == ProviderType.Reseller ? provider.BillingEmail : org.BillingEmail;
|
2018-03-22 17:33:22 -04:00
|
|
|
|
PlanType = org.PlanType;
|
2018-03-22 14:29:33 -04:00
|
|
|
|
Plan = org.Plan;
|
2018-03-22 17:33:22 -04:00
|
|
|
|
Seats = org.Seats;
|
2021-09-23 06:36:08 -04:00
|
|
|
|
MaxAutoscaleSeats = org.MaxAutoscaleSeats;
|
2018-03-22 17:33:22 -04:00
|
|
|
|
MaxCollections = org.MaxCollections;
|
2020-01-15 15:00:54 -05:00
|
|
|
|
UsePolicies = org.UsePolicies;
|
2020-07-22 09:38:39 -04:00
|
|
|
|
UseSso = org.UseSso;
|
2021-11-17 11:46:35 +01:00
|
|
|
|
UseKeyConnector = org.UseKeyConnector;
|
2022-07-14 15:58:48 -04:00
|
|
|
|
UseScim = org.UseScim;
|
2018-03-22 14:29:33 -04:00
|
|
|
|
UseGroups = org.UseGroups;
|
2018-03-22 17:33:22 -04:00
|
|
|
|
UseDirectory = org.UseDirectory;
|
2018-03-22 14:29:33 -04:00
|
|
|
|
UseEvents = org.UseEvents;
|
|
|
|
|
|
UseTotp = org.UseTotp;
|
2018-04-20 16:37:17 -04:00
|
|
|
|
Use2fa = org.Use2fa;
|
2019-03-02 15:09:33 -05:00
|
|
|
|
UseApi = org.UseApi;
|
2023-01-13 15:02:53 +01:00
|
|
|
|
UseSecretsManager = org.UseSecretsManager;
|
2021-06-07 09:08:34 -05:00
|
|
|
|
UseResetPassword = org.UseResetPassword;
|
2018-03-22 17:33:22 -04:00
|
|
|
|
SelfHost = org.SelfHost;
|
|
|
|
|
|
UsersGetPremium = org.UsersGetPremium;
|
2022-12-06 09:50:08 +00:00
|
|
|
|
UseCustomPermissions = org.UseCustomPermissions;
|
2018-03-22 17:33:22 -04:00
|
|
|
|
MaxStorageGb = org.MaxStorageGb;
|
2018-03-22 14:29:33 -04:00
|
|
|
|
Gateway = org.Gateway;
|
2018-03-22 17:33:22 -04:00
|
|
|
|
GatewayCustomerId = org.GatewayCustomerId;
|
|
|
|
|
|
GatewaySubscriptionId = org.GatewaySubscriptionId;
|
|
|
|
|
|
Enabled = org.Enabled;
|
|
|
|
|
|
LicenseKey = org.LicenseKey;
|
|
|
|
|
|
ExpirationDate = org.ExpirationDate;
|
2023-06-27 05:23:23 -04:00
|
|
|
|
SmSeats = org.SmSeats;
|
|
|
|
|
|
MaxAutoscaleSmSeats = org.MaxAutoscaleSmSeats;
|
|
|
|
|
|
SmServiceAccounts = org.SmServiceAccounts;
|
|
|
|
|
|
MaxAutoscaleSmServiceAccounts = org.MaxAutoscaleSmServiceAccounts;
|
2023-07-26 18:24:09 -04:00
|
|
|
|
SecretsManagerBeta = org.SecretsManagerBeta;
|
2018-03-22 17:33:22 -04:00
|
|
|
|
}
|
2018-03-22 14:29:33 -04:00
|
|
|
|
|
|
|
|
|
|
public BillingInfo BillingInfo { get; set; }
|
2021-11-17 11:46:35 +01:00
|
|
|
|
public string RandomLicenseKey => CoreHelpers.SecureRandomString(20);
|
2018-03-22 14:29:33 -04:00
|
|
|
|
public string FourteenDayExpirationDate => DateTime.Now.AddDays(14).ToString("yyyy-MM-ddTHH:mm");
|
|
|
|
|
|
public string BraintreeMerchantId { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
[Required]
|
2023-04-14 11:13:16 +01:00
|
|
|
|
[Display(Name = "Organization Name")]
|
2018-03-22 14:29:33 -04:00
|
|
|
|
public string Name { get; set; }
|
|
|
|
|
|
[Display(Name = "Business Name")]
|
|
|
|
|
|
public string BusinessName { get; set; }
|
2019-06-12 22:08:53 -04:00
|
|
|
|
[Display(Name = "Billing Email")]
|
|
|
|
|
|
public string BillingEmail { get; set; }
|
2018-03-22 14:29:33 -04:00
|
|
|
|
[Required]
|
|
|
|
|
|
[Display(Name = "Plan")]
|
|
|
|
|
|
public PlanType? PlanType { get; set; }
|
|
|
|
|
|
[Required]
|
|
|
|
|
|
[Display(Name = "Plan Name")]
|
|
|
|
|
|
public string Plan { get; set; }
|
|
|
|
|
|
[Display(Name = "Seats")]
|
|
|
|
|
|
public int? Seats { get; set; }
|
|
|
|
|
|
[Display(Name = "Max. Autoscale Seats")]
|
|
|
|
|
|
public int? MaxAutoscaleSeats { get; set; }
|
|
|
|
|
|
[Display(Name = "Max. Collections")]
|
|
|
|
|
|
public short? MaxCollections { get; set; }
|
2020-01-15 15:00:54 -05:00
|
|
|
|
[Display(Name = "Policies")]
|
|
|
|
|
|
public bool UsePolicies { get; set; }
|
2020-07-22 09:38:39 -04:00
|
|
|
|
[Display(Name = "SSO")]
|
|
|
|
|
|
public bool UseSso { get; set; }
|
2021-11-17 11:46:35 +01:00
|
|
|
|
[Display(Name = "Key Connector with Customer Encryption")]
|
2018-03-22 14:29:33 -04:00
|
|
|
|
public bool UseKeyConnector { get; set; }
|
|
|
|
|
|
[Display(Name = "Groups")]
|
|
|
|
|
|
public bool UseGroups { get; set; }
|
|
|
|
|
|
[Display(Name = "Directory")]
|
|
|
|
|
|
public bool UseDirectory { get; set; }
|
|
|
|
|
|
[Display(Name = "Events")]
|
|
|
|
|
|
public bool UseEvents { get; set; }
|
|
|
|
|
|
[Display(Name = "TOTP")]
|
|
|
|
|
|
public bool UseTotp { get; set; }
|
2018-04-20 16:37:17 -04:00
|
|
|
|
[Display(Name = "2FA")]
|
2018-04-20 16:45:41 -04:00
|
|
|
|
public bool Use2fa { get; set; }
|
2019-03-02 15:09:33 -05:00
|
|
|
|
[Display(Name = "API")]
|
|
|
|
|
|
public bool UseApi { get; set; }
|
2021-06-07 09:08:34 -05:00
|
|
|
|
[Display(Name = "Reset Password")]
|
2020-07-22 09:38:39 -04:00
|
|
|
|
public bool UseResetPassword { get; set; }
|
2022-07-14 15:58:48 -04:00
|
|
|
|
[Display(Name = "SCIM")]
|
|
|
|
|
|
public bool UseScim { get; set; }
|
2023-01-13 15:02:53 +01:00
|
|
|
|
[Display(Name = "Secrets Manager")]
|
|
|
|
|
|
public bool UseSecretsManager { get; set; }
|
2018-04-20 16:45:41 -04:00
|
|
|
|
[Display(Name = "Self Host")]
|
2018-03-22 14:29:33 -04:00
|
|
|
|
public bool SelfHost { get; set; }
|
|
|
|
|
|
[Display(Name = "Users Get Premium")]
|
|
|
|
|
|
public bool UsersGetPremium { get; set; }
|
2022-12-06 09:50:08 +00:00
|
|
|
|
[Display(Name = "Custom Permissions")]
|
|
|
|
|
|
public bool UseCustomPermissions { get; set; }
|
2018-03-22 14:29:33 -04:00
|
|
|
|
[Display(Name = "Max. Storage GB")]
|
|
|
|
|
|
public short? MaxStorageGb { get; set; }
|
|
|
|
|
|
[Display(Name = "Gateway")]
|
2018-03-22 21:10:10 -04:00
|
|
|
|
public GatewayType? Gateway { get; set; }
|
2018-03-22 14:29:33 -04:00
|
|
|
|
[Display(Name = "Gateway Customer Id")]
|
|
|
|
|
|
public string GatewayCustomerId { get; set; }
|
|
|
|
|
|
[Display(Name = "Gateway Subscription Id")]
|
|
|
|
|
|
public string GatewaySubscriptionId { get; set; }
|
|
|
|
|
|
[Display(Name = "Enabled")]
|
|
|
|
|
|
public bool Enabled { get; set; }
|
|
|
|
|
|
[Display(Name = "License Key")]
|
|
|
|
|
|
public string LicenseKey { get; set; }
|
|
|
|
|
|
[Display(Name = "Expiration Date")]
|
|
|
|
|
|
public DateTime? ExpirationDate { get; set; }
|
2021-08-11 12:44:30 -04:00
|
|
|
|
public bool SalesAssistedTrialStarted { get; set; }
|
2023-06-27 05:23:23 -04:00
|
|
|
|
[Display(Name = "Seats")]
|
|
|
|
|
|
public int? SmSeats { get; set; }
|
|
|
|
|
|
[Display(Name = "Max Autoscale Seats")]
|
|
|
|
|
|
public int? MaxAutoscaleSmSeats { get; set; }
|
2023-08-16 09:03:17 +10:00
|
|
|
|
[Display(Name = "Service Accounts")]
|
2023-06-27 05:23:23 -04:00
|
|
|
|
public int? SmServiceAccounts { get; set; }
|
|
|
|
|
|
[Display(Name = "Max Autoscale Service Accounts")]
|
|
|
|
|
|
public int? MaxAutoscaleSmServiceAccounts { get; set; }
|
2023-07-26 18:24:09 -04:00
|
|
|
|
[Display(Name = "Secrets Manager Beta")]
|
|
|
|
|
|
public bool SecretsManagerBeta { get; set; }
|
2022-08-29 15:53:48 -04:00
|
|
|
|
|
2023-08-16 09:03:17 +10:00
|
|
|
|
/**
|
|
|
|
|
|
* Creates a Plan[] object for use in Javascript
|
|
|
|
|
|
* 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() =>
|
2023-10-17 15:56:35 +01:00
|
|
|
|
StaticStore.Plans
|
|
|
|
|
|
.Where(p => p.SupportsSecretsManager)
|
|
|
|
|
|
.Select(p => new Dictionary<string, object>
|
2023-08-16 09:03:17 +10:00
|
|
|
|
{
|
|
|
|
|
|
{ "type", p.Type },
|
2023-10-17 15:56:35 +01:00
|
|
|
|
{ "baseServiceAccount", p.SecretsManager.BaseServiceAccount }
|
2023-08-16 09:03:17 +10:00
|
|
|
|
});
|
|
|
|
|
|
|
2023-04-14 11:13:16 +01:00
|
|
|
|
public Organization CreateOrganization(Provider provider)
|
|
|
|
|
|
{
|
|
|
|
|
|
BillingEmail = provider.BillingEmail;
|
|
|
|
|
|
|
|
|
|
|
|
return ToOrganization(new Organization());
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-07-22 09:38:39 -04:00
|
|
|
|
public Organization ToOrganization(Organization existingOrganization)
|
2022-08-29 15:53:48 -04:00
|
|
|
|
{
|
2021-11-17 11:46:35 +01:00
|
|
|
|
existingOrganization.Name = Name;
|
|
|
|
|
|
existingOrganization.BusinessName = BusinessName;
|
|
|
|
|
|
existingOrganization.BillingEmail = BillingEmail?.ToLowerInvariant()?.Trim();
|
2018-03-22 14:29:33 -04:00
|
|
|
|
existingOrganization.PlanType = PlanType.Value;
|
|
|
|
|
|
existingOrganization.Plan = Plan;
|
2022-07-14 15:58:48 -04:00
|
|
|
|
existingOrganization.Seats = Seats;
|
2022-05-10 17:12:09 -04:00
|
|
|
|
existingOrganization.MaxCollections = MaxCollections;
|
2018-03-22 14:29:33 -04:00
|
|
|
|
existingOrganization.UsePolicies = UsePolicies;
|
2020-01-15 15:00:54 -05:00
|
|
|
|
existingOrganization.UseSso = UseSso;
|
2018-03-22 14:29:33 -04:00
|
|
|
|
existingOrganization.UseKeyConnector = UseKeyConnector;
|
2020-01-15 15:00:54 -05:00
|
|
|
|
existingOrganization.UseScim = UseScim;
|
2018-03-22 14:29:33 -04:00
|
|
|
|
existingOrganization.UseGroups = UseGroups;
|
|
|
|
|
|
existingOrganization.UseDirectory = UseDirectory;
|
|
|
|
|
|
existingOrganization.UseEvents = UseEvents;
|
|
|
|
|
|
existingOrganization.UseTotp = UseTotp;
|
2018-04-20 16:37:17 -04:00
|
|
|
|
existingOrganization.Use2fa = Use2fa;
|
2019-03-02 15:09:33 -05:00
|
|
|
|
existingOrganization.UseApi = UseApi;
|
2023-01-13 15:02:53 +01:00
|
|
|
|
existingOrganization.UseSecretsManager = UseSecretsManager;
|
2021-06-07 09:08:34 -05:00
|
|
|
|
existingOrganization.UseResetPassword = UseResetPassword;
|
2018-03-22 14:29:33 -04:00
|
|
|
|
existingOrganization.SelfHost = SelfHost;
|
|
|
|
|
|
existingOrganization.UsersGetPremium = UsersGetPremium;
|
2022-12-06 09:50:08 +00:00
|
|
|
|
existingOrganization.UseCustomPermissions = UseCustomPermissions;
|
2018-03-22 14:29:33 -04:00
|
|
|
|
existingOrganization.MaxStorageGb = MaxStorageGb;
|
|
|
|
|
|
existingOrganization.Gateway = Gateway;
|
|
|
|
|
|
existingOrganization.GatewayCustomerId = GatewayCustomerId;
|
|
|
|
|
|
existingOrganization.GatewaySubscriptionId = GatewaySubscriptionId;
|
|
|
|
|
|
existingOrganization.Enabled = Enabled;
|
|
|
|
|
|
existingOrganization.LicenseKey = LicenseKey;
|
|
|
|
|
|
existingOrganization.ExpirationDate = ExpirationDate;
|
2021-09-23 06:36:08 -04:00
|
|
|
|
existingOrganization.MaxAutoscaleSeats = MaxAutoscaleSeats;
|
2023-06-27 05:23:23 -04:00
|
|
|
|
existingOrganization.SmSeats = SmSeats;
|
|
|
|
|
|
existingOrganization.MaxAutoscaleSmSeats = MaxAutoscaleSmSeats;
|
|
|
|
|
|
existingOrganization.SmServiceAccounts = SmServiceAccounts;
|
|
|
|
|
|
existingOrganization.MaxAutoscaleSmServiceAccounts = MaxAutoscaleSmServiceAccounts;
|
2023-07-26 18:24:09 -04:00
|
|
|
|
existingOrganization.SecretsManagerBeta = SecretsManagerBeta;
|
2018-03-22 14:29:33 -04:00
|
|
|
|
return existingOrganization;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|