Commit f064a327 authored by Sean McGivern's avatar Sean McGivern

Fix EE::User#any_namespace_{with,without}_trial? methods

`namespaces.trial_ends_on` is being removed, so
`any_namespace_without_trial?` should use
`gitlab_subscriptions.trial_ends_on` instead.

`any_namespace_with_trial?` wasn't actually needed, as it was used when
checking if a user owned either:

1. A namespace on a paid plan.
2. A namespace on an active trial.

But all active trials are on paid plans (a trial on the free plan
doesn't make sense), so we only need the first check there.
parent 5c3ddecc
...@@ -53,8 +53,8 @@ module EE ...@@ -53,8 +53,8 @@ module EE
return unless show_gold_trial?(user, GOLD_TRIAL) && return unless show_gold_trial?(user, GOLD_TRIAL) &&
user_default_dashboard?(user) && user_default_dashboard?(user) &&
::Feature.enabled?(:render_dashboard_gold_trial, default_enabled: true) && ::Feature.enabled?(:render_dashboard_gold_trial, default_enabled: true) &&
has_no_trial_or_paid_plan?(user) && !user.owns_paid_namespace? &&
has_some_namespaces_with_no_trials?(user) user.any_namespace_without_trial?
render 'shared/gold_trial_callout_content' render 'shared/gold_trial_callout_content'
end end
...@@ -119,15 +119,5 @@ module EE ...@@ -119,15 +119,5 @@ module EE
def show_gold_trial_suitable_env? def show_gold_trial_suitable_env?
::Gitlab.com? && !::Gitlab::Database.read_only? ::Gitlab.com? && !::Gitlab::Database.read_only?
end end
def has_no_trial_or_paid_plan?(user)
return false if user.owns_paid_namespace?
!user.any_namespace_with_trial?
end
def has_some_namespaces_with_no_trials?(user)
user&.any_namespace_without_trial?
end
end end
end end
...@@ -227,20 +227,18 @@ module EE ...@@ -227,20 +227,18 @@ module EE
super || DEFAULT_GROUP_VIEW super || DEFAULT_GROUP_VIEW
end end
def any_namespace_with_trial? # Returns true if the user is a Reporter or higher on any namespace
::Namespace # that has never had a trial (now or in the past)
.from("(#{namespace_union_for_owned(:trial_ends_on)}) #{::Namespace.table_name}")
.where('trial_ends_on > ?', Time.now.utc)
.any?
end
def any_namespace_without_trial? def any_namespace_without_trial?
::Namespace ::Namespace
.from("(#{namespace_union_for_owned(:trial_ends_on)}) #{::Namespace.table_name}") .from("(#{namespace_union_for_reporter_developer_maintainer_owned}) #{::Namespace.table_name}")
.where(trial_ends_on: nil) .include_gitlab_subscription
.where(gitlab_subscriptions: { trial_ends_on: nil })
.any? .any?
end end
# Returns true if the user is a Reporter or higher on any namespace
# currently on a paid plan
def has_paid_namespace? def has_paid_namespace?
::Namespace ::Namespace
.from("(#{namespace_union_for_reporter_developer_maintainer_owned}) #{::Namespace.table_name}") .from("(#{namespace_union_for_reporter_developer_maintainer_owned}) #{::Namespace.table_name}")
...@@ -249,6 +247,8 @@ module EE ...@@ -249,6 +247,8 @@ module EE
.any? .any?
end end
# Returns true if the user is an Owner on any namespace currently on
# a paid plan
def owns_paid_namespace? def owns_paid_namespace?
::Namespace ::Namespace
.from("(#{namespace_union_for_owned}) #{::Namespace.table_name}") .from("(#{namespace_union_for_owned}) #{::Namespace.table_name}")
......
...@@ -177,7 +177,7 @@ describe EE::UserCalloutsHelper do ...@@ -177,7 +177,7 @@ describe EE::UserCalloutsHelper do
let_it_be(:gold_plan) { create(:gold_plan) } let_it_be(:gold_plan) { create(:gold_plan) }
let(:user) { namespace.owner } let(:user) { namespace.owner }
where(:has_some_namespaces_with_no_trials?, :show_gold_trial?, :user_default_dashboard?, :has_no_trial_or_paid_plan?, :should_render?) do where(:any_namespace_without_trial?, :show_gold_trial?, :user_default_dashboard?, :has_no_trial_or_paid_plan?, :should_render?) do
true | true | true | true | true true | true | true | true | true
true | true | true | false | false true | true | true | false | false
true | true | false | true | false true | true | false | true | false
...@@ -200,7 +200,7 @@ describe EE::UserCalloutsHelper do ...@@ -200,7 +200,7 @@ describe EE::UserCalloutsHelper do
before do before do
allow(helper).to receive(:show_gold_trial?) { show_gold_trial? } allow(helper).to receive(:show_gold_trial?) { show_gold_trial? }
allow(helper).to receive(:user_default_dashboard?) { user_default_dashboard? } 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? } allow(user).to receive(:any_namespace_without_trial?) { any_namespace_without_trial? }
unless has_no_trial_or_paid_plan? unless has_no_trial_or_paid_plan?
create(:gitlab_subscription, hosted_plan: gold_plan, namespace: namespace) create(:gitlab_subscription, hosted_plan: gold_plan, namespace: namespace)
......
...@@ -39,7 +39,9 @@ RSpec.shared_examples 'dashboard gold trial callout' do ...@@ -39,7 +39,9 @@ RSpec.shared_examples 'dashboard gold trial callout' do
end end
it 'hides promotion callout if a trial is active' do it 'hides promotion callout if a trial is active' do
group = create(:group, name: 'trial group', trial_ends_on: 1.year.from_now) allow_any_instance_of(EE::DashboardHelper).to receive(:user_default_dashboard?).and_return(true)
group = create(:group_with_plan, name: 'trial group', plan: :silver_plan, trial_ends_on: 1.year.from_now)
group.add_owner(user) group.add_owner(user)
visit page_path visit page_path
...@@ -47,7 +49,9 @@ RSpec.shared_examples 'dashboard gold trial callout' do ...@@ -47,7 +49,9 @@ RSpec.shared_examples 'dashboard gold trial callout' do
expect(page).not_to have_selector '.promotion-callout' expect(page).not_to have_selector '.promotion-callout'
end end
it 'hides promotion callout if a gold plan is active', :js do it 'hides promotion callout if user owns a paid namespace', :js do
allow_any_instance_of(EE::DashboardHelper).to receive(:user_default_dashboard?).and_return(true)
group = create(:group_with_plan, name: 'gold group', plan: :gold_plan) group = create(:group_with_plan, name: 'gold group', plan: :gold_plan)
group.add_owner(user) group.add_owner(user)
......
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