Commit bfde1e5b authored by Jay Swain's avatar Jay Swain

Display expiring subscription banner on more pages

The subscription banner should be shown for all group pages/subpages as
well as all project pages/subpages.

Finishes https://gitlab.com/gitlab-org/growth/product/-/issues/1557
parent 997e6bd8
# frozen_string_literal: true
module SubscribableBannerHelper
# Overridden in EE
def display_subscription_banner!
end
end
SubscribableBannerHelper.prepend_if_ee('EE::SubscribableBannerHelper')
- breadcrumb_title _("Details") - breadcrumb_title _("Details")
- @content_class = "limit-container-width" unless fluid_layout - @content_class = "limit-container-width" unless fluid_layout
= content_for :flash_message do
- if Feature.enabled?(:subscribable_banner_subscription)
= render_if_exists "layouts/header/ee_subscribable_banner", subscription: true
= content_for :meta_tags do = content_for :meta_tags do
= auto_discovery_link_tag(:atom, group_url(@group, rss_url_options), title: "#{@group.name} activity") = auto_discovery_link_tag(:atom, group_url(@group, rss_url_options), title: "#{@group.name} activity")
......
...@@ -6,8 +6,6 @@ ...@@ -6,8 +6,6 @@
.alert-wrapper .alert-wrapper
= render 'shared/outdated_browser' = render 'shared/outdated_browser'
= render_if_exists 'layouts/header/users_over_license_banner' = render_if_exists 'layouts/header/users_over_license_banner'
- if Feature.enabled?(:subscribable_banner_license, default_enabled: true)
= render_if_exists "layouts/header/ee_subscribable_banner"
= render_if_exists "layouts/header/licensed_user_count_threshold" = render_if_exists "layouts/header/licensed_user_count_threshold"
= render "layouts/broadcast" = render "layouts/broadcast"
= render "layouts/header/read_only_banner" = render "layouts/header/read_only_banner"
...@@ -15,6 +13,7 @@ ...@@ -15,6 +13,7 @@
= yield :flash_message = yield :flash_message
= render "shared/ping_consent" = render "shared/ping_consent"
= render_account_recovery_regular_check = render_account_recovery_regular_check
= render_if_exists "layouts/header/ee_subscribable_banner"
- unless @hide_breadcrumbs - unless @hide_breadcrumbs
= render "layouts/nav/breadcrumbs" = render "layouts/nav/breadcrumbs"
.d-flex .d-flex
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
- page_description @group.description unless page_description - page_description @group.description unless page_description
- header_title group_title(@group) unless header_title - header_title group_title(@group) unless header_title
- nav "group" - nav "group"
- display_subscription_banner!
- @left_sidebar = true - @left_sidebar = true
- content_for :page_specific_javascripts do - content_for :page_specific_javascripts do
......
...@@ -2,7 +2,8 @@ ...@@ -2,7 +2,8 @@
- page_description @project.description unless page_description - page_description @project.description unless page_description
- header_title project_title(@project) unless header_title - header_title project_title(@project) unless header_title
- nav "project" - nav "project"
- @left_sidebar = true - display_subscription_banner!
- @left_sidebar = true
- content_for :project_javascripts do - content_for :project_javascripts do
- project = @target_project || @project - project = @target_project || @project
......
...@@ -8,6 +8,4 @@ ...@@ -8,6 +8,4 @@
- unless project.empty_repo? - unless project.empty_repo?
= render 'shared/auto_devops_implicitly_enabled_banner', project: project = render 'shared/auto_devops_implicitly_enabled_banner', project: project
= render_if_exists 'projects/above_size_limit_warning', project: project = render_if_exists 'projects/above_size_limit_warning', project: project
- if Feature.enabled?(:subscribable_banner_subscription)
= render_if_exists "layouts/header/ee_subscribable_banner", subscription: true
= render_if_exists 'shared/shared_runners_minutes_limit', project: project, classes: [container_class, ("limit-container-width" unless fluid_layout)] = render_if_exists 'shared/shared_runners_minutes_limit', project: project, classes: [container_class, ("limit-container-width" unless fluid_layout)]
# frozen_string_literal: true
module EE
module SubscribableBannerHelper
extend ::Gitlab::Utils::Override
def gitlab_subscription_or_license
return decorated_subscription if display_subscription_banner?
License.current if display_license_banner?
end
def gitlab_subscription_message_or_license_message
return subscription_message if display_subscription_banner?
license_message if display_license_banner?
end
override :display_subscription_banner!
def display_subscription_banner!
@display_subscription_banner = true
end
private
def license_message(signed_in: signed_in?, is_admin: current_user&.admin?, license: License.current)
::Gitlab::ExpiringSubscriptionMessage.new(
subscribable: license,
signed_in: signed_in,
is_admin: is_admin
).message
end
def subscription_message
entity = @project || @group
namespace = @project&.namespace || @group
::Gitlab::ExpiringSubscriptionMessage.new(
subscribable: decorated_subscription,
signed_in: signed_in?,
is_admin: can?(current_user, :owner_access, entity),
namespace: namespace
).message
end
def decorated_subscription
entity = @project || @group
subscription = entity&.closest_gitlab_subscription
return unless subscription
::SubscriptionPresenter.new(subscription)
end
def display_license_banner?
::Feature.enabled?(:subscribable_license_banner, default_enabled: true)
end
def display_subscription_banner?
@display_subscription_banner &&
::Gitlab::CurrentSettings.should_check_namespace_plan? &&
::Feature.enabled?(:subscribable_subscription_banner, default_enabled: false)
end
end
end
...@@ -18,14 +18,6 @@ module LicenseHelper ...@@ -18,14 +18,6 @@ module LicenseHelper
License.current&.maximum_user_count || 0 License.current&.maximum_user_count || 0
end end
def license_message(signed_in: signed_in?, is_admin: current_user&.admin?, license: License.current)
Gitlab::ExpiringSubscriptionMessage.new(
subscribable: license,
signed_in: signed_in,
is_admin: is_admin
).message
end
def seats_calculation_message(license) def seats_calculation_message(license)
return unless license.present? return unless license.present?
return unless license.exclude_guests_from_active_count? return unless license.exclude_guests_from_active_count?
......
...@@ -3,29 +3,6 @@ ...@@ -3,29 +3,6 @@
module SubscriptionsHelper module SubscriptionsHelper
include ::Gitlab::Utils::StrongMemoize include ::Gitlab::Utils::StrongMemoize
def subscription_message
return unless ::Gitlab.com?
entity = @project || @group
namespace = @project&.namespace || @group
::Gitlab::ExpiringSubscriptionMessage.new(
subscribable: decorated_subscription,
signed_in: signed_in?,
is_admin: can?(current_user, :owner_access, entity),
namespace: namespace
).message
end
def decorated_subscription
entity = @project || @group
subscription = entity&.closest_gitlab_subscription
return unless subscription
SubscriptionPresenter.new(subscription)
end
def subscription_data def subscription_data
{ {
setup_for_company: (current_user.setup_for_company == true).to_s, setup_for_company: (current_user.setup_for_company == true).to_s,
......
...@@ -8,7 +8,7 @@ class SubscriptionPresenter < Gitlab::View::Presenter::Delegated ...@@ -8,7 +8,7 @@ class SubscriptionPresenter < Gitlab::View::Presenter::Delegated
end end
def plan def plan
namespace.try(:actual_plan_name) hosted_plan.name
end end
def notify_admins? def notify_admins?
......
- if local_assigns[:subscription] - subscribable = gitlab_subscription_or_license
- subscribable = decorated_subscription - message = gitlab_subscription_message_or_license_message
- message = subscription_message
- else
- subscribable = License.current
- message = license_message(license: subscribable)
- if message.present? && subscribable.present? - if message.present? && subscribable.present?
.container-fluid.container-limited.pt-3 .container-fluid.container-limited.pt-3
......
---
title: Display expiring subscription banner on more pages
merge_request: 31497
author:
type: changed
# frozen_string_literal: true
require 'spec_helper'
describe EE::SubscribableBannerHelper do
describe '#gitlab_subscription_or_license' do
subject { helper.gitlab_subscription_or_license }
shared_examples 'when a subscription exists' do
let(:gitlab_subscription) { build_stubbed(:gitlab_subscription) }
it 'returns a decorator' do
allow(entity).to receive(:closest_gitlab_subscription).and_return(gitlab_subscription)
expect(subject).to be_a(SubscriptionPresenter)
end
end
context 'when feature flag is enabled' do
let(:license) { double(:license) }
before do
stub_feature_flags(subscribable_banner: true)
end
context 'when instance variable true' do
before do
assign(:display_subscription_banner, true)
end
context 'when should_check_namespace_plan is true' do
before do
allow(::Gitlab::CurrentSettings).to receive(:should_check_namespace_plan?).and_return(true)
end
context 'when a project exists' do
let(:entity) { create(:project) }
before do
assign(:project, entity)
end
it_behaves_like 'when a subscription exists'
end
context 'when a group exists' do
let(:entity) { create(:group) }
before do
assign(:group, entity)
end
it_behaves_like 'when a subscription exists'
end
end
context 'when should_check_namespace_plan is false' do
before do
allow(::Gitlab::CurrentSettings).to receive(:should_check_namespace_plan?).and_return(false)
end
it 'returns the current license' do
expect(License).to receive(:current).and_return(license)
expect(subject).to eq(license)
end
end
end
context 'when instance variable false' do
before do
assign(:display_subscription_banner, false)
allow(::Gitlab::CurrentSettings).to receive(:should_check_namespace_plan?).and_return(true)
end
it 'returns the current license' do
expect(License).to receive(:current).and_return(license)
expect(subject).to eq(license)
end
end
end
end
describe '#gitlab_subscription_message_or_license_message' do
subject { helper.gitlab_subscription_message_or_license_message }
let(:message) { double(:message) }
context 'when feature flag is enabled' do
before do
stub_feature_flags(subscribable_banner: true)
end
context 'when instance variable true' do
before do
assign(:display_subscription_banner, true)
end
context 'when should_check_namespace_plan is true' do
before do
allow(::Gitlab::CurrentSettings).to receive(:should_check_namespace_plan?).and_return(true)
end
let(:gitlab_subscription) { entity.closest_gitlab_subscription }
let(:decorated_mock) { double(:decorated_mock) }
let(:message_mock) { double(:message_mock) }
let(:user) { double(:user_mock) }
shared_examples 'subscription message' do
it 'calls Gitlab::ExpiringSubscriptionMessage and SubscriptionPresenter if is Gitlab.com?' do
allow(helper).to receive(:signed_in?).and_return(true)
allow(helper).to receive(:current_user).and_return(user)
allow(helper).to receive(:can?).with(user, :owner_access, entity).and_return(true)
expect(SubscriptionPresenter).to receive(:new).with(gitlab_subscription).and_return(decorated_mock)
expect(::Gitlab::ExpiringSubscriptionMessage).to receive(:new).with(
subscribable: decorated_mock,
signed_in: true,
is_admin: true,
namespace: namespace
).and_return(message_mock)
expect(message_mock).to receive(:message).and_return('hey yay yay yay')
expect(subject).to eq('hey yay yay yay')
end
end
context 'when a project is present' do
let(:entity) { create(:project, namespace: namespace) }
let(:namespace) { create(:namespace_with_plan) }
before do
assign(:project, entity)
end
it_behaves_like 'subscription message'
end
context 'when a group is present' do
let(:entity) { create(:group_with_plan) }
let(:namespace) { entity }
before do
assign(:project, nil)
assign(:group, entity)
end
it_behaves_like 'subscription message'
end
end
context 'when should_check_namespace_plan is false' do
let(:license) { double(:license) }
let(:message_mock) { double(:message_mock) }
let(:user) { double(:user) }
before do
allow(::Gitlab::CurrentSettings).to receive(:should_check_namespace_plan?).and_return(false)
allow(License).to receive(:current).and_return(license)
allow(helper).to receive(:current_user).and_return(user)
allow(helper).to receive(:signed_in?).and_return(true)
allow(user).to receive(:admin?).and_return(false)
end
it 'calls Gitlab::ExpiringSubscriptionMessage to get expiring message' do
expect(Gitlab::ExpiringSubscriptionMessage).to receive(:new).with(
subscribable: license,
signed_in: true,
is_admin: false
).and_return(message_mock)
expect(message_mock).to receive(:message)
subject
end
end
end
context 'when instance variable false' do
before do
assign(:display_subscription_banner, false)
allow(::Gitlab::CurrentSettings).to receive(:should_check_namespace_plan?).and_return(true)
end
it 'returns the license message' do
expect(helper).to receive(:license_message).and_return(message)
expect(subject).to eq(message)
end
end
end
end
describe '#display_subscription_banner!' do
it 'sets @display_subscription_banner to true' do
expect(helper.instance_variable_get(:@display_subscription_banner)).to be nil
helper.display_subscription_banner!
expect(helper.instance_variable_get(:@display_subscription_banner)).to be true
end
end
end
...@@ -8,27 +8,6 @@ describe LicenseHelper do ...@@ -8,27 +8,6 @@ describe LicenseHelper do
allow(Rails.application.routes).to receive(:default_url_options).and_return(url_options) allow(Rails.application.routes).to receive(:default_url_options).and_return(url_options)
end end
describe '#license_message' do
let(:license) { double(:license) }
let(:message_mock) { double(:message_mock) }
before do
allow(License).to receive(:current).and_return(license)
end
it 'calls Gitlab::ExpiringSubscriptionMessage to get expiring message' do
expect(Gitlab::ExpiringSubscriptionMessage).to receive(:new).with(
subscribable: license,
signed_in: true,
is_admin: false
).and_return(message_mock)
expect(message_mock).to receive(:message)
license_message(signed_in: true, is_admin: false)
end
end
describe '#api_license_url' do describe '#api_license_url' do
it 'returns license API url' do it 'returns license API url' do
stub_default_url_options stub_default_url_options
......
...@@ -87,108 +87,4 @@ describe SubscriptionsHelper do ...@@ -87,108 +87,4 @@ describe SubscriptionsHelper do
it { is_expected.to eq(nil) } it { is_expected.to eq(nil) }
end end
end end
describe '#subscription_message' do
let(:gitlab_subscription) { entity.closest_gitlab_subscription }
let(:decorated_mock) { double(:decorated_mock) }
let(:message_mock) { double(:message_mock) }
let(:user) { double(:user_mock) }
it 'if it is not Gitlab.com? it returns nil' do
allow(Gitlab).to receive(:com?).and_return(false)
expect(helper.subscription_message).to be_nil
end
shared_examples 'subscription message' do
it 'calls Gitlab::ExpiringSubscriptionMessage and SubscriptionPresenter if is Gitlab.com?' do
allow(Gitlab).to receive(:com?).and_return(true)
allow(helper).to receive(:signed_in?).and_return(true)
allow(helper).to receive(:current_user).and_return(user)
allow(helper).to receive(:can?).with(user, :owner_access, entity).and_return(true)
expect(SubscriptionPresenter).to receive(:new).with(gitlab_subscription).and_return(decorated_mock)
expect(::Gitlab::ExpiringSubscriptionMessage).to receive(:new).with(
subscribable: decorated_mock,
signed_in: true,
is_admin: true,
namespace: namespace
).and_return(message_mock)
expect(message_mock).to receive(:message).and_return('hey yay yay yay')
expect(helper.subscription_message).to eq('hey yay yay yay')
end
end
context 'when a project is present' do
let(:entity) { create(:project, namespace: namespace) }
let(:namespace) { create(:namespace_with_plan) }
before do
assign(:project, entity)
end
it_behaves_like 'subscription message'
end
context 'when a group is present' do
let(:entity) { create(:group_with_plan) }
let(:namespace) { entity }
before do
assign(:project, nil)
assign(:group, entity)
end
it_behaves_like 'subscription message'
end
end
describe '#decorated_subscription' do
subject { helper.decorated_subscription }
shared_examples 'when a subscription exists' do
let(:gitlab_subscription) { build_stubbed(:gitlab_subscription) }
it 'returns a decorator' do
allow(entity).to receive(:closest_gitlab_subscription).and_return(gitlab_subscription)
expect(subject).to be_a(SubscriptionPresenter)
end
end
context 'when a project exists' do
let(:entity) { create(:project) }
before do
assign(:project, entity)
end
it_behaves_like 'when a subscription exists'
end
context 'when a group exists' do
let(:entity) { create(:group) }
before do
assign(:group, entity)
end
it_behaves_like 'when a subscription exists'
end
context 'when no subscription exists' do
let(:entity) { create(:project) }
before do
assign(:project, entity)
end
it 'returns a nil object' do
allow(entity).to receive(:closest_gitlab_subscription).and_return(nil)
expect(subject).to be_nil
end
end
end
end end
# frozen_string_literal: true
require 'spec_helper'
describe SubscribableBannerHelper do
describe '#display_subscription_banner!' do
it 'is over-written in EE' do
expect { helper.display_subscription_banner! }.not_to raise_error
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