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
......@@ -7,19 +7,19 @@ class UserCallout < ApplicationRecord
gke_cluster_integration: 1,
gcp_signup_offer: 2,
cluster_security_warning: 3,
gold_trial: 4, # EE-only
geo_enable_hashed_storage: 5, # EE-only
geo_migrate_hashed_storage: 6, # EE-only
canary_deployment: 7, # EE-only
gold_trial_billings: 8, # EE-only
gold_trial: 4, # EE-only
geo_enable_hashed_storage: 5, # EE-only
geo_migrate_hashed_storage: 6, # EE-only
canary_deployment: 7, # EE-only
gold_trial_billings: 8, # EE-only
suggest_popover_dismissed: 9,
tabs_position_highlight: 10,
threat_monitoring_info: 11, # EE-only
account_recovery_regular_check: 12, # EE-only
threat_monitoring_info: 11, # EE-only
account_recovery_regular_check: 12, # EE-only
webhooks_moved: 13,
service_templates_deprecated: 14,
admin_integrations_moved: 15,
web_ide_alert_dismissed: 16, # no longer in use
web_ide_alert_dismissed: 16, # no longer in use
active_user_count_threshold: 18, # EE-only
buy_pipeline_minutes_notification_dot: 19, # EE-only
personal_access_token_expiry: 21, # EE-only
......@@ -27,8 +27,9 @@ class UserCallout < ApplicationRecord
customize_homepage: 23,
feature_flags_new_version: 24,
registration_enabled_callout: 25,
new_user_signups_cap_reached: 26, # EE-only
unfinished_tag_cleanup_callout: 27
new_user_signups_cap_reached: 26, # EE-only
unfinished_tag_cleanup_callout: 27,
eoa_bronze_plan_banner: 28 # EE-only
}
validates :user, presence: true
......
......@@ -127,20 +127,8 @@ module BillingPlansHelper
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
def eoa_bronze_plan_end_date
Date.parse('2022-01-26')
end
def add_seats_url(group)
return unless group
......
......@@ -13,6 +13,7 @@ module EE
NEW_USER_SIGNUPS_CAP_REACHED = 'new_user_signups_cap_reached'
PERSONAL_ACCESS_TOKEN_EXPIRY = 'personal_access_token_expiry'
THREAT_MONITORING_INFO = 'threat_monitoring_info'
EOA_BRONZE_PLAN_BANNER = 'eoa_bronze_plan_banner'
def render_enable_hashed_storage_warning
return unless show_enable_hashed_storage_warning?
......@@ -93,8 +94,21 @@ module EE
new_user_signups_cap.to_i <= ::User.billable.count
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
def eoa_bronze_plan_end_date
Date.parse('2022-01-26')
end
def hashed_storage_enabled?
::Gitlab::CurrentSettings.current_application_settings.hashed_storage_enabled
end
......
- if show_eoa_banner?(namespace)
- if show_eoa_bronze_plan_banner?(namespace)
.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')
%button.js-close.gl-alert-dismiss{ type: 'button', 'aria-label' => _('Dismiss') }
= sprite_icon('close', css_class: 'gl-icon')
......
......@@ -3,8 +3,6 @@
require 'spec_helper'
RSpec.describe BillingPlansHelper do
include Devise::Test::ControllerHelpers
describe '#subscription_plan_data_attributes' do
let(:customer_portal_url) { "#{EE::SUBSCRIPTIONS_URL}/subscriptions" }
......@@ -421,118 +419,6 @@ RSpec.describe BillingPlansHelper do
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
it 'returns the current plan' do
other_plan = Hashie::Mash.new(code: 'bronze')
......
......@@ -3,6 +3,7 @@
require "spec_helper"
RSpec.describe EE::UserCalloutsHelper do
include Devise::Test::ControllerHelpers
using RSpec::Parameterized::TableSyntax
describe '.render_enable_hashed_storage_warning' do
......@@ -379,4 +380,71 @@ RSpec.describe EE::UserCalloutsHelper do
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
......@@ -65,8 +65,24 @@ RSpec.describe 'shared/billings/_eoa_bronze_plan_banner.html.haml' do
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
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
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