diff --git a/ee/app/helpers/license_helper.rb b/ee/app/helpers/license_helper.rb index 30340c24df1ed1d5be60f7cdd820107ca8a7c013..3c2fbcd8e7b2c0655a4b24df7a41ee9f4b8ce1f7 100644 --- a/ee/app/helpers/license_helper.rb +++ b/ee/app/helpers/license_helper.rb @@ -28,12 +28,14 @@ def new_trial_url uri.to_s end - def show_promotions?(selected_user = current_user) + def show_promotions?(selected_user = current_user, hide_on_self_managed: false) return false unless selected_user if Gitlab::CurrentSettings.current_application_settings - .should_check_namespace_plan? + .should_check_namespace_plan? # that checks Gitlab.com? too true + elsif hide_on_self_managed + false else license = License.current license.nil? || license.expired? diff --git a/ee/app/views/shared/promotions/_promote_epics.html.haml b/ee/app/views/shared/promotions/_promote_epics.html.haml index 9a0d07882964c001ac0e6ee060e90e591d5cccf7..b05f9e44622ec86387168cb70eb6bc31c2571245 100644 --- a/ee/app/views/shared/promotions/_promote_epics.html.haml +++ b/ee/app/views/shared/promotions/_promote_epics.html.haml @@ -1,6 +1,6 @@ - promotion_feature = 'promote_epics_sidebar_dismissed' -- if show_promotions? && show_callout?(promotion_feature) +- if show_promotions?(hide_on_self_managed: true) && show_callout?(promotion_feature) .block.js-epics-sidebar-callout.promotion-issue-sidebar{ data: { uid: promotion_feature } } .sidebar-collapsed-icon{ data: { toggle: "dropdown", target: ".js-epics-sidebar-callout" } } %span{ data: { toggle: "tooltip", placement: "left", container: "body" }, title: _('Epic') } diff --git a/ee/spec/features/promotion_spec.rb b/ee/spec/features/promotion_spec.rb index 61c430beaf8a7e1a98887e4f8ebe513904f7f15f..eb37937e1a42427058e5bc7744c60411c81867e6 100644 --- a/ee/spec/features/promotion_spec.rb +++ b/ee/spec/features/promotion_spec.rb @@ -163,7 +163,12 @@ sign_in(user) end - it_behaves_like 'Epics promotion' + it 'does not appear on the page' do + visit project_issue_path(project, issue) + wait_for_requests + + expect(page).not_to have_selector('.js-epics-sidebar-callout') + end end end @@ -214,7 +219,6 @@ click_link 'Learn more' expect(page).to have_selector('.js-weight-sidebar-callout') - expect(page).to have_selector('.promotion-issue-sidebar-message', visible: false) end context 'when checking namespace plans' do diff --git a/ee/spec/helpers/license_helper_spec.rb b/ee/spec/helpers/license_helper_spec.rb index f027840b937b1bb9102793c0089277e8eaebdb35..f73892be9d75d37373b862b6604c6b7037c47fe3 100644 --- a/ee/spec/helpers/license_helper_spec.rb +++ b/ee/spec/helpers/license_helper_spec.rb @@ -120,4 +120,74 @@ def stub_default_url_options(host: "localhost", protocol: "http", port: nil, scr end end end + + describe '#show_promotions?' do + context 'without a user' do + subject { helper.show_promotions?(nil) } + + it { is_expected.to eq(false) } + end + + context 'with a user' do + let_it_be(:selected_user) { create(:user) } + + subject { helper.show_promotions?(selected_user) } + + context 'on saas' do + before do + stub_ee_application_setting(should_check_namespace_plan: true) + end + + it { is_expected.to eq(true) } + end + + context 'when gitlabdotcom returns false' do + before do + allow(Gitlab).to receive(:com?).and_return(false) + end + + it { is_expected.to eq(false) } + end + + context 'on EE' do + context 'with hide on self managed true' do + subject { helper.show_promotions?(selected_user, hide_on_self_managed: true) } + + it { is_expected.to eq(false) } + end + + context 'without a valid license' do + before do + allow(License).to receive(:current).and_return(nil) + end + + it { is_expected.to eq(true) } + end + + context 'with a valid license' do + let_it_be(:license) { create(:license) } + + before do + allow(License).to receive(:current).and_return(license) + end + + context 'expired license' do + before do + allow(license).to receive(:expired?).and_return(true) + end + + it { is_expected.to eq(true) } + end + + context 'non expired license' do + before do + allow(license).to receive(:expired?).and_return(false) + end + + it { is_expected.to eq(false) } + end + end + end + end + end end