Commit b89fb2a8 authored by Mikołaj Wawrzyniak's avatar Mikołaj Wawrzyniak

Merge branch '346260_manual_quarterly_co_term_banner' into 'master'

Add logic for manual quarterly co-term banner

See merge request gitlab-org/gitlab!76255
parents 6a301eed d88e57ba
# frozen_string_literal: true
module Gitlab
class ManualQuarterlyCoTermBanner < Gitlab::ManualBanner
include ::Gitlab::Utils::StrongMemoize
def display_error_version?
actionable.next_reconciliation_date < Date.current
end
private
def require_notification?
return false unless actionable
(actionable.next_reconciliation_date - REMINDER_DAYS) <= Date.current
end
def formatted_date
strong_memoize(:formatted_date) do
actionable.next_reconciliation_date.strftime('%Y-%m-%d')
end
end
def banner_subject
_('A quarterly reconciliation is due on %{date}') % { date: formatted_date }
end
def banner_body
if display_error_version?
_(
'You have more active users than are allowed by your license. GitLab must now reconcile your ' \
'subscription. To complete this process, export your license usage file and email it to ' \
'%{renewal_service_email}. A new license will be emailed to the email address registered in the ' \
'%{customers_dot}. You can upload this license to your instance.'
).html_safe % { renewal_service_email: renewal_service_email, customers_dot: customers_dot_url }
else
_(
'You have more active users than are allowed by your license. Before %{date} GitLab ' \
'must reconcile your subscription. To complete this process, export your license usage file and email ' \
'it to %{renewal_service_email}. A new license will be emailed to the email address registered in ' \
'the %{customers_dot}. You can upload this license to your instance.'
).html_safe % { date: formatted_date, renewal_service_email: renewal_service_email, customers_dot: customers_dot_url }
end
end
end
end
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Gitlab::ManualQuarterlyCoTermBanner do
include ActionView::Helpers::SanitizeHelper
let(:manual_quarterly_co_term_banner) { described_class.new(actionable: upcoming_reconciliation) }
let(:upcoming_reconciliation) do
build(:upcoming_reconciliation, :self_managed, next_reconciliation_date: next_reconciliation_date)
end
let(:next_reconciliation_date) { Date.current + 60.days }
describe '#display?' do
subject(:display?) { manual_quarterly_co_term_banner.display? }
let(:should_check_namespace_plan?) { false }
let(:feature_flag_enabled) { true }
before do
allow(Gitlab::CurrentSettings).to receive(:should_check_namespace_plan?) { should_check_namespace_plan? }
stub_feature_flags(automated_email_provision: feature_flag_enabled)
end
context 'when on GitLab.com' do
let(:should_check_namespace_plan?) { true }
it { is_expected.to eq(false) }
end
context 'when feature flag :automated_email_provision is disabled' do
let(:feature_flag_enabled) { false }
it { is_expected.to eq(false) }
end
context 'when upcoming reconciliation is nil' do
let(:upcoming_reconciliation) { nil }
it { is_expected.to eq(false) }
end
context 'when expiration date is not within the notification window' do
let(:next_reconciliation_date) { Date.tomorrow + described_class::REMINDER_DAYS }
it { is_expected.to eq(false) }
end
context 'when reconciliation date is within the notification window' do
context 'when notification window starts today' do
let(:next_reconciliation_date) { Date.today + described_class::REMINDER_DAYS }
it { is_expected.to eq(true) }
end
context 'when notification window is already on going' do
let(:next_reconciliation_date) { Date.yesterday + described_class::REMINDER_DAYS }
it { is_expected.to eq(true) }
end
end
end
describe '#subject' do
subject { manual_quarterly_co_term_banner.subject }
before do
allow(manual_quarterly_co_term_banner).to receive(:display?).and_return(display)
end
context 'when banner should not be displayed' do
let(:display) { false }
it { is_expected.to eq(nil) }
end
context 'when banner should be displayed' do
let(:display) { true }
context 'when reconciliation is upcoming but within the notification window' do
shared_examples 'an upcoming reconciliation' do
it { is_expected.to eq("A quarterly reconciliation is due on #{next_reconciliation_date}") }
end
context 'when notification date is today' do
let(:next_reconciliation_date) { Date.today + described_class::REMINDER_DAYS }
it_behaves_like 'an upcoming reconciliation'
end
context 'when notification date is within the next 14 days' do
let(:next_reconciliation_date) { Date.yesterday + described_class::REMINDER_DAYS }
it_behaves_like 'an upcoming reconciliation'
end
end
context 'when reconciliation is overdue' do
let(:next_reconciliation_date) { Date.today }
it { is_expected.to eq("A quarterly reconciliation is due on #{next_reconciliation_date}") }
end
end
end
describe '#body' do
subject(:body) { strip_tags(manual_quarterly_co_term_banner.body) }
before do
allow(manual_quarterly_co_term_banner).to receive(:display?).and_return(display)
end
context 'when banner should not be displayed' do
let(:display) { false }
it { is_expected.to eq(nil) }
end
context 'when banner should be displayed' do
let(:display) { true }
context 'when reconciliation is upcoming and within the notification window' do
shared_examples 'an upcoming reconciliation' do
it 'returns a message for an upcoming reconciliation' do
expect(body).to eq(
"You have more active users than are allowed by your license. Before #{next_reconciliation_date} " \
"GitLab must reconcile your subscription. To complete this process, export your license usage " \
"file and email it to #{Gitlab::SubscriptionPortal::RENEWAL_SERVICE_EMAIL}. A new license will " \
"be emailed to the email address registered in the Customers Portal. You can upload this license " \
"to your instance."
)
end
end
context 'when notification date is today' do
let(:next_reconciliation_date) { Date.today + described_class::REMINDER_DAYS }
it_behaves_like 'an upcoming reconciliation'
end
context 'when notification date is within the next 14 days' do
let(:next_reconciliation_date) { Date.yesterday + described_class::REMINDER_DAYS }
it_behaves_like 'an upcoming reconciliation'
end
end
context 'when reconciliation is overdue' do
let(:next_reconciliation_date) { Date.yesterday }
it 'returns a message for an overdue reconciliation' do
expect(body).to eq(
"You have more active users than are allowed by your license. GitLab must now reconcile your " \
"subscription. To complete this process, export your license usage file and email it to " \
"#{Gitlab::SubscriptionPortal::RENEWAL_SERVICE_EMAIL}. A new license will be emailed to the " \
"email address registered in the Customers Portal. You can upload this license to your instance."
)
end
end
end
end
describe 'display_error_version?' do
subject(:display_error_version?) { manual_quarterly_co_term_banner.display_error_version? }
context 'when reconciliation is not overdue yet' do
let(:next_reconciliation_date) { Date.today }
it { is_expected.to eq(false) }
end
context 'when reconciliation is overdue' do
let(:next_reconciliation_date) { Date.yesterday }
it { is_expected.to eq(true) }
end
end
end
......@@ -1556,6 +1556,9 @@ msgstr ""
msgid "A project’s repository name defines its URL (the one you use to access the project via a browser) and its place on the file disk where GitLab is installed. %{link_start}Learn more.%{link_end}"
msgstr ""
msgid "A quarterly reconciliation is due on %{date}"
msgstr ""
msgid "A ready-to-go template for use with Android apps"
msgstr ""
......@@ -40287,6 +40290,12 @@ msgstr ""
msgid "You have insufficient permissions to view shifts for this rotation"
msgstr ""
msgid "You have more active users than are allowed by your license. Before %{date} GitLab must reconcile your subscription. To complete this process, export your license usage file and email it to %{renewal_service_email}. A new license will be emailed to the email address registered in the %{customers_dot}. You can upload this license to your instance."
msgstr ""
msgid "You have more active users than are allowed by your license. GitLab must now reconcile your subscription. To complete this process, export your license usage file and email it to %{renewal_service_email}. A new license will be emailed to the email address registered in the %{customers_dot}. You can upload this license to your instance."
msgstr ""
msgid "You have no permissions"
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