Commit da10f026 authored by Douglas Barbosa Alexandre's avatar Douglas Barbosa Alexandre

Merge branch...

Merge branch '8591-geo-http-403-when-dismissing-free-trial-of-gitlab-com-gold-message' into 'master'

Don't show 'Free Trial of GitLab.com Gold' message for secondary nodes

Closes #8591

See merge request gitlab-org/gitlab-ee!8635
parents 27097a63 8be435b0
......@@ -22,7 +22,9 @@ module EE
end
def user_default_dashboard?(user = current_user)
controller_action_to_child_dashboards.any? {|dashboard| dashboard == user.dashboard }
return false unless user
controller_action_to_child_dashboards.any? { |dashboard| dashboard == user.dashboard }
end
end
end
......@@ -2,13 +2,24 @@
module EE
module UserCalloutsHelper
GOLD_TRIAL = 'gold_trial'.freeze
GOLD_TRIAL = 'gold_trial'
def show_gold_trial?(user = current_user)
!user_dismissed?(GOLD_TRIAL) &&
(::Gitlab.com? || Rails.env.development?) &&
!user.any_namespace_with_gold? &&
!user.any_namespace_with_trial?
return false if user_dismissed?(GOLD_TRIAL)
return false unless show_gold_trial_suitable_env?
users_namespaces_clean?(user)
end
def show_gold_trial_suitable_env?
(::Gitlab.com? || Rails.env.development?) &&
!::Gitlab::Database.read_only?
end
def users_namespaces_clean?(user)
return false if user.any_namespace_with_gold?
!user.any_namespace_with_trial?
end
end
end
- if show_gold_trial? && user_default_dashboard?
- if user_default_dashboard? && show_gold_trial?
.pt-1.d-none.d-md-block{ class: container_class }
.user-callout.promotion-callout.thin-callout.js-gold-trial-callout{ data: { uid: 'trial_callout_dismissed', feature_id: UserCalloutsHelper::GOLD_TRIAL, dismiss_endpoint: user_callouts_path } }
.bordered-box.justify-content-left.align-items-center
......
# frozen_string_literal: true
require 'spec_helper'
describe EE::UserCalloutsHelper do
let(:user) { create(:user) }
before do
allow(helper).to receive(:current_user).and_return(user)
end
describe '.show_gold_trial?' do
let(:suitable_env) { nil }
before do
allow(helper).to receive(:user_dismissed?).with(described_class::GOLD_TRIAL).and_return(user_dismissed)
allow(helper).to receive(:show_gold_trial_suitable_env?).and_return(suitable_env)
end
context 'when user has already dismissed the callout' do
let(:user_dismissed) { true }
it 'returns false' do
expect(helper.show_gold_trial?).to be_falsey
end
end
context 'when show_gold_trial_suitable_env? returns false' do
let(:user_dismissed) { false }
let(:suitable_env) { false }
it 'returns false' do
expect(helper.show_gold_trial?).to be_falsey
end
end
context 'when show_gold_trial_namespaces_checked?' do
let(:user_dismissed) { false }
let(:suitable_env) { true }
before do
allow(helper).to receive(:users_namespaces_clean?).and_return(namespaces_checked)
end
context 'returns false' do
let(:namespaces_checked) { false }
it 'returns false' do
expect(helper.show_gold_trial?).to be_falsey
end
end
context 'returns true' do
let(:namespaces_checked) { true }
it 'returns true' do
expect(helper.show_gold_trial?).to be_truthy
end
end
end
end
describe '.show_gold_trial_suitable_env?' do
before do
allow(Gitlab).to receive(:com?).and_return(gitlab_com)
allow(Rails.env).to receive(:development?).and_return(rails_dev_env)
allow(Gitlab::Database).to receive(:read_only?).and_return(db_read_only)
end
context 'with a writable DB' do
let(:db_read_only) { false }
context "when we're neither GitLab.com or a Rails development env" do
let(:gitlab_com) { false }
let(:rails_dev_env) { false }
it 'returns true' do
expect(helper.show_gold_trial_suitable_env?).to be_falsey
end
end
context "when we're GitLab.com" do
let(:gitlab_com) { true }
let(:rails_dev_env) { false }
it 'returns true' do
expect(helper.show_gold_trial_suitable_env?).to be_truthy
end
end
context "when we're a Rails development env" do
let(:gitlab_com) { false }
let(:rails_dev_env) { true }
it 'returns true' do
expect(helper.show_gold_trial_suitable_env?).to be_truthy
end
end
end
context 'with a readonly DB' do
let(:db_read_only) { true }
context "when we're GitLab.com" do
let(:gitlab_com) { true }
let(:rails_dev_env) { false }
it 'returns true' do
expect(helper.show_gold_trial_suitable_env?).to be_falsey
end
end
context "when we're a Rails development env" do
let(:gitlab_com) { false }
let(:rails_dev_env) { true }
it 'returns true' do
expect(helper.show_gold_trial_suitable_env?).to be_falsey
end
end
end
end
describe '.show_gold_trial_namespaces_checked?' do
let(:a_name_space_has_trial) { nil }
before do
allow(user).to receive(:any_namespace_with_gold?).and_return(a_name_space_has_gold)
allow(user).to receive(:any_namespace_with_trial?).and_return(a_name_space_has_trial)
end
context "when a user's namespace has gold" do
let(:a_name_space_has_gold) { true }
it 'returns false' do
expect(helper.users_namespaces_clean?(user)).to be_falsey
end
end
context "when a user's namespace does not have gold" do
let(:a_name_space_has_gold) { false }
context "but a user's namespace has a trial" do
let(:a_name_space_has_trial) { true }
it 'returns false' do
expect(helper.users_namespaces_clean?(user)).to be_falsey
end
end
context "and does not have a trial" do
let(:a_name_space_has_trial) { false }
it 'returns true' do
expect(helper.users_namespaces_clean?(user)).to be_truthy
end
end
end
end
end
......@@ -53,5 +53,11 @@ shared_examples 'gold trial callout' do
expect(page).not_to have_selector '.promotion-callout'
end
it 'hides promotion callout if database is in a readonly state' do
allow(Gitlab::Database).to receive(:read_only?).and_return(true)
expect(page).not_to have_selector '.promotion-callout'
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