Commit aa8d833b authored by James Lopez's avatar James Lopez

Merge branch '35440-for-com-namespaces-with-expired-trials-remove-start-trial-ctas' into 'master'

Hide trial banner  for namespaces with expired trials

See merge request gitlab-org/gitlab!19510
parents afa69815 56cad1f7
---
title: Hide trial banner for namespaces with expired trials
merge_request: 19510
author:
type: changed
......@@ -50,13 +50,15 @@ module EE
def render_dashboard_gold_trial(user)
return unless show_gold_trial?(user, GOLD_TRIAL) &&
user_default_dashboard?(user) &&
has_no_trial_or_gold_plan?(user)
has_no_trial_or_gold_plan?(user) &&
has_some_namespaces_with_no_trials?(user)
render 'shared/gold_trial_callout_content'
end
def render_billings_gold_trial(user, namespace)
return if namespace.gold_plan?
return unless namespace.never_had_trial?
return unless show_gold_trial?(user, GOLD_TRIAL_BILLINGS)
render 'shared/gold_trial_callout_content', is_dismissable: !namespace.free_plan?, callout: GOLD_TRIAL_BILLINGS
......@@ -107,5 +109,9 @@ module EE
!user.any_namespace_with_trial?
end
def has_some_namespaces_with_no_trials?(user)
user&.any_namespace_without_trial?
end
end
end
......@@ -259,6 +259,10 @@ module EE
trial? && trial_ends_on.present? && trial_ends_on >= Date.today
end
def never_had_trial?
trial_ends_on.nil?
end
def trial_expired?
trial_ends_on.present? &&
trial_ends_on < Date.today &&
......
......@@ -235,6 +235,13 @@ module EE
.any?
end
def any_namespace_without_trial?
::Namespace
.from("(#{namespace_union(:trial_ends_on)}) #{::Namespace.table_name}")
.where(trial_ends_on: nil)
.any?
end
def any_namespace_with_gold?
::Namespace
.includes(:plan)
......
......@@ -177,21 +177,30 @@ describe EE::UserCalloutsHelper do
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
where(:has_some_namespaces_with_no_trials?, :show_gold_trial?, :user_default_dashboard?, :has_no_trial_or_gold_plan?, :should_render?) do
true | true | true | true | true
true | true | true | false | false
true | true | false | true | false
true | false | true | true | false
true | true | false | false | false
true | false | false | true | false
true | false | true | false | false
true | false | false | false | false
false | true | true | true | false
false | true | true | false | false
false | true | false | true | false
false | false | true | true | false
false | true | false | false | false
false | false | false | true | false
false | false | true | false | 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? }
allow(helper).to receive(:has_some_namespaces_with_no_trials?) { has_some_namespaces_with_no_trials? }
namespace.update(plan: gold_plan) unless has_no_trial_or_gold_plan?
end
......@@ -211,19 +220,29 @@ describe EE::UserCalloutsHelper do
using RSpec::Parameterized::TableSyntax
set(:namespace) { create(:namespace) }
set(:free_plan) { create(:free_plan) }
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
let(:gitlab_subscription) { create(:gitlab_subscription, namespace: namespace) }
where(:never_had_trial?, :show_gold_trial?, :gold_plan?, :free_plan?, :should_render?) do
true | true | false | false | true
true | true | false | true | true
true | true | true | true | false
true | true | true | false | false
true | false | true | true | false
true | false | false | true | false
true | false | true | false | false
true | false | false | false | false
false | true | false | false | false
false | true | false | true | false
false | true | true | true | false
false | true | true | false | false
false | false | true | true | false
false | false | false | true | false
false | false | true | false | false
false | false | false | false | false
end
with_them do
......@@ -231,6 +250,11 @@ describe EE::UserCalloutsHelper 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?
unless never_had_trial?
namespace.update(plan: free_plan)
namespace.create_gitlab_subscription(trial_ends_on: Date.yesterday)
end
end
it 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