mirror of
https://github.com/bitwarden/server
synced 2025-12-19 09:43:25 +00:00
[AC-2313] Add Gateway fields to Provider edit in Admin (#4057)
* Formatting * Add Gateway fields to provider edit * Remove unnecessary usings * Thomas' feedback * Removing unnecessary using for linter * Removing unused file * Removing unused file
This commit is contained in:
@@ -10,16 +10,21 @@ public class ProviderEditModel : ProviderViewModel
|
||||
{
|
||||
public ProviderEditModel() { }
|
||||
|
||||
public ProviderEditModel(Provider provider, IEnumerable<ProviderUserUserDetails> providerUsers,
|
||||
IEnumerable<ProviderOrganizationOrganizationDetails> organizations, IEnumerable<ProviderPlan> providerPlans)
|
||||
: base(provider, providerUsers, organizations)
|
||||
public ProviderEditModel(
|
||||
Provider provider,
|
||||
IEnumerable<ProviderUserUserDetails> providerUsers,
|
||||
IEnumerable<ProviderOrganizationOrganizationDetails> organizations,
|
||||
IReadOnlyCollection<ProviderPlan> providerPlans) : base(provider, providerUsers, organizations)
|
||||
{
|
||||
Name = provider.DisplayName();
|
||||
BusinessName = provider.DisplayBusinessName();
|
||||
BillingEmail = provider.BillingEmail;
|
||||
BillingPhone = provider.BillingPhone;
|
||||
TeamsMinimumSeats = GetMinimumSeats(providerPlans, PlanType.TeamsMonthly);
|
||||
EnterpriseMinimumSeats = GetMinimumSeats(providerPlans, PlanType.EnterpriseMonthly);
|
||||
TeamsMonthlySeatMinimum = GetSeatMinimum(providerPlans, PlanType.TeamsMonthly);
|
||||
EnterpriseMonthlySeatMinimum = GetSeatMinimum(providerPlans, PlanType.EnterpriseMonthly);
|
||||
Gateway = provider.Gateway;
|
||||
GatewayCustomerId = provider.GatewayCustomerId;
|
||||
GatewaySubscriptionId = provider.GatewaySubscriptionId;
|
||||
}
|
||||
|
||||
[Display(Name = "Billing Email")]
|
||||
@@ -29,38 +34,28 @@ public class ProviderEditModel : ProviderViewModel
|
||||
[Display(Name = "Business Name")]
|
||||
public string BusinessName { get; set; }
|
||||
public string Name { get; set; }
|
||||
[Display(Name = "Teams minimum seats")]
|
||||
public int TeamsMinimumSeats { get; set; }
|
||||
[Display(Name = "Teams (Monthly) Seat Minimum")]
|
||||
public int TeamsMonthlySeatMinimum { get; set; }
|
||||
|
||||
[Display(Name = "Enterprise minimum seats")]
|
||||
public int EnterpriseMinimumSeats { get; set; }
|
||||
[Display(Name = "Events")]
|
||||
[Display(Name = "Enterprise (Monthly) Seat Minimum")]
|
||||
public int EnterpriseMonthlySeatMinimum { get; set; }
|
||||
[Display(Name = "Gateway")]
|
||||
public GatewayType? Gateway { get; set; }
|
||||
[Display(Name = "Gateway Customer Id")]
|
||||
public string GatewayCustomerId { get; set; }
|
||||
[Display(Name = "Gateway Subscription Id")]
|
||||
public string GatewaySubscriptionId { get; set; }
|
||||
|
||||
public IEnumerable<ProviderPlan> ToProviderPlan(IEnumerable<ProviderPlan> existingProviderPlans)
|
||||
public virtual Provider ToProvider(Provider existingProvider)
|
||||
{
|
||||
var providerPlans = existingProviderPlans.ToList();
|
||||
foreach (var existingProviderPlan in providerPlans)
|
||||
{
|
||||
existingProviderPlan.SeatMinimum = existingProviderPlan.PlanType switch
|
||||
{
|
||||
PlanType.TeamsMonthly => TeamsMinimumSeats,
|
||||
PlanType.EnterpriseMonthly => EnterpriseMinimumSeats,
|
||||
_ => existingProviderPlan.SeatMinimum
|
||||
};
|
||||
}
|
||||
return providerPlans;
|
||||
}
|
||||
|
||||
public Provider ToProvider(Provider existingProvider)
|
||||
{
|
||||
existingProvider.BillingEmail = BillingEmail?.ToLowerInvariant()?.Trim();
|
||||
existingProvider.BillingPhone = BillingPhone?.ToLowerInvariant()?.Trim();
|
||||
existingProvider.BillingEmail = BillingEmail?.ToLowerInvariant().Trim();
|
||||
existingProvider.BillingPhone = BillingPhone?.ToLowerInvariant().Trim();
|
||||
existingProvider.Gateway = Gateway;
|
||||
existingProvider.GatewayCustomerId = GatewayCustomerId;
|
||||
existingProvider.GatewaySubscriptionId = GatewaySubscriptionId;
|
||||
return existingProvider;
|
||||
}
|
||||
|
||||
|
||||
private int GetMinimumSeats(IEnumerable<ProviderPlan> providerPlans, PlanType planType)
|
||||
{
|
||||
return (from providerPlan in providerPlans where providerPlan.PlanType == planType select (int)providerPlan.SeatMinimum).FirstOrDefault();
|
||||
}
|
||||
private static int GetSeatMinimum(IEnumerable<ProviderPlan> providerPlans, PlanType planType)
|
||||
=> providerPlans.FirstOrDefault(providerPlan => providerPlan.PlanType == planType)?.SeatMinimum ?? 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user