Commit 9da101ef authored by Nick Thomas's avatar Nick Thomas

Merge branch...

Merge branch '36402-update-start-trial-cta-in-top-right-banner-to-only-appear-if-all-namespaces-are-free' into 'master'

Update start trial CTA in top right banner to only appear if all namespaces are free

See merge request gitlab-org/gitlab!20177
parents 5466da88 c291db55
...@@ -110,6 +110,10 @@ class User < ApplicationRecord ...@@ -110,6 +110,10 @@ class User < ApplicationRecord
through: :group_members, through: :group_members,
source: :group source: :group
alias_attribute :masters_groups, :maintainers_groups alias_attribute :masters_groups, :maintainers_groups
has_many :reporter_developer_maintainer_owned_groups,
-> { where(members: { access_level: [Gitlab::Access::REPORTER, Gitlab::Access::DEVELOPER, Gitlab::Access::MAINTAINER, Gitlab::Access::OWNER] }) },
through: :group_members,
source: :group
# Projects # Projects
has_many :groups_projects, through: :groups, source: :projects has_many :groups_projects, through: :groups, source: :projects
......
...@@ -16,7 +16,9 @@ module EE ...@@ -16,7 +16,9 @@ module EE
return unless user return unless user
return unless ::Gitlab.com? return unless ::Gitlab.com?
user.any_namespace_without_trial? Rails.cache.fetch(['users', user.id, 'trials_allowed?'], expires_in: 10.minutes) do
!user.has_paid_namespace? && user.any_namespace_without_trial?
end
end end
end end
end end
...@@ -253,6 +253,13 @@ module EE ...@@ -253,6 +253,13 @@ module EE
.any? .any?
end end
def has_paid_namespace?
::Namespace
.from("(#{namespace_union_for_reporter_developer_maintainer_owned(:plan_id)}) #{::Namespace.table_name}")
.where(plan_id: Plan.where(name: Plan::PAID_HOSTED_PLANS).select(:id))
.any?
end
def any_namespace_with_gold? def any_namespace_with_gold?
::Namespace ::Namespace
.includes(:plan) .includes(:plan)
...@@ -342,5 +349,12 @@ module EE ...@@ -342,5 +349,12 @@ module EE
owned_groups.select(select).where(parent_id: nil) owned_groups.select(select).where(parent_id: nil)
]).to_sql ]).to_sql
end end
def namespace_union_for_reporter_developer_maintainer_owned(select = :id)
::Gitlab::SQL::Union.new([
::Namespace.select(select).where(type: nil, owner: self),
reporter_developer_maintainer_owned_groups.select(select).where(parent_id: nil)
]).to_sql
end
end end
end end
---
title: Update start trial CTA in top right banner to only appear if all namespaces
are free
merge_request: 20177
author:
type: changed
...@@ -7,18 +7,12 @@ describe UsersHelper do ...@@ -7,18 +7,12 @@ describe UsersHelper do
let(:user) { create(:user) } let(:user) { create(:user) }
using RSpec::Parameterized::TableSyntax using RSpec::Parameterized::TableSyntax
subject(:items) { helper.current_user_menu_items } where(
has_paid_namespace?: [true, false],
where(:user?, :gitlab_com?, :user_eligible?, :should_include_start_trial?) do user?: [true, false],
true | true | true | true gitlab_com?: [true, false],
true | true | false | false user_eligible?: [true, false]
true | false | true | false )
true | false | false | false
false | true | true | false
false | true | false | false
false | false | true | false
false | false | false | false
end
with_them do with_them do
before do before do
...@@ -27,15 +21,14 @@ describe UsersHelper do ...@@ -27,15 +21,14 @@ describe UsersHelper do
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(:any_namespace_without_trial?) { user_eligible? }
allow(user).to receive(:has_paid_namespace?) { has_paid_namespace? }
end end
it do let(:expected_result) { !has_paid_namespace? && user? && gitlab_com? && user_eligible? }
if should_include_start_trial?
expect(items).to include(:start_trial) subject { helper.current_user_menu_items.include?(:start_trial) }
else
expect(items).not_to include(:start_trial) it { is_expected.to eq(expected_result) }
end
end
end end
end end
end end
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