Commit 82a9eccf authored by Markus Koller's avatar Markus Koller

Merge branch '300546-dynamic-plan-renaming' into 'master'

Dynamically rename plan title after EoA rollout date

See merge request gitlab-org/gitlab!53473
parents 4c0def7c b9332772
...@@ -173,7 +173,7 @@ module EE ...@@ -173,7 +173,7 @@ module EE
root_ancestor.actual_plan root_ancestor.actual_plan
else else
subscription = find_or_create_subscription subscription = find_or_create_subscription
subscription&.hosted_plan hosted_plan_for(subscription)
end end
end || fallback_plan end || fallback_plan
end end
...@@ -442,5 +442,16 @@ module EE ...@@ -442,5 +442,16 @@ module EE
.without_unlimited_repository_size_limit .without_unlimited_repository_size_limit
end end
end end
def hosted_plan_for(subscription)
return unless subscription
plan = subscription.hosted_plan
if plan && !subscription.legacy?
::Subscriptions::NewPlanPresenter.new(plan)
else
plan
end
end
end end
end end
...@@ -4,6 +4,8 @@ class GitlabSubscription < ApplicationRecord ...@@ -4,6 +4,8 @@ class GitlabSubscription < ApplicationRecord
include EachBatch include EachBatch
include Gitlab::Utils::StrongMemoize include Gitlab::Utils::StrongMemoize
EOA_ROLLOUT_DATE = '2021-01-26'
default_value_for(:start_date) { Date.today } default_value_for(:start_date) { Date.today }
before_update :log_previous_state_for_update before_update :log_previous_state_for_update
after_commit :index_namespace, on: [:create, :update] after_commit :index_namespace, on: [:create, :update]
...@@ -45,6 +47,10 @@ class GitlabSubscription < ApplicationRecord ...@@ -45,6 +47,10 @@ class GitlabSubscription < ApplicationRecord
end end
end end
def legacy?
start_date < EOA_ROLLOUT_DATE.to_date
end
def calculate_seats_in_use def calculate_seats_in_use
namespace.billable_members_count namespace.billable_members_count
end end
......
# frozen_string_literal: true
module Subscriptions
class NewPlanPresenter < Gitlab::View::Presenter::Delegated
NEW_PLAN_TITLES = {
silver: 'Premium (Formerly Silver)',
gold: 'Ultimate (Formerly Gold)'
}.freeze
def title
NEW_PLAN_TITLES.fetch(plan_key, super)
end
private
def plan_key
name&.to_sym
end
end
end
---
title: Dynamically rename plan title after EoA rollout date
merge_request: 53473
author:
type: added
...@@ -28,7 +28,7 @@ RSpec.describe 'Changes GL.com plan for group' do ...@@ -28,7 +28,7 @@ RSpec.describe 'Changes GL.com plan for group' do
click_button('Save changes') click_button('Save changes')
expect(page).to have_content('Plan: Silver') expect(page).to have_content('Plan: Premium (Formerly Silver)')
end end
end end
...@@ -45,7 +45,7 @@ RSpec.describe 'Changes GL.com plan for group' do ...@@ -45,7 +45,7 @@ RSpec.describe 'Changes GL.com plan for group' do
click_button('Save changes') click_button('Save changes')
expect(page).to have_content('Plan: Silver') expect(page).to have_content('Plan: Premium (Formerly Silver)')
end end
end end
end end
...@@ -702,12 +702,25 @@ RSpec.describe Namespace do ...@@ -702,12 +702,25 @@ RSpec.describe Namespace do
context 'when namespace has a subscription associated' do context 'when namespace has a subscription associated' do
before do before do
create(:gitlab_subscription, namespace: namespace, hosted_plan: gold_plan) create(:gitlab_subscription, namespace: namespace, hosted_plan: gold_plan, start_date: start_date)
end end
it 'returns the plan from the subscription' do context 'when this subscription was purchased before EoA rollout (legacy)' do
expect(namespace.actual_plan).to eq(gold_plan) let(:start_date) { GitlabSubscription::EOA_ROLLOUT_DATE.to_date - 3.days }
expect(namespace.gitlab_subscription).to be_present
it 'returns the legacy plan from the subscription' do
expect(namespace.actual_plan).to eq(gold_plan)
expect(namespace.gitlab_subscription).to be_present
end
end
context 'when this subscription was purchase after EoA rollout (new plan)' do
let(:start_date) { GitlabSubscription::EOA_ROLLOUT_DATE.to_date + 3.days }
it 'returns the new plan from the subscription' do
expect(namespace.actual_plan).to be_an_instance_of(Subscriptions::NewPlanPresenter)
expect(namespace.gitlab_subscription).to be_present
end
end end
end end
......
...@@ -605,4 +605,29 @@ RSpec.describe GitlabSubscription do ...@@ -605,4 +605,29 @@ RSpec.describe GitlabSubscription do
end end
end end
end end
describe '#legacy?' do
let_it_be(:eoa_rollout_date) { GitlabSubscription::EOA_ROLLOUT_DATE.to_date }
let!(:gitlab_subscription) { create(:gitlab_subscription, start_date: start_date) }
subject { gitlab_subscription.legacy? }
context 'when a subscription was purchased before the EoA rollout date' do
let(:start_date) { eoa_rollout_date - 1.day }
it { is_expected.to be_truthy }
end
context 'when a subscription was purchased on the EoA rollout date' do
let(:start_date) { eoa_rollout_date }
it { is_expected.to be_falsey }
end
context 'when a subscription was purchased after the EoA rollout date' do
let(:start_date) { eoa_rollout_date + 1.day}
it { is_expected.to be_falsey }
end
end
end end
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Subscriptions::NewPlanPresenter do
describe '#title' do
using RSpec::Parameterized::TableSyntax
where(:legacy_name, :new_title) do
'bronze' | 'Bronze'
'silver' | 'Premium (Formerly Silver)'
'gold' | 'Ultimate (Formerly Gold)'
end
with_them do
it 'returns the correct title for new plans' do
legacy_plan = build("#{legacy_name}_plan".to_sym)
expect(described_class.new(legacy_plan).title).to eq(new_title)
end
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment