Skip to content

Commit

Permalink
Consolidated features within teams and enterprise tiers
Browse files Browse the repository at this point in the history
  • Loading branch information
cturnbull-bitwarden committed Oct 6, 2023
1 parent 4dcd467 commit f55a1d3
Show file tree
Hide file tree
Showing 16 changed files with 567 additions and 83 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,8 @@ await sutProvider.GetDependency<IProjectRepository>().DidNotReceiveWithAnyArgs()

[Theory]
[BitAutoData(PlanType.FamiliesAnnually2019)]
[BitAutoData(PlanType.TeamsMonthly2019)]
[BitAutoData(PlanType.TeamsAnnually2019)]
[BitAutoData(PlanType.EnterpriseMonthly2019)]
[BitAutoData(PlanType.EnterpriseAnnually2019)]
[BitAutoData(PlanType.Custom)]
[BitAutoData(PlanType.FamiliesAnnually)]
[BitAutoData(PlanType.Custom)]
public async Task GetByOrgIdAsync_SmPlanIsNull_ThrowsBadRequest(PlanType planType,
SutProvider<MaxProjectsQuery> sutProvider, Organization organization)
{
Expand Down
8 changes: 8 additions & 0 deletions src/Admin/Views/Shared/_OrganizationFormScripts.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@
function togglePlanFeatures(planType) {
switch(planType) {
case '@((byte)PlanType.TeamsMonthly2019)':
case '@((byte)PlanType.TeamsAnnually2019)':
case '@((byte)PlanType.TeamsMonthly2020)':
case '@((byte)PlanType.TeamsAnnually2020)':
case '@((byte)PlanType.TeamsMonthly)':
case '@((byte)PlanType.TeamsAnnually)':
document.getElementById('@(nameof(Model.UsePolicies))').checked = false;
Expand All @@ -81,6 +85,10 @@
document.getElementById('@(nameof(Model.UseScim))').checked = false;
break;
case '@((byte)PlanType.EnterpriseMonthly2019)':
case '@((byte)PlanType.EnterpriseAnnually2019)':
case '@((byte)PlanType.EnterpriseMonthly2020)':
case '@((byte)PlanType.EnterpriseAnnually2020)':
case '@((byte)PlanType.EnterpriseMonthly)':
case '@((byte)PlanType.EnterpriseAnnually)':
document.getElementById('@(nameof(Model.UsePolicies))').checked = true;
Expand Down
4 changes: 2 additions & 2 deletions src/Api/Models/Response/ProfileOrganizationResponseModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ public ProfileOrganizationResponseModel(OrganizationUserOrganizationDetails orga
UsePasswordManager = organization.UsePasswordManager;
UsersGetPremium = organization.UsersGetPremium;
UseCustomPermissions = organization.UseCustomPermissions;
UseActivateAutofillPolicy = organization.PlanType == PlanType.EnterpriseAnnually ||
organization.PlanType == PlanType.EnterpriseMonthly;
UseActivateAutofillPolicy =
StaticStore.GetPasswordManagerPlan(organization.PlanType).Product == ProductType.Enterprise;
SelfHost = organization.SelfHost;
Seats = organization.Seats;
MaxCollections = organization.MaxCollections;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ public ProfileProviderOrganizationResponseModel(ProviderUserOrganizationDetails
UseResetPassword = organization.UseResetPassword;
UsersGetPremium = organization.UsersGetPremium;
UseCustomPermissions = organization.UseCustomPermissions;
UseActivateAutofillPolicy = organization.PlanType == PlanType.EnterpriseAnnually ||
organization.PlanType == PlanType.EnterpriseMonthly;
UseActivateAutofillPolicy =
StaticStore.GetPasswordManagerPlan(organization.PlanType).Product == ProductType.Enterprise;
SelfHost = organization.SelfHost;
Seats = organization.Seats;
MaxCollections = organization.MaxCollections;
Expand Down
4 changes: 4 additions & 0 deletions src/Billing/Controllers/FreshsalesController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -159,14 +159,18 @@ private static bool TryGetPlanName(PlanType planType, out string planName)
planName = "Families";
return true;
case PlanType.TeamsAnnually:
case PlanType.TeamsAnnually2020:
case PlanType.TeamsAnnually2019:
case PlanType.TeamsMonthly:
case PlanType.TeamsMonthly2020:
case PlanType.TeamsMonthly2019:
planName = "Teams";
return true;
case PlanType.EnterpriseAnnually:
case PlanType.EnterpriseAnnually2020:
case PlanType.EnterpriseAnnually2019:
case PlanType.EnterpriseMonthly:
case PlanType.EnterpriseMonthly2020:
case PlanType.EnterpriseMonthly2019:
planName = "Enterprise";
return true;
Expand Down
17 changes: 4 additions & 13 deletions src/Billing/Controllers/StripeController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ await _userService.UpdatePremiumExpirationAsync(userId,
}

var org = await _organizationRepository.GetByIdAsync(ids.Item1.Value);
if (org != null && OrgPlanForInvoiceNotifications(org))
if (org != null && OrgPlanShouldSendUpcomingInvoiceNotificationEmail(org))
{
email = org.BillingEmail;
}
Expand Down Expand Up @@ -710,18 +710,9 @@ private async Task AttemptToPayOpenSubscriptionAsync(Subscription unpaidSubscrip
return new Tuple<Guid?, Guid?>(orgId, userId);
}

private bool OrgPlanForInvoiceNotifications(Organization org)
{
switch (org.PlanType)
{
case PlanType.FamiliesAnnually:
case PlanType.TeamsAnnually:
case PlanType.EnterpriseAnnually:
return true;
default:
return false;
}
}
private static bool OrgPlanShouldSendUpcomingInvoiceNotificationEmail(Organization org) =>
StaticStore.GetPasswordManagerPlan(org.PlanType)
.IsAnnual;

private async Task<bool> AttemptToPayInvoiceAsync(Invoice invoice, bool attemptToPayWithStripe = false)
{
Expand Down
16 changes: 12 additions & 4 deletions src/Core/Enums/PlanType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,20 @@ public enum PlanType : byte
Custom = 6,
[Display(Name = "Families")]
FamiliesAnnually = 7,
[Display(Name = "Teams (Monthly) 2023")]
TeamsMonthly2020 = 8,
[Display(Name = "Teams (Annually) 2023")]
TeamsAnnually2020 = 9,
[Display(Name = "Enterprise (Monthly) 2023")]
EnterpriseMonthly2020 = 10,
[Display(Name = "Enterprise (Annually) 2023")]
EnterpriseAnnually2020 = 11,
[Display(Name = "Teams (Monthly)")]
TeamsMonthly = 8,
TeamsMonthly = 12,
[Display(Name = "Teams (Annually)")]
TeamsAnnually = 9,
TeamsAnnually = 13,
[Display(Name = "Enterprise (Monthly)")]
EnterpriseMonthly = 10,
EnterpriseMonthly = 14,
[Display(Name = "Enterprise (Annually)")]
EnterpriseAnnually = 11,
EnterpriseAnnually = 15,
}
5 changes: 0 additions & 5 deletions src/Core/Services/Implementations/OrganizationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1936,11 +1936,6 @@ private async Task<Organization> GetOrgById(Guid id)

private static void ValidatePlan(Models.StaticStore.Plan plan, int additionalSeats, string productType)
{
if (plan is not { LegacyYear: null })
{
throw new BadRequestException($"Invalid {productType} plan selected.");
}

if (plan.Disabled)
{
throw new BadRequestException($"{productType} Plan not found.");
Expand Down
16 changes: 0 additions & 16 deletions src/Core/Services/Implementations/PolicyService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,6 @@ public async Task SaveAsync(Policy policy, IUserService userService, IOrganizati
await DependsOnSingleOrgAsync(org);
}
break;

// Activate Autofill is only available to Enterprise 2020-current plans
case PolicyType.ActivateAutofill:
if (policy.Enabled)
{
LockedTo2020Plan(org);
}
break;
}

var now = DateTime.UtcNow;
Expand Down Expand Up @@ -274,14 +266,6 @@ private async Task RequiredByVaultTimeoutAsync(Organization org)
}
}

private void LockedTo2020Plan(Organization org)
{
if (org.PlanType != PlanType.EnterpriseAnnually && org.PlanType != PlanType.EnterpriseMonthly)
{
throw new BadRequestException("This policy is only available to 2020 Enterprise plans.");
}
}

private async Task RequiredBySsoTrustedDeviceEncryptionAsync(Organization org)
{
var ssoConfig = await _ssoConfigRepository.GetByOrganizationIdAsync(org.Id);
Expand Down
Loading

0 comments on commit f55a1d3

Please sign in to comment.