Commit e614de5b authored by Corinna Wiesner's avatar Corinna Wiesner

Render manual renewal banner

Render the manual renewal banner by using the previously introduced
backend logic. The banner will be displayed to offline customers that
have restricted internet access. The logic is behind a feature flag.
parent a7b7f5ae
......@@ -3,6 +3,7 @@
- billable_users_url = help_page_path('subscriptions/self_managed/index', anchor: 'billable-users')
- billable_users_link_start = '<a href="%{url}" target="_blank" rel="noopener noreferrer nofollow">'.html_safe % { url: billable_users_url }
= render_if_exists 'shared/manual_renewal_banner'
= render_if_exists 'shared/qrtly_reconciliation_alert'
= render 'admin/dashboard/security_newsletter_callout'
......
# frozen_string_literal: true
module ManualRenewalBannerHelper
def manual_renewal_banner
return unless current_user&.can_admin_all_resources?
Gitlab::ManualRenewalBanner.new(actionable: License.current)
end
end
-# EE:Self Managed
- page_title _('Subscription')
= render_if_exists 'shared/manual_renewal_banner'
#js-show-subscription-page{ data: cloud_license_view_data }
- payload = manual_renewal_banner
- return unless payload&.display?
= content_for :page_level_alert do
= render 'shared/global_alert',
title: payload.subject,
variant: payload.display_error_version? ? :danger : :warning,
close_button_class: 'js-close',
alert_class: 'gl-mt-5 gl-mb-5',
alert_data: { testid: 'close-manual-renewal-banner' } do
.gl-alert-body
= payload.body
.gl-alert-actions
= link_to s_('SubscriptionBanner|Export license usage file'), admin_license_usage_export_path(format: :csv), class: 'btn gl-alert-action gl-button btn-confirm'
= link_to s_('SubscriptionBanner|Upload new license'), new_admin_license_path, class: 'btn gl-alert-action gl-button btn-default'
......@@ -98,4 +98,6 @@ RSpec.describe 'Admin Dashboard' do
end
end
end
include_examples 'manual renewal banner', path_to_visit: :admin_subscription_path
end
......@@ -224,6 +224,8 @@ RSpec.describe 'Admin views Subscription', :js do
end
end
include_examples 'manual renewal banner', path_to_visit: :admin_subscription_path
private
def fill_activation_form
......
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe ManualRenewalBannerHelper do
describe '#manual_renewal_banner' do
subject(:manual_renewal_banner) { helper.manual_renewal_banner }
let_it_be(:current_user) { create(:admin) }
before do
allow(helper).to receive(:current_user).and_return(current_user)
end
context 'when current user is empty' do
let(:current_user) { nil }
it 'does not return a banner payload' do
expect(manual_renewal_banner).to eq(nil)
end
end
context 'when current user cannot admin all resources' do
it 'does not return a banner payload' do
expect(manual_renewal_banner).to eq(nil)
end
end
context 'when current user can admin all resources' do
before do
allow(current_user).to receive(:can_admin_all_resources?).and_return(true)
allow_next_instance_of(Gitlab::ManualRenewalBanner) do |banner|
allow(banner).to receive(:display?).and_return(display_banner)
end
end
context 'when no banner instance is returned' do
let(:display_banner) { false }
it 'does not return a banner payload' do
aggregate_failures do
expect(manual_renewal_banner).to be_an_instance_of(Gitlab::ManualRenewalBanner)
expect(manual_renewal_banner.subject).to eq(nil)
end
end
end
context 'when a banner instance is returned' do
let(:display_banner) { true }
context 'when current license is expired' do
before do
allow(License).to receive(:current).and_return(create(:license, expires_at: 1.month.ago.to_date))
end
it 'returns a banner payload' do
aggregate_failures do
expect(manual_renewal_banner).to be_an_instance_of(Gitlab::ManualRenewalBanner)
expect(manual_renewal_banner.subject).to include('subscription expired')
expect(manual_renewal_banner.display_error_version?).to eq(true)
end
end
end
context 'when current license is not expired' do
it 'returns a banner payload' do
aggregate_failures do
expect(manual_renewal_banner).to be_an_instance_of(Gitlab::ManualRenewalBanner)
expect(manual_renewal_banner.subject).to include('subscription expires')
expect(manual_renewal_banner.display_error_version?).to eq(false)
end
end
end
end
end
end
end
# frozen_string_literal: true
RSpec.shared_examples 'manual renewal banner' do |path_to_visit:|
shared_examples 'a visible dismissible manual renewal banner' do
context 'when dismissed' do
before do
page.within(find('[data-testid="close-manual-renewal-banner"]', match: :first)) do
click_button 'Dismiss'
end
end
it_behaves_like 'a hidden manual renewal banner'
context 'when visiting again' do
before do
visit current_path
end
it 'displays a banner' do
expect(page).to have_selector('[data-testid="close-manual-renewal-banner"]')
end
end
end
end
shared_examples 'a hidden manual renewal banner' do
it 'does not display a banner' do
expect(page).not_to have_selector('[data-testid="close-manual-renewal-banner"]')
end
end
describe 'manual renewal banner', :js do
let_it_be(:reminder_days) { Gitlab::ManualRenewalBanner::REMINDER_DAYS }
before do
create_current_license(expires_at: expires_at)
allow(Gitlab::CurrentSettings).to receive(:should_check_namespace_plan?) { should_check_namespace_plan? }
visit(send(path_to_visit))
end
context 'when on Gitlab.com' do
let(:expires_at) { 1.month.from_now.to_date }
let(:should_check_namespace_plan?) { true }
it_behaves_like 'a hidden manual renewal banner'
end
context 'when on self-managed' do
let(:should_check_namespace_plan?) { false }
context 'when subscription is expiring' do
context 'within notification window' do
let(:expires_at) { Date.today + reminder_days }
it_behaves_like 'a visible dismissible manual renewal banner'
end
context 'outside of notification window' do
let(:expires_at) { Date.tomorrow + reminder_days }
it_behaves_like 'a hidden manual renewal banner'
end
end
context 'when subscription is expired' do
let(:expires_at) { Date.today }
it_behaves_like 'a visible dismissible manual renewal banner'
end
context 'when subscription is not expiring/expired yet' do
let(:expires_at) { 1.month.from_now.to_date }
it_behaves_like 'a hidden manual renewal banner'
end
end
end
end
......@@ -33755,6 +33755,12 @@ msgstr ""
msgid "Subscription successfully deleted."
msgstr ""
msgid "SubscriptionBanner|Export license usage file"
msgstr ""
msgid "SubscriptionBanner|Upload new license"
msgstr ""
msgid "SubscriptionTable|Add seats"
msgstr ""
......
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