Commit c291db55 authored by Alper Akgun's avatar Alper Akgun

Start trial CTA appear if all namespaces are free

Update start trial CTA in top right banner to only appear if all
namespaces are free
parent 262bcdd6
......@@ -110,6 +110,10 @@ class User < ApplicationRecord
through: :group_members,
source: :group
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
has_many :groups_projects, through: :groups, source: :projects
......
......@@ -16,7 +16,9 @@ module EE
return unless user
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
......@@ -253,6 +253,13 @@ module EE
.any?
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?
::Namespace
.includes(:plan)
......@@ -342,5 +349,12 @@ module EE
owned_groups.select(select).where(parent_id: nil)
]).to_sql
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
---
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
let(:user) { create(:user) }
using RSpec::Parameterized::TableSyntax
subject(:items) { helper.current_user_menu_items }
where(:user?, :gitlab_com?, :user_eligible?, :should_include_start_trial?) do
true | true | true | true
true | true | false | 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
where(
has_paid_namespace?: [true, false],
user?: [true, false],
gitlab_com?: [true, false],
user_eligible?: [true, false]
)
with_them do
before do
......@@ -27,15 +21,14 @@ describe UsersHelper do
allow(::Gitlab).to receive(:com?) { gitlab_com? }
allow(user).to receive(:any_namespace_without_trial?) { user_eligible? }
allow(user).to receive(:has_paid_namespace?) { has_paid_namespace? }
end
it do
if should_include_start_trial?
expect(items).to include(:start_trial)
else
expect(items).not_to include(:start_trial)
end
end
let(:expected_result) { !has_paid_namespace? && user? && gitlab_com? && user_eligible? }
subject { helper.current_user_menu_items.include?(:start_trial) }
it { is_expected.to eq(expected_result) }
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