1
0
mirror of https://github.com/bitwarden/server.git synced 2025-07-04 09:32:48 -05:00

Cleaned up feature flag logic now that it's released (#3490)

This commit is contained in:
Conner Turnbull
2023-12-04 08:16:25 -05:00
committed by GitHub
parent f9941f5dfe
commit a31295df26
3 changed files with 3 additions and 37 deletions

View File

@ -1,9 +1,5 @@
using Bit.Api.Models.Response;
using Bit.Core;
using Bit.Core.Context;
using Bit.Core.Enums;
using Bit.Core.Repositories;
using Bit.Core.Services;
using Bit.Core.Utilities;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
@ -15,42 +11,14 @@ namespace Bit.Api.Controllers;
public class PlansController : Controller
{
private readonly ITaxRateRepository _taxRateRepository;
private readonly IFeatureService _featureService;
private readonly ICurrentContext _currentContext;
public PlansController(
ITaxRateRepository taxRateRepository,
IFeatureService featureService,
ICurrentContext currentContext)
{
_taxRateRepository = taxRateRepository;
_featureService = featureService;
_currentContext = currentContext;
}
public PlansController(ITaxRateRepository taxRateRepository) => _taxRateRepository = taxRateRepository;
[HttpGet("")]
[AllowAnonymous]
public ListResponseModel<PlanResponseModel> Get()
{
var plansUpgradeIsEnabled = _featureService.IsEnabled(FeatureFlagKeys.BillingPlansUpgrade, _currentContext);
var teamsStarterPlanIsEnabled = _featureService.IsEnabled(FeatureFlagKeys.BillingStarterPlan, _currentContext);
var responses = StaticStore.Plans
// If plans upgrade is disabled, return only the original plans. Otherwise, return everything
.Where(plan => plansUpgradeIsEnabled || plan.Type <= PlanType.EnterpriseAnnually2020 || plan.Type == PlanType.TeamsStarter)
// If teams starter is disabled, don't return that plan, otherwise return everything
.Where(plan => teamsStarterPlanIsEnabled || plan.Product != ProductType.TeamsStarter)
.Select(plan =>
{
if (!plansUpgradeIsEnabled && plan.Type is <= PlanType.EnterpriseAnnually2020 and >= PlanType.TeamsMonthly2020)
{
plan.LegacyYear = null;
}
else if (plansUpgradeIsEnabled && plan.Type is <= PlanType.EnterpriseAnnually2020 and >= PlanType.TeamsMonthly2020)
{
plan.LegacyYear = 2023;
}
return new PlanResponseModel(plan);
});
var responses = StaticStore.Plans.Select(plan => new PlanResponseModel(plan));
return new ListResponseModel<PlanResponseModel>(responses);
}