Commit 660b968a authored by James Lopez's avatar James Lopez

Merge branch 'fix-any-namespace-with-trial' into 'master'

Fix EE::User#any_namespace_{with,without}_trial? methods to use correct table

See merge request gitlab-org/gitlab!29908
parents 42ceab4f f064a327
......@@ -53,8 +53,8 @@ module EE
return unless show_gold_trial?(user, GOLD_TRIAL) &&
user_default_dashboard?(user) &&
::Feature.enabled?(:render_dashboard_gold_trial, default_enabled: true) &&
has_no_trial_or_paid_plan?(user) &&
has_some_namespaces_with_no_trials?(user)
!user.owns_paid_namespace? &&
user.any_namespace_without_trial?
render 'shared/gold_trial_callout_content'
end
......@@ -119,15 +119,5 @@ module EE
def show_gold_trial_suitable_env?
::Gitlab.com? && !::Gitlab::Database.read_only?
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
......@@ -227,20 +227,18 @@ module EE
super || DEFAULT_GROUP_VIEW
end
def any_namespace_with_trial?
::Namespace
.from("(#{namespace_union_for_owned(:trial_ends_on)}) #{::Namespace.table_name}")
.where('trial_ends_on > ?', Time.now.utc)
.any?
end
# Returns true if the user is a Reporter or higher on any namespace
# that has never had a trial (now or in the past)
def any_namespace_without_trial?
::Namespace
.from("(#{namespace_union_for_owned(:trial_ends_on)}) #{::Namespace.table_name}")
.where(trial_ends_on: nil)
.from("(#{namespace_union_for_reporter_developer_maintainer_owned}) #{::Namespace.table_name}")
.include_gitlab_subscription
.where(gitlab_subscriptions: { trial_ends_on: nil })
.any?
end
# Returns true if the user is a Reporter or higher on any namespace
# currently on a paid plan
def has_paid_namespace?
::Namespace
.from("(#{namespace_union_for_reporter_developer_maintainer_owned}) #{::Namespace.table_name}")
......@@ -249,6 +247,8 @@ module EE
.any?
end
# Returns true if the user is an Owner on any namespace currently on
# a paid plan
def owns_paid_namespace?
::Namespace
.from("(#{namespace_union_for_owned}) #{::Namespace.table_name}")
......
......@@ -177,7 +177,7 @@ describe EE::UserCalloutsHelper do
let_it_be(:gold_plan) { create(:gold_plan) }
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 | false | false
true | true | false | true | false
......@@ -200,7 +200,7 @@ describe EE::UserCalloutsHelper 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? }
allow(user).to receive(:any_namespace_without_trial?) { any_namespace_without_trial? }
unless has_no_trial_or_paid_plan?
create(:gitlab_subscription, hosted_plan: gold_plan, namespace: namespace)
......
......@@ -39,7 +39,9 @@ RSpec.shared_examples 'dashboard gold trial callout' do
end
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)
visit page_path
......@@ -47,7 +49,9 @@ RSpec.shared_examples 'dashboard gold trial callout' do
expect(page).not_to have_selector '.promotion-callout'
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.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