Commit 8e6c5621 authored by Alper Akgun's avatar Alper Akgun

Remove ultimate trial banner for non-group owning users

parent 526b222a
...@@ -48,7 +48,7 @@ module EE ...@@ -48,7 +48,7 @@ module EE
return unless show_ultimate_trial?(user, ULTIMATE_TRIAL) && return unless show_ultimate_trial?(user, ULTIMATE_TRIAL) &&
user_default_dashboard?(user) && user_default_dashboard?(user) &&
!user.owns_paid_namespace? && !user.owns_paid_namespace? &&
user.any_namespace_without_trial? user.owns_group_without_trial?
render 'shared/ultimate_trial_callout_content' render 'shared/ultimate_trial_callout_content'
end end
......
...@@ -36,7 +36,7 @@ module EE ...@@ -36,7 +36,7 @@ module EE
return unless ::Gitlab.com? return unless ::Gitlab.com?
Rails.cache.fetch(['users', user.id, 'trials_allowed?'], expires_in: 10.minutes) do Rails.cache.fetch(['users', user.id, 'trials_allowed?'], expires_in: 10.minutes) do
!user.has_paid_namespace? && user.any_namespace_without_trial? !user.has_paid_namespace? && user.owns_group_without_trial?
end end
end end
end end
......
...@@ -229,12 +229,12 @@ module EE ...@@ -229,12 +229,12 @@ module EE
super || DEFAULT_GROUP_VIEW super || DEFAULT_GROUP_VIEW
end end
# Returns true if the user is a Reporter or higher on any namespace # Returns true if the user owns a group
# that has never had a trial (now or in the past) # that has never had a trial (now or in the past)
def any_namespace_without_trial? def owns_group_without_trial?
::Namespace owned_groups
.from("(#{namespace_union_for_reporter_developer_maintainer_owned}) #{::Namespace.table_name}")
.include_gitlab_subscription .include_gitlab_subscription
.where(parent_id: nil)
.where(gitlab_subscriptions: { trial_ends_on: nil }) .where(gitlab_subscriptions: { trial_ends_on: nil })
.any? .any?
end end
......
---
title: Remove ultimate trial banner for users that are not already a group admin
merge_request: 59611
author:
type: changed
...@@ -138,7 +138,7 @@ RSpec.describe EE::UserCalloutsHelper do ...@@ -138,7 +138,7 @@ RSpec.describe EE::UserCalloutsHelper do
let(:user) { namespace.owner } let(:user) { namespace.owner }
where(:any_namespace_without_trial?, :show_ultimate_trial?, :user_default_dashboard?, :has_no_trial_or_paid_plan?, :should_render?) do where(:owns_group_without_trial?, :show_ultimate_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
...@@ -161,7 +161,7 @@ RSpec.describe EE::UserCalloutsHelper do ...@@ -161,7 +161,7 @@ RSpec.describe EE::UserCalloutsHelper do
before do before do
allow(helper).to receive(:show_ultimate_trial?) { show_ultimate_trial? } allow(helper).to receive(:show_ultimate_trial?) { show_ultimate_trial? }
allow(helper).to receive(:user_default_dashboard?) { user_default_dashboard? } allow(helper).to receive(:user_default_dashboard?) { user_default_dashboard? }
allow(user).to receive(:any_namespace_without_trial?) { any_namespace_without_trial? } allow(user).to receive(:owns_group_without_trial?) { owns_group_without_trial? }
unless has_no_trial_or_paid_plan? unless has_no_trial_or_paid_plan?
create(:gitlab_subscription, hosted_plan: ultimate_plan, namespace: namespace) create(:gitlab_subscription, hosted_plan: ultimate_plan, namespace: namespace)
......
...@@ -21,7 +21,7 @@ RSpec.describe UsersHelper do ...@@ -21,7 +21,7 @@ RSpec.describe UsersHelper do
allow(helper).to receive(:can?).and_return(false) allow(helper).to receive(:can?).and_return(false)
allow(::Gitlab).to receive(:com?) { gitlab_com? } allow(::Gitlab).to receive(:com?) { gitlab_com? }
allow(user).to receive(:any_namespace_without_trial?) { user_eligible? } allow(user).to receive(:owns_group_without_trial?) { user_eligible? }
allow(user).to receive(:has_paid_namespace?) { has_paid_namespace? } allow(user).to receive(:has_paid_namespace?) { has_paid_namespace? }
end end
......
...@@ -1711,4 +1711,34 @@ RSpec.describe User do ...@@ -1711,4 +1711,34 @@ RSpec.describe User do
it { is_expected.to eq(result) } it { is_expected.to eq(result) }
end end
end end
describe "#owns_group_without_trial" do
let_it_be(:user) { create(:user) }
let_it_be(:group) { create(:group) }
subject { user.owns_group_without_trial? }
it 'returns true if owns a group' do
group.add_owner(user)
is_expected.to be(true)
end
it 'returns false if is a member group' do
group.add_maintainer(user)
is_expected.to be(false)
end
it 'returns false if is not a member of any group' do
is_expected.to be(false)
end
it 'returns false if owns a group with a plan on a trial with an end date' do
group_with_plan = create(:group_with_plan, name: 'trial group', plan: :premium_plan, trial_ends_on: 1.year.from_now)
group_with_plan.add_owner(user)
is_expected.to be(false)
end
end
end end
...@@ -18,7 +18,10 @@ RSpec.shared_examples 'dashboard ultimate trial callout' do ...@@ -18,7 +18,10 @@ RSpec.shared_examples 'dashboard ultimate trial callout' do
allow(Gitlab).to receive(:com?).and_return(true) allow(Gitlab).to receive(:com?).and_return(true)
end end
it 'shows dismissable promotion callout if default dashboard', :js do it 'shows dismissable promotion callout if default dashboard for an owner', :js do
group = create(:group)
group.add_owner(user)
allow_any_instance_of(EE::DashboardHelper).to receive(:user_default_dashboard?).and_return(true) allow_any_instance_of(EE::DashboardHelper).to receive(:user_default_dashboard?).and_return(true)
visit page_path visit page_path
...@@ -30,6 +33,14 @@ RSpec.shared_examples 'dashboard ultimate trial callout' do ...@@ -30,6 +33,14 @@ RSpec.shared_examples 'dashboard ultimate trial callout' do
expect(page).not_to have_selector '.promotion-callout' expect(page).not_to have_selector '.promotion-callout'
end end
it 'hides dismissable promotion callout if default dashboard for a non group owner' do
allow_any_instance_of(EE::DashboardHelper).to receive(:user_default_dashboard?).and_return(true)
visit page_path
expect(page).not_to have_selector '.promotion-callout'
end
it 'hides dismissable promotion callout if not default dashboard', :js do it 'hides dismissable promotion callout if not default dashboard', :js do
allow_any_instance_of(EE::DashboardHelper).to receive(:user_default_dashboard?).and_return(false) allow_any_instance_of(EE::DashboardHelper).to receive(:user_default_dashboard?).and_return(false)
......
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