Commit f794242b authored by Alper Akgun's avatar Alper Akgun

Merge branch...

Merge branch '327043-remove-ultimate-trial-banner-for-users-that-are-not-already-a-group-admin' into 'master'

Remove ultimate trial banner for non-group owning users

See merge request gitlab-org/gitlab!59611
parents bf81b259 8e6c5621
......@@ -48,7 +48,7 @@ module EE
return unless show_ultimate_trial?(user, ULTIMATE_TRIAL) &&
user_default_dashboard?(user) &&
!user.owns_paid_namespace? &&
user.any_namespace_without_trial?
user.owns_group_without_trial?
render 'shared/ultimate_trial_callout_content'
end
......
......@@ -36,7 +36,7 @@ module EE
return unless ::Gitlab.com?
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
......
......@@ -229,12 +229,12 @@ module EE
super || DEFAULT_GROUP_VIEW
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)
def any_namespace_without_trial?
::Namespace
.from("(#{namespace_union_for_reporter_developer_maintainer_owned}) #{::Namespace.table_name}")
def owns_group_without_trial?
owned_groups
.include_gitlab_subscription
.where(parent_id: nil)
.where(gitlab_subscriptions: { trial_ends_on: nil })
.any?
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
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 | false | false
true | true | false | true | false
......@@ -161,7 +161,7 @@ RSpec.describe EE::UserCalloutsHelper do
before do
allow(helper).to receive(:show_ultimate_trial?) { show_ultimate_trial? }
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?
create(:gitlab_subscription, hosted_plan: ultimate_plan, namespace: namespace)
......
......@@ -21,7 +21,7 @@ RSpec.describe UsersHelper do
allow(helper).to receive(:can?).and_return(false)
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? }
end
......
......@@ -136,7 +136,7 @@ RSpec.describe User do
it 'returns the user' do
expect(described_class.find_by_smartcard_identity(smartcard_identity.subject,
smartcard_identity.issuer))
smartcard_identity.issuer))
.to eq(user)
end
end
......@@ -1249,7 +1249,7 @@ RSpec.describe User do
before do
allow(Gitlab::CurrentSettings)
.to receive(:should_check_namespace_plan?)
.and_return(false)
.and_return(false)
end
it { is_expected.to contain_exactly private_group, project_group, minimal_access_group }
......@@ -1263,7 +1263,7 @@ RSpec.describe User do
before do
allow(Gitlab::CurrentSettings)
.to receive(:should_check_namespace_plan?)
.and_return(true)
.and_return(true)
create(:gitlab_subscription, :ultimate, namespace: minimal_access_group)
create(:group_member, :minimal_access, user: user, source: create(:group))
end
......@@ -1711,4 +1711,34 @@ RSpec.describe User do
it { is_expected.to eq(result) }
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
......@@ -18,7 +18,10 @@ RSpec.shared_examples 'dashboard ultimate trial callout' do
allow(Gitlab).to receive(:com?).and_return(true)
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)
visit page_path
......@@ -30,6 +33,14 @@ RSpec.shared_examples 'dashboard ultimate trial callout' do
expect(page).not_to have_selector '.promotion-callout'
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
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