Commit 6ffb2a16 authored by Sean McGivern's avatar Sean McGivern

Merge branch 'billings-gold-trial-callout' into 'master'

BE Add Gitlab.com gold trial callout to /billings

See merge request gitlab-org/gitlab-ee!9610
parents fa045e87 9974a091
...@@ -17,6 +17,9 @@ module UserCalloutsHelper ...@@ -17,6 +17,9 @@ module UserCalloutsHelper
render 'shared/flash_user_callout', flash_type: flash_type, message: message, feature_name: feature_name render 'shared/flash_user_callout', flash_type: flash_type, message: message, feature_name: feature_name
end end
def render_dashboard_gold_trial(user)
end
private private
def user_dismissed?(feature_name) def user_dismissed?(feature_name)
......
...@@ -2,18 +2,13 @@ ...@@ -2,18 +2,13 @@
module EE module EE
module UserCalloutsHelper module UserCalloutsHelper
GOLD_TRIAL = 'gold_trial' extend ::Gitlab::Utils::Override
GEO_ENABLE_HASHED_STORAGE = 'geo_enable_hashed_storage' GEO_ENABLE_HASHED_STORAGE = 'geo_enable_hashed_storage'
GEO_MIGRATE_HASHED_STORAGE = 'geo_migrate_hashed_storage' GEO_MIGRATE_HASHED_STORAGE = 'geo_migrate_hashed_storage'
CANARY_DEPLOYMENT = 'canary_deployment' CANARY_DEPLOYMENT = 'canary_deployment'
GOLD_TRIAL = 'gold_trial'
def show_gold_trial?(user = current_user) GOLD_TRIAL_BILLINGS = 'gold_trial_billings'
return false unless user
return false if user_dismissed?(GOLD_TRIAL)
return false unless show_gold_trial_suitable_env?
users_namespaces_clean?(user)
end
def show_canary_deployment_callout?(project) def show_canary_deployment_callout?(project)
!user_dismissed?(CANARY_DEPLOYMENT) && !user_dismissed?(CANARY_DEPLOYMENT) &&
...@@ -22,17 +17,6 @@ module EE ...@@ -22,17 +17,6 @@ module EE
!project.feature_available?(:deploy_board) !project.feature_available?(:deploy_board)
end end
def show_gold_trial_suitable_env?
(::Gitlab.com? || Rails.env.development?) &&
!::Gitlab::Database.read_only?
end
def users_namespaces_clean?(user)
return false if user.any_namespace_with_gold?
!user.any_namespace_with_trial?
end
def render_enable_hashed_storage_warning def render_enable_hashed_storage_warning
return unless show_enable_hashed_storage_warning? return unless show_enable_hashed_storage_warning?
...@@ -62,6 +46,22 @@ module EE ...@@ -62,6 +46,22 @@ module EE
any_project_not_in_hashed_storage? any_project_not_in_hashed_storage?
end end
override :render_dashboard_gold_trial
def render_dashboard_gold_trial(user)
return unless user_default_dashboard?(user) &&
show_gold_trial?(user, GOLD_TRIAL) &&
has_no_trial_or_gold_plan?(user)
render 'shared/gold_trial_callout'
end
def render_billings_gold_trial(user, namespace)
return if namespace.gold_plan?
return unless show_gold_trial?(user, GOLD_TRIAL_BILLINGS)
render 'shared/gold_trial_callout', is_dismissable: !namespace.free_plan?
end
private private
def hashed_storage_enabled? def hashed_storage_enabled?
...@@ -89,5 +89,24 @@ module EE ...@@ -89,5 +89,24 @@ module EE
linked_message = message % { migrate_link: migrate_link } linked_message = message % { migrate_link: migrate_link }
linked_message.html_safe linked_message.html_safe
end end
def show_gold_trial?(user, callout = GOLD_TRIAL)
return false unless user
return false unless show_gold_trial_suitable_env?
return false if user_dismissed?(callout)
true
end
def show_gold_trial_suitable_env?
(::Gitlab.com? || Rails.env.development?) &&
!::Gitlab::Database.read_only?
end
def has_no_trial_or_gold_plan?(user)
return false if user.any_namespace_with_gold?
!user.any_namespace_with_trial?
end
end end
end end
...@@ -237,6 +237,26 @@ module EE ...@@ -237,6 +237,26 @@ module EE
feature_available?(:dast)) feature_available?(:dast))
end end
def free_plan?
actual_plan_name == FREE_PLAN
end
def early_adopter_plan?
actual_plan_name == EARLY_ADOPTER_PLAN
end
def bronze_plan?
actual_plan_name == BRONZE_PLAN
end
def silver_plan?
actual_plan_name == SILVER_PLAN
end
def gold_plan?
actual_plan_name == GOLD_PLAN
end
private private
def validate_plan_name def validate_plan_name
......
...@@ -13,7 +13,8 @@ module EE ...@@ -13,7 +13,8 @@ module EE
gold_trial: 4, gold_trial: 4,
geo_enable_hashed_storage: 5, geo_enable_hashed_storage: 5,
geo_migrate_hashed_storage: 6, geo_migrate_hashed_storage: 6,
canary_deployment: 7) canary_deployment: 7,
gold_trial_billings: 8)
end end
end end
end end
......
- if show_gold_trial? && user_default_dashboard? - if show_gold_trial?(current_user) && user_default_dashboard?(current_user) && has_no_trial_or_gold_plan?(current_user)
.pt-1.d-none.d-md-block{ class: container_class } .pt-1.d-none.d-md-block{ class: container_class }
.user-callout.promotion-callout.thin-callout.js-gold-trial-callout{ data: { uid: 'trial_callout_dismissed', feature_id: UserCalloutsHelper::GOLD_TRIAL, dismiss_endpoint: user_callouts_path } } .user-callout.promotion-callout.thin-callout.js-gold-trial-callout{ data: { uid: 'trial_callout_dismissed', feature_id: UserCalloutsHelper::GOLD_TRIAL, dismiss_endpoint: user_callouts_path } }
.bordered-box.justify-content-left.align-items-center .bordered-box.justify-content-left.align-items-center
......
...@@ -3,28 +3,6 @@ ...@@ -3,28 +3,6 @@
require "spec_helper" require "spec_helper"
describe EE::UserCalloutsHelper do describe EE::UserCalloutsHelper do
describe '.show_gold_trial?' do
let(:user) { create(:user) }
before do
allow(helper).to receive(:user_dismissed?).with(described_class::GOLD_TRIAL).and_return(false)
allow(Gitlab).to receive(:com?).and_return(true)
allow(Gitlab::Database).to receive(:read_only?).and_return(false)
allow(user).to receive(:any_namespace_with_gold?).and_return(false)
allow(user).to receive(:any_namespace_with_trial?).and_return(false)
end
it 'returns true when all conditions are met' do
expect(helper.show_gold_trial?(user)).to be(true)
end
it 'returns false when there is no user record' do
allow(helper).to receive(:current_user).and_return(nil)
expect(helper.show_gold_trial?).to be(false)
end
end
describe '.render_enable_hashed_storage_warning' do describe '.render_enable_hashed_storage_warning' do
context 'when we should show the enable warning' do context 'when we should show the enable warning' do
it 'renders the enable warning' do it 'renders the enable warning' do
...@@ -189,4 +167,79 @@ describe EE::UserCalloutsHelper do ...@@ -189,4 +167,79 @@ describe EE::UserCalloutsHelper do
it { is_expected.to be_falsey } it { is_expected.to be_falsey }
end end
end end
describe '#render_dashboard_gold_trial' do
using RSpec::Parameterized::TableSyntax
set(:namespace) { create(:namespace) }
set(:gold_plan) { create(:gold_plan) }
let(:user) { namespace.owner }
where(:show_gold_trial?, :user_default_dashboard?, :has_no_trial_or_gold_plan?, :should_render?) do
true | true | true | true
true | true | false | false
true | false | true | false
false | true | true | false
true | false | false | false
false | false | true | false
false | true | false | false
false | false | false | false
end
with_them do
before do
allow(helper).to receive(:show_gold_trial?) { show_gold_trial? }
allow(helper).to receive(:user_default_dashboard?) { user_default_dashboard? }
namespace.update(plan: gold_plan) unless has_no_trial_or_gold_plan?
end
it do
if should_render?
expect(helper).to receive(:render).with('shared/gold_trial_callout')
else
expect(helper).not_to receive(:render)
end
helper.render_dashboard_gold_trial(user)
end
end
end
describe '#render_billings_gold_trial' do
using RSpec::Parameterized::TableSyntax
set(:namespace) { create(:namespace) }
set(:silver_plan) { create(:silver_plan) }
set(:gold_plan) { create(:gold_plan) }
let(:user) { namespace.owner }
where(:show_gold_trial?, :gold_plan?, :free_plan?, :should_render?) do
true | false | false | true
true | false | true | true
true | true | true | false
true | true | false | false
false | true | true | false
false | false | true | false
false | true | false | false
false | false | false | false
end
with_them do
before do
allow(helper).to receive(:show_gold_trial?) { show_gold_trial? }
namespace.update(plan: gold_plan) if gold_plan?
namespace.update(plan: silver_plan) if !gold_plan? && !free_plan?
end
it do
if should_render?
expect(helper).to receive(:render).with('shared/gold_trial_callout', is_dismissable: !free_plan?)
else
expect(helper).not_to receive(:render)
end
helper.render_billings_gold_trial(user, namespace)
end
end
end
end end
# frozen_string_literal: true
require 'spec_helper'
describe Namespace do
shared_examples 'plan helper' do |namespace_plan|
let(:namespace) { described_class.new(plan: plan) }
subject { namespace.public_send("#{namespace_plan}_plan?") }
context "for a #{namespace_plan} plan" do
let(:plan) { Plan.create(name: namespace_plan) }
it { is_expected.to eq(true) }
end
context "for a plan that isn't #{namespace_plan}" do
where(plan_name: described_class::PLANS - [namespace_plan])
with_them do
let(:plan) { Plan.create(name: plan_name) }
it { is_expected.to eq(false) }
end
end
end
described_class::PLANS.each do |namespace_plan|
describe "#{namespace_plan}_plan?" do
it_behaves_like 'plan helper', namespace_plan
end
end
end
# frozen_string_literal: true
require 'spec_helper' require 'spec_helper'
describe Plan do describe Plan do
......
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