Commit c0bdcbf6 authored by Robert Speicher's avatar Robert Speicher

Merge branch '122398-allow-namespaces-in-a-trial-to-upgrade-to-any-plan' into 'master'

Allow namespaces in a trial to upgrade to any plan

See merge request gitlab-org/gitlab!22273
parents f4e559f3 97a5e112
...@@ -8,7 +8,7 @@ class Groups::BillingsController < Groups::ApplicationController ...@@ -8,7 +8,7 @@ class Groups::BillingsController < Groups::ApplicationController
def index def index
@top_most_group = @group.root_ancestor if @group.has_parent? @top_most_group = @group.root_ancestor if @group.has_parent?
current_plan = (@top_most_group || @group).actual_plan_name current_plan = (@top_most_group || @group).plan_name_for_upgrading
@plans_data = FetchSubscriptionPlansService.new(plan: current_plan).execute @plans_data = FetchSubscriptionPlansService.new(plan: current_plan).execute
end end
end end
...@@ -5,7 +5,7 @@ class Profiles::BillingsController < Profiles::ApplicationController ...@@ -5,7 +5,7 @@ class Profiles::BillingsController < Profiles::ApplicationController
def index def index
@plans_data = FetchSubscriptionPlansService @plans_data = FetchSubscriptionPlansService
.new(plan: current_user.namespace.actual_plan_name) .new(plan: current_user.namespace.plan_name_for_upgrading)
.execute .execute
end end
end end
...@@ -60,6 +60,10 @@ module BillingPlansHelper ...@@ -60,6 +60,10 @@ module BillingPlansHelper
end end
end end
def show_plans?(namespace)
namespace.trial_active? || !namespace.gold_plan?
end
def show_trial_banner?(namespace) def show_trial_banner?(namespace)
return false unless params[:trial] return false unless params[:trial]
......
...@@ -170,6 +170,12 @@ module EE ...@@ -170,6 +170,12 @@ module EE
actual_plan&.name || Plan::FREE actual_plan&.name || Plan::FREE
end end
def plan_name_for_upgrading
return Plan::FREE if trial_active?
actual_plan_name
end
def actual_size_limit def actual_size_limit
::Gitlab::CurrentSettings.repository_size_limit ::Gitlab::CurrentSettings.repository_size_limit
end end
......
- purchase_link = plan.purchase_link - purchase_link = plan.purchase_link
- is_current_plan = purchase_link.action == 'current_plan' - is_current_plan = plan.code == namespace.actual_plan_name
.col-md-6.col-lg-3 .col-md-6.col-lg-3
.card.mb-5{ class: ("card-active" if is_current_plan) } .card.mb-5{ class: ("card-active" if is_current_plan) }
...@@ -34,5 +34,5 @@ ...@@ -34,5 +34,5 @@
- if purchase_link - if purchase_link
.card-footer.p-3 .card-footer.p-3
.pull-right{ class: ("invisible" unless purchase_link.action == 'upgrade' || is_current_plan) } .pull-right{ class: ("invisible" unless purchase_link.action == 'upgrade' || is_current_plan) }
- upgrade_button_class = "disabled" if is_current_plan - upgrade_button_class = "disabled" if is_current_plan && !namespace.trial_active?
= link_to s_('BillingPlan|Upgrade'), plan_purchase_or_upgrade_url(namespace, plan, current_plan), class: "btn btn-success #{upgrade_button_class}" = link_to s_('BillingPlan|Upgrade'), plan_purchase_or_upgrade_url(namespace, plan, current_plan), class: "btn btn-success #{upgrade_button_class}"
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
- if current_plan - if current_plan
= render 'shared/billings/billing_plan_header', namespace: namespace, plan: current_plan = render 'shared/billings/billing_plan_header', namespace: namespace, plan: current_plan
- unless namespace.gold_plan? - if show_plans?(namespace)
.billing-plans.mt-5.row .billing-plans.mt-5.row
- plans_data.each do |plan| - plans_data.each do |plan|
= render 'shared/billings/billing_plan', namespace: namespace, plan: plan, current_plan: current_plan = render 'shared/billings/billing_plan', namespace: namespace, plan: plan, current_plan: current_plan
......
---
title: Allow namespaces in a trial to upgrade to any plan
merge_request: 22273
author:
type: changed
...@@ -183,6 +183,81 @@ describe 'Billing plan pages', :feature do ...@@ -183,6 +183,81 @@ describe 'Billing plan pages', :feature do
end end
end end
context 'users profile billing page with a trial' do
let(:page_path) { profile_billings_path }
context 'on free' do
let(:plan) { free_plan }
let!(:subscription) do
create(:gitlab_subscription, namespace: namespace, hosted_plan: plan,
trial: true, trial_ends_on: Date.current.tomorrow, seats: 15)
end
before do
visit page_path
end
it 'displays all plans' do
page.within('.billing-plans') do
panels = page.all('.card')
expect(panels.length).to eq(plans_data.length)
plans_data.each.with_index do |data, index|
expect(panels[index].find('.card-header')).to have_content(data[:name])
end
end
end
it 'displays correct plan actions' do
expected_actions = plans_data.map { |data| data.fetch(:purchase_link).fetch(:action) }
plan_actions = page.all('.billing-plans .card .card-footer')
expect(plan_actions.length).to eq(expected_actions.length)
expected_actions.each_with_index do |expected_action, index|
action = plan_actions[index]
case expected_action
when 'downgrade'
expect(action).not_to have_link('Upgrade')
expect(action).not_to have_css('.disabled')
when 'current_plan'
expect(action).to have_link('Upgrade')
expect(action).not_to have_css('.disabled')
when 'upgrade'
expect(action).to have_link('Upgrade')
expect(action).not_to have_css('.disabled')
end
end
end
end
context 'on bronze plan' do
let(:plan) { bronze_plan }
let!(:subscription) do
create(:gitlab_subscription, namespace: namespace, hosted_plan: plan, seats: 15)
end
it_behaves_like 'plan with header'
it_behaves_like 'downgradable plan'
it_behaves_like 'upgradable plan'
end
context 'on gold plan' do
let(:plan) { gold_plan }
let!(:subscription) do
create(:gitlab_subscription, namespace: namespace, hosted_plan: plan, seats: 15)
end
it_behaves_like 'plan with header'
it_behaves_like 'downgradable plan'
it_behaves_like 'non-upgradable plan'
end
end
context 'group billing page' do context 'group billing page' do
let(:namespace) { create(:group) } let(:namespace) { create(:group) }
let!(:group_member) { create(:group_member, :owner, group: namespace, user: user) } let!(:group_member) { create(:group_member, :owner, group: namespace, user: user) }
...@@ -190,6 +265,34 @@ describe 'Billing plan pages', :feature do ...@@ -190,6 +265,34 @@ describe 'Billing plan pages', :feature do
context 'top-most group' do context 'top-most group' do
let(:page_path) { group_billings_path(namespace) } let(:page_path) { group_billings_path(namespace) }
context 'on gold' do
let(:plan) { gold_plan }
let!(:subscription) do
create(:gitlab_subscription, namespace: namespace, hosted_plan: plan, seats: 15)
end
before do
visit page_path
end
it 'displays plan header' do
page.within('.billing-plan-header') do
expect(page).to have_content("#{namespace.name} is currently using the Gold plan")
expect(page).to have_css('.billing-plan-logo .identicon')
end
end
it 'does not display the billing plans table' do
expect(page).not_to have_css('.billing-plans')
end
it 'displays subscription table', :js do
expect(page).to have_selector('.js-subscription-table')
end
end
context 'on bronze' do context 'on bronze' do
let(:plan) { bronze_plan } let(:plan) { bronze_plan }
...@@ -220,6 +323,52 @@ describe 'Billing plan pages', :feature do ...@@ -220,6 +323,52 @@ describe 'Billing plan pages', :feature do
end end
end end
context 'group billing page with a trial' do
let(:namespace) { create(:group) }
let!(:group_member) { create(:group_member, :owner, group: namespace, user: user) }
before do
stub_full_request("#{EE::SUBSCRIPTIONS_URL}/gitlab_plans?plan=free")
.to_return(status: 200, body: plans_data.to_json)
end
context 'top-most group' do
let(:page_path) { group_billings_path(namespace) }
context 'on gold' do
let(:plan) { gold_plan }
let!(:subscription) do
create(:gitlab_subscription, namespace: namespace, hosted_plan: plan,
trial: true, trial_ends_on: Date.current.tomorrow, seats: 15)
end
before do
visit page_path
end
it 'displays plan header' do
page.within('.billing-plan-header') do
expect(page).to have_content("#{namespace.name} is currently using the Gold plan")
expect(page).to have_css('.billing-plan-logo .identicon')
end
end
it 'does display the billing plans table' do
expect(page).to have_css('.billing-plans')
end
it 'displays subscription table', :js do
expect(page).to have_selector('.js-subscription-table')
end
it_behaves_like 'downgradable plan'
it_behaves_like 'non-upgradable plan'
end
end
end
context 'on sub-group' do context 'on sub-group' do
let(:user2) { create(:user) } let(:user2) { create(:user) }
let(:user3) { create(:user) } let(:user3) { create(:user) }
......
...@@ -7,7 +7,7 @@ describe 'Show trial banner', :js do ...@@ -7,7 +7,7 @@ describe 'Show trial banner', :js do
let!(:user) { create(:user) } let!(:user) { create(:user) }
let!(:group) { create(:group) } let!(:group) { create(:group) }
let!(:bronze_plan) { create(:bronze_plan) } let!(:gold_plan) { create(:gold_plan) }
let(:plans_data) do let(:plans_data) do
JSON.parse(File.read(Rails.root.join('ee/spec/fixtures/gitlab_com_plans.json'))).map do |data| JSON.parse(File.read(Rails.root.join('ee/spec/fixtures/gitlab_com_plans.json'))).map do |data|
data.deep_symbolize_keys data.deep_symbolize_keys
...@@ -17,12 +17,12 @@ describe 'Show trial banner', :js do ...@@ -17,12 +17,12 @@ describe 'Show trial banner', :js do
before do before do
stub_application_setting(check_namespace_plan: true) stub_application_setting(check_namespace_plan: true)
allow(Gitlab).to receive(:com?).and_return(true).at_least(:once) allow(Gitlab).to receive(:com?).and_return(true).at_least(:once)
stub_full_request("#{EE::SUBSCRIPTIONS_URL}/gitlab_plans?plan=bronze") stub_full_request("#{EE::SUBSCRIPTIONS_URL}/gitlab_plans?plan=free")
.to_return(status: 200, body: plans_data.to_json) .to_return(status: 200, body: plans_data.to_json)
group.add_owner(user) group.add_owner(user)
create(:gitlab_subscription, namespace: user.namespace, hosted_plan: bronze_plan, trial: true, trial_ends_on: Date.current + 1.month) create(:gitlab_subscription, namespace: user.namespace, hosted_plan: gold_plan, trial: true, trial_ends_on: Date.current + 1.month)
create(:gitlab_subscription, namespace: group, hosted_plan: bronze_plan, trial: true, trial_ends_on: Date.current + 1.month) create(:gitlab_subscription, namespace: group, hosted_plan: gold_plan, trial: true, trial_ends_on: Date.current + 1.month)
gitlab_sign_in(user) gitlab_sign_in(user)
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