Files
server/src/Admin/Models/OrganizationEditModel.cs

147 lines
6.2 KiB
C#
Raw Normal View History

2018-03-22 14:29:33 -04:00
using System;
2018-03-22 21:10:10 -04:00
using System.Collections.Generic;
2018-03-22 14:29:33 -04:00
using System.ComponentModel.DataAnnotations;
2018-03-22 21:10:10 -04:00
using Bit.Core.Enums;
2019-02-25 10:39:04 -05:00
using Bit.Core.Models.Business;
2018-03-22 21:10:10 -04:00
using Bit.Core.Models.Data;
2018-03-22 14:29:33 -04:00
using Bit.Core.Models.Table;
using Bit.Core.Utilities;
using Bit.Core.Settings;
2018-03-22 14:29:33 -04:00
namespace Bit.Admin.Models
{
2018-03-23 09:29:11 -04:00
public class OrganizationEditModel : OrganizationViewModel
2018-03-22 14:29:33 -04:00
{
public OrganizationEditModel() { }
2018-03-22 21:10:10 -04:00
public OrganizationEditModel(Organization org, IEnumerable<OrganizationUserUserDetails> orgUsers,
IEnumerable<Cipher> ciphers, IEnumerable<Collection> collections, IEnumerable<Group> groups,
IEnumerable<Policy> policies, BillingInfo billingInfo, GlobalSettings globalSettings)
: base(org, orgUsers, ciphers, collections, groups, policies)
2018-03-22 14:29:33 -04:00
{
2019-02-25 10:39:04 -05:00
BillingInfo = billingInfo;
BraintreeMerchantId = globalSettings.Braintree.MerchantId;
2018-03-22 14:29:33 -04:00
Name = org.Name;
BusinessName = org.BusinessName;
BillingEmail = org.BillingEmail;
PlanType = org.PlanType;
Plan = org.Plan;
Seats = org.Seats;
MaxAutoscaleSeats = org.MaxAutoscaleSeats;
2018-03-22 14:29:33 -04:00
MaxCollections = org.MaxCollections;
2020-01-15 15:00:54 -05:00
UsePolicies = org.UsePolicies;
UseSso = org.UseSso;
2018-03-22 14:29:33 -04:00
UseGroups = org.UseGroups;
UseDirectory = org.UseDirectory;
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;
UseResetPassword = org.UseResetPassword;
2018-03-22 14:29:33 -04:00
SelfHost = org.SelfHost;
UsersGetPremium = org.UsersGetPremium;
MaxStorageGb = org.MaxStorageGb;
Gateway = org.Gateway;
GatewayCustomerId = org.GatewayCustomerId;
GatewaySubscriptionId = org.GatewaySubscriptionId;
Enabled = org.Enabled;
LicenseKey = org.LicenseKey;
ExpirationDate = org.ExpirationDate;
}
2019-02-25 10:39:04 -05:00
public BillingInfo BillingInfo { get; set; }
public string RandomLicenseKey => CoreHelpers.SecureRandomString(20);
public string FourteenDayExpirationDate => DateTime.Now.AddDays(14).ToString("yyyy-MM-ddTHH:mm");
public string BraintreeMerchantId { get; set; }
2018-03-22 14:29:33 -04:00
[Required]
[Display(Name = "Name")]
public string Name { get; set; }
[Display(Name = "Business Name")]
public string BusinessName { get; set; }
[Display(Name = "Billing Email")]
public string BillingEmail { get; set; }
[Required]
[Display(Name = "Plan")]
2018-03-22 21:10:10 -04:00
public PlanType? PlanType { get; set; }
2018-03-22 14:29:33 -04:00
[Required]
[Display(Name = "Plan Name")]
public string Plan { get; set; }
[Display(Name = "Seats")]
Support large organization sync (#1311) * Increase organization max seat size from 30k to 2b (#1274) * Increase organization max seat size from 30k to 2b * PR review. Do not modify unless state matches expected * Organization sync simultaneous event reporting (#1275) * Split up azure messages according to max size * Allow simultaneous login of organization user events * Early resolve small event lists * Clarify logic Co-authored-by: Chad Scharf <3904944+cscharf@users.noreply.github.com> * Improve readability This comes at the cost of multiple serializations, but the improvement in wire-time should more than make up for this on message where serialization time matters Co-authored-by: Chad Scharf <3904944+cscharf@users.noreply.github.com> * Queue emails (#1286) * Extract common Azure queue methods * Do not use internal entity framework namespace * Prefer IEnumerable to IList unless needed All of these implementations were just using `Count == 1`, which is easily replicated. This will be used when abstracting Azure queues * Add model for azure queue message * Abstract Azure queue for reuse * Creat service to enqueue mail messages for later processing Azure queue mail service uses Azure queues. Blocking just blocks until all the work is done -- This is how emailing works today * Provide mail queue service to DI * Queue organization invite emails for later processing All emails can later be added to this queue * Create Admin hosted service to process enqueued mail messages * Prefer constructors to static generators * Mass delete organization users (#1287) * Add delete many to Organization Users * Correct formatting * Remove erroneous migration * Clarify parameter name * Formatting fixes * Simplify bump account revision sproc * Formatting fixes * Match file names to objects * Indicate if large import is expected * Early pull all existing users we were planning on inviting (#1290) * Early pull all existing users we were planning on inviting * Improve sproc name * Batch upsert org users (#1289) * Add UpsertMany sprocs to OrganizationUser * Add method to create TVPs from any object. Uses DbOrder attribute to generate. Sproc will fail unless TVP column order matches that of the db type * Combine migrations * Correct formatting * Include sql objects in sql project * Keep consisten parameter names * Batch deletes for performance * Correct formatting * consolidate migrations * Use batch methods in OrganizationImport * Declare @BatchSize * Transaction names limited to 32 chars Drop sproc before creating it if it exists * Update import tests * Allow for more users in org upgrades * Fix formatting * Improve class hierarchy structure * Use name tuple types * Fix formatting * Front load all reflection * Format constructor * Simplify ToTvp as class-specific extension Co-authored-by: Chad Scharf <3904944+cscharf@users.noreply.github.com>
2021-05-17 09:43:02 -05:00
public int? Seats { get; set; }
[Display(Name = "Max. Autoscale Seats")]
public int? MaxAutoscaleSeats { get; set; }
2018-03-22 14:29:33 -04:00
[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; }
[Display(Name = "SSO")]
public bool UseSso { get; set; }
2018-03-22 14:29:33 -04:00
[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; }
[Display(Name = "Reset Password")]
public bool UseResetPassword { 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; }
[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; }
public bool SalesAssistedTrialStarted { get; set; }
2018-03-22 14:29:33 -04:00
public Organization ToOrganization(Organization existingOrganization)
{
existingOrganization.Name = Name;
existingOrganization.BusinessName = BusinessName;
2019-06-12 22:08:53 -04:00
existingOrganization.BillingEmail = BillingEmail?.ToLowerInvariant()?.Trim();
2018-03-22 14:29:33 -04:00
existingOrganization.PlanType = PlanType.Value;
existingOrganization.Plan = Plan;
existingOrganization.Seats = Seats;
existingOrganization.MaxCollections = MaxCollections;
2020-01-15 15:00:54 -05:00
existingOrganization.UsePolicies = UsePolicies;
existingOrganization.UseSso = UseSso;
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;
existingOrganization.UseResetPassword = UseResetPassword;
2018-03-22 14:29:33 -04:00
existingOrganization.SelfHost = SelfHost;
existingOrganization.UsersGetPremium = UsersGetPremium;
existingOrganization.MaxStorageGb = MaxStorageGb;
existingOrganization.Gateway = Gateway;
existingOrganization.GatewayCustomerId = GatewayCustomerId;
existingOrganization.GatewaySubscriptionId = GatewaySubscriptionId;
existingOrganization.Enabled = Enabled;
existingOrganization.LicenseKey = LicenseKey;
existingOrganization.ExpirationDate = ExpirationDate;
existingOrganization.MaxAutoscaleSeats = MaxAutoscaleSeats;
2018-03-22 14:29:33 -04:00
return existingOrganization;
}
}
}