Commit 328e928e authored by Michael Lunøe's avatar Michael Lunøe Committed by Stan Hu

Refactor(EoA Banner): Migrate to user callout

This also helps persist when the banner has been
dismissed
parent 3a77b9d2
...@@ -28,7 +28,8 @@ class UserCallout < ApplicationRecord ...@@ -28,7 +28,8 @@ class UserCallout < ApplicationRecord
feature_flags_new_version: 24, feature_flags_new_version: 24,
registration_enabled_callout: 25, registration_enabled_callout: 25,
new_user_signups_cap_reached: 26, # EE-only new_user_signups_cap_reached: 26, # EE-only
unfinished_tag_cleanup_callout: 27 unfinished_tag_cleanup_callout: 27,
eoa_bronze_plan_banner: 28 # EE-only
} }
validates :user, presence: true validates :user, presence: true
......
...@@ -127,20 +127,8 @@ module BillingPlansHelper ...@@ -127,20 +127,8 @@ module BillingPlansHelper
end end
end end
def show_eoa_banner?(namespace)
return false unless ::Feature.enabled?(:show_billing_eoa_banner)
return false unless Date.current < eoa_bronze_plan_end_date
return false unless namespace.bronze_plan?
(namespace.group? && namespace.has_owner?(current_user.id)) || !namespace.group?
end
private private
def eoa_bronze_plan_end_date
Date.parse('2022-01-26')
end
def add_seats_url(group) def add_seats_url(group)
return unless group return unless group
......
...@@ -13,6 +13,7 @@ module EE ...@@ -13,6 +13,7 @@ module EE
NEW_USER_SIGNUPS_CAP_REACHED = 'new_user_signups_cap_reached' NEW_USER_SIGNUPS_CAP_REACHED = 'new_user_signups_cap_reached'
PERSONAL_ACCESS_TOKEN_EXPIRY = 'personal_access_token_expiry' PERSONAL_ACCESS_TOKEN_EXPIRY = 'personal_access_token_expiry'
THREAT_MONITORING_INFO = 'threat_monitoring_info' THREAT_MONITORING_INFO = 'threat_monitoring_info'
EOA_BRONZE_PLAN_BANNER = 'eoa_bronze_plan_banner'
def render_enable_hashed_storage_warning def render_enable_hashed_storage_warning
return unless show_enable_hashed_storage_warning? return unless show_enable_hashed_storage_warning?
...@@ -93,8 +94,21 @@ module EE ...@@ -93,8 +94,21 @@ module EE
new_user_signups_cap.to_i <= ::User.billable.count new_user_signups_cap.to_i <= ::User.billable.count
end end
def show_eoa_bronze_plan_banner?(namespace)
return false unless ::Feature.enabled?(:show_billing_eoa_banner)
return false unless Date.current < eoa_bronze_plan_end_date
return false unless namespace.bronze_plan?
return false if user_dismissed?(EOA_BRONZE_PLAN_BANNER)
(namespace.group? && namespace.has_owner?(current_user.id)) || !namespace.group?
end
private private
def eoa_bronze_plan_end_date
Date.parse('2022-01-26')
end
def hashed_storage_enabled? def hashed_storage_enabled?
::Gitlab::CurrentSettings.current_application_settings.hashed_storage_enabled ::Gitlab::CurrentSettings.current_application_settings.hashed_storage_enabled
end end
......
- if show_eoa_banner?(namespace) - if show_eoa_bronze_plan_banner?(namespace)
.container-fluid.container-limited.pt-3 .container-fluid.container-limited.pt-3
.gl-alert.gl-alert-info.mt-3{ role: 'alert' } .gl-alert.gl-alert-info.gl-mt-5{ role: 'alert', data: { feature_id: ::EE::UserCalloutsHelper::EOA_BRONZE_PLAN_BANNER, dismiss_endpoint: user_callouts_path } }
= sprite_icon('information-o', css_class: 'gl-icon gl-alert-icon gl-alert-icon-no-title') = sprite_icon('information-o', css_class: 'gl-icon gl-alert-icon gl-alert-icon-no-title')
%button.js-close.gl-alert-dismiss{ type: 'button', 'aria-label' => _('Dismiss') } %button.js-close.gl-alert-dismiss{ type: 'button', 'aria-label' => _('Dismiss') }
= sprite_icon('close', css_class: 'gl-icon') = sprite_icon('close', css_class: 'gl-icon')
......
...@@ -3,8 +3,6 @@ ...@@ -3,8 +3,6 @@
require 'spec_helper' require 'spec_helper'
RSpec.describe BillingPlansHelper do RSpec.describe BillingPlansHelper do
include Devise::Test::ControllerHelpers
describe '#subscription_plan_data_attributes' do describe '#subscription_plan_data_attributes' do
let(:customer_portal_url) { "#{EE::SUBSCRIPTIONS_URL}/subscriptions" } let(:customer_portal_url) { "#{EE::SUBSCRIPTIONS_URL}/subscriptions" }
...@@ -421,118 +419,6 @@ RSpec.describe BillingPlansHelper do ...@@ -421,118 +419,6 @@ RSpec.describe BillingPlansHelper do
end end
end end
describe '#show_eoa_banner?' do
let_it_be(:user) { create(:user) }
stub_feature_flags(show_billing_eoa_banner: true)
shared_examples 'current time' do
before do
allow(namespace).to receive(:actual_plan_name).and_return(::Plan::BRONZE)
end
it 'displays the banner' do
travel_to(eoa_bronze_plan_end_date - 1.day) do
expect(helper.show_eoa_banner?(namespace)).to eq(true)
end
end
end
shared_examples 'past eoa date' do
before do
allow(namespace).to receive(:actual_plan_name).and_return(::Plan::BRONZE)
end
it 'does not display the banner' do
travel_to(eoa_bronze_plan_end_date + 1.day) do
expect(helper.show_eoa_banner?(namespace)).to eq(false)
end
end
end
shared_examples 'with show_billing_eoa_banner turned off' do
before do
stub_feature_flags(show_billing_eoa_banner: false)
allow(namespace).to receive(:actual_plan_name).and_return(::Plan::BRONZE)
end
it 'does not display the banner' do
travel_to(eoa_bronze_plan_end_date - 1.day) do
expect(helper.show_eoa_banner?(namespace)).to eq(false)
end
end
end
shared_examples 'with a different plan than Bronze' do
before do
allow(namespace).to receive(:actual_plan_name).and_return(::Plan::SILVER)
end
it 'does not display the banner' do
travel_to(eoa_bronze_plan_end_date - 1.day) do
expect(helper.show_eoa_banner?(namespace)).to eq(false)
end
end
end
context 'with group namespace' do
let(:group) { create(:group) }
let(:current_user) { user }
before do
group.add_owner(current_user.id)
allow(group).to receive(:actual_plan_name).and_return(::Plan::BRONZE)
allow(helper).to receive(:current_user).and_return(current_user)
end
it_behaves_like 'current time' do
let(:namespace) { group }
end
it_behaves_like 'past eoa date' do
let(:namespace) { group }
end
it_behaves_like 'with show_billing_eoa_banner turned off' do
let(:namespace) { group }
end
it_behaves_like 'with a different plan than Bronze' do
let(:namespace) { group }
end
end
context 'with personal namespace' do
let(:current_user) { user }
before do
allow(current_user.namespace).to receive(:actual_plan_name).and_return(::Plan::BRONZE)
end
it_behaves_like 'current time' do
let(:namespace) { current_user.namespace }
end
it_behaves_like 'past eoa date' do
let(:namespace) { current_user.namespace }
end
it_behaves_like 'with show_billing_eoa_banner turned off' do
let(:namespace) { current_user.namespace }
end
it_behaves_like 'with a different plan than Bronze' do
let(:namespace) { current_user.namespace }
end
end
end
describe '#eoa_bronze_plan_end_date' do
it 'returns a date type value' do
expect(helper.send(:eoa_bronze_plan_end_date).is_a?(Date)).to eq(true)
end
end
describe '#subscription_plan_info' do describe '#subscription_plan_info' do
it 'returns the current plan' do it 'returns the current plan' do
other_plan = Hashie::Mash.new(code: 'bronze') other_plan = Hashie::Mash.new(code: 'bronze')
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
require "spec_helper" require "spec_helper"
RSpec.describe EE::UserCalloutsHelper do RSpec.describe EE::UserCalloutsHelper do
include Devise::Test::ControllerHelpers
using RSpec::Parameterized::TableSyntax using RSpec::Parameterized::TableSyntax
describe '.render_enable_hashed_storage_warning' do describe '.render_enable_hashed_storage_warning' do
...@@ -379,4 +380,71 @@ RSpec.describe EE::UserCalloutsHelper do ...@@ -379,4 +380,71 @@ RSpec.describe EE::UserCalloutsHelper do
end end
end end
end end
describe '#show_eoa_bronze_plan_banner?' do
let_it_be(:user) { create(:user) }
shared_examples 'shows and hides the banner depending on circumstances' do
where(:show_billing_eoa_banner, :actual_plan_name, :dismissed_callout, :travel_to_date, :result) do
true | ::Plan::BRONZE | false | eoa_bronze_plan_end_date - 1.day | true
true | ::Plan::BRONZE | false | eoa_bronze_plan_end_date | false
true | ::Plan::BRONZE | false | eoa_bronze_plan_end_date + 1.day | false
true | ::Plan::BRONZE | true | eoa_bronze_plan_end_date - 1.day | false
true | ::Plan::SILVER | false | eoa_bronze_plan_end_date - 1.day | false
true | ::Plan::GOLD | false | eoa_bronze_plan_end_date - 1.day | false
false | ::Plan::BRONZE | false | eoa_bronze_plan_end_date - 1.day | false
end
with_them do
before do
stub_feature_flags(show_billing_eoa_banner: show_billing_eoa_banner)
allow(namespace).to receive(:actual_plan_name).and_return(actual_plan_name)
allow(user).to receive(:dismissed_callout?).and_return(dismissed_callout)
end
it do
travel_to(travel_to_date) do
expect(helper.show_eoa_bronze_plan_banner?(namespace)).to eq(result)
end
end
end
end
before do
allow(helper).to receive(:current_user).and_return(user)
end
context 'with group namespace' do
let(:group) { create(:group) }
let(:current_user) { user }
before do
group.add_owner(current_user.id)
allow(group).to receive(:actual_plan_name).and_return(::Plan::BRONZE)
allow(helper).to receive(:current_user).and_return(current_user)
end
it_behaves_like 'shows and hides the banner depending on circumstances' do
let(:namespace) { group }
end
end
context 'with personal namespace' do
let(:current_user) { user }
before do
allow(current_user.namespace).to receive(:actual_plan_name).and_return(::Plan::BRONZE)
end
it_behaves_like 'shows and hides the banner depending on circumstances' do
let(:namespace) { current_user.namespace }
end
end
end
describe '#eoa_bronze_plan_end_date' do
it 'returns a date type value' do
expect(helper.send(:eoa_bronze_plan_end_date).is_a?(Date)).to eq(true)
end
end
end end
...@@ -65,8 +65,24 @@ RSpec.describe 'shared/billings/_eoa_bronze_plan_banner.html.haml' do ...@@ -65,8 +65,24 @@ RSpec.describe 'shared/billings/_eoa_bronze_plan_banner.html.haml' do
end end
end end
shared_examples 'when user dismissed the banner' do
before do
allow(namespace).to receive(:actual_plan_name).and_return(::Plan::BRONZE)
allow(view).to receive(:user_dismissed?).with(::EE::UserCalloutsHelper::EOA_BRONZE_PLAN_BANNER).and_return(true)
end
it 'does not display the banner' do
travel_to(eoa_bronze_plan_end_date - 1.day) do
render
expect(rendered).not_to have_content("End of availability for the Bronze Plan")
end
end
end
before do before do
allow(view).to receive(:eoa_bronze_plan_end_date).and_return(eoa_bronze_plan_end_date) allow(view).to receive(:eoa_bronze_plan_end_date).and_return(eoa_bronze_plan_end_date)
allow(view).to receive(:user_dismissed?).with(::EE::UserCalloutsHelper::EOA_BRONZE_PLAN_BANNER).and_return(false)
end end
context 'with group namespace' do context 'with group namespace' do
......
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