Commit d55e8d21 authored by Stan Hu's avatar Stan Hu

Merge branch 'jswain_expiring_subscription_downgrade' into 'master'

Only display downgraded message if on free plan

See merge request gitlab-org/gitlab!41213
parents 2fdadb11 06fad53d
---
title: Only display downgraded message if on free plan
merge_request: 41213
author:
type: changed
......@@ -39,7 +39,7 @@ module Gitlab
end
def expired_subject
if subscribable.block_changes?
if show_downgrade_messaging?
if auto_renew
_('Something went wrong with your automatic subscription renewal.')
else
......@@ -63,7 +63,7 @@ module Gitlab
end
def expired_message
return block_changes_message if subscribable.block_changes?
return block_changes_message if show_downgrade_messaging?
_('No worries, you can still use all the %{strong}%{plan_name}%{strong_close} features for now. You have %{remaining_days} to renew your subscription.') % { plan_name: plan_name, remaining_days: remaining_days_formatted, strong: strong, strong_close: strong_close }
end
......@@ -71,16 +71,16 @@ module Gitlab
def block_changes_message
return namespace_block_changes_message if namespace
_('You didn\'t renew your %{strong}%{plan_name}%{strong_close} subscription so it was downgraded to the GitLab Core Plan.') % { plan_name: plan_name, strong: strong, strong_close: strong_close }
_('You didn\'t renew your subscription so it was downgraded to the GitLab Core Plan.')
end
def namespace_block_changes_message
if auto_renew
support_link = '<a href="mailto:support@gitlab.com">support@gitlab.com</a>'.html_safe
_('We tried to automatically renew your %{strong}%{plan_name}%{strong_close} subscription for %{strong}%{namespace_name}%{strong_close} on %{expires_on} but something went wrong so your subscription was downgraded to the free plan. Don\'t worry, your data is safe. We suggest you check your payment method and get in touch with our support team (%{support_link}). They\'ll gladly help with your subscription renewal.') % { plan_name: plan_name, strong: strong, strong_close: strong_close, namespace_name: namespace.name, support_link: support_link, expires_on: expires_at_or_cutoff_at.strftime("%Y-%m-%d") }
_('We tried to automatically renew your subscription for %{strong}%{namespace_name}%{strong_close} on %{expires_on} but something went wrong so your subscription was downgraded to the free plan. Don\'t worry, your data is safe. We suggest you check your payment method and get in touch with our support team (%{support_link}). They\'ll gladly help with your subscription renewal.') % { strong: strong, strong_close: strong_close, namespace_name: namespace.name, support_link: support_link, expires_on: expires_at_or_cutoff_at.strftime("%Y-%m-%d") }
else
_('You didn\'t renew your %{strong}%{plan_name}%{strong_close} subscription for %{strong}%{namespace_name}%{strong_close} so it was downgraded to the free plan.') % { plan_name: plan_name, strong: strong, strong_close: strong_close, namespace_name: namespace.name }
_('You didn\'t renew your subscription for %{strong}%{namespace_name}%{strong_close} so it was downgraded to the free plan.') % { strong: strong, strong_close: strong_close, namespace_name: namespace.name }
end
end
......@@ -143,6 +143,14 @@ module Gitlab
@plan_name ||= subscribable.plan.titleize
end
def plan_downgraded?
plan_name.downcase == ::Plan::FREE
end
def show_downgrade_messaging?
subscribable.block_changes? && (self_managed? || plan_downgraded?)
end
def strong
'<strong>'.html_safe
end
......@@ -186,6 +194,8 @@ module Gitlab
(expires_at_or_cutoff_at - Date.today).to_i
end
days = days < 0 ? 0 : days
pluralize(days, 'day')
end
end
......
......@@ -40,7 +40,7 @@ RSpec.describe "Admin views license" do
context "when license blocks changes" do
let_it_be(:license) { build(:license, data: build(:gitlab_license, expires_at: Date.yesterday, block_changes_at: Date.today).export).save!(validate: false) }
it { expect(page).to have_content "You didn't renew your Starter subscription so it was downgraded to the GitLab Core Plan" }
it { expect(page).to have_content "You didn't renew your subscription so it was downgraded to the GitLab Core Plan" }
end
end
......
......@@ -22,6 +22,7 @@ RSpec.describe Gitlab::ExpiringSubscriptionMessage do
let(:grace_period_effective_from) { expired_date - 35.days }
let(:today) { Time.utc(2020, 3, 7, 10) }
let(:expired_date) { Time.utc(2020, 3, 9, 10).to_date }
let(:plan_name) { ::Plan::GOLD }
before do
allow_any_instance_of(Gitlab::ExpiringSubscriptionMessage).to receive(:grace_period_effective_from).and_return(grace_period_effective_from)
......@@ -31,7 +32,7 @@ RSpec.describe Gitlab::ExpiringSubscriptionMessage do
let(:auto_renew) { false }
before do
allow(subscribable).to receive(:plan).and_return('ultimate')
allow(subscribable).to receive(:plan).and_return(plan_name)
allow(subscribable).to receive(:expires_at).and_return(expired_date)
allow(subscribable).to receive(:auto_renew).and_return(auto_renew)
end
......@@ -68,11 +69,23 @@ RSpec.describe Gitlab::ExpiringSubscriptionMessage do
end
context 'when it is currently blocking changes' do
let(:plan_name) { ::Plan::FREE }
before do
allow(subscribable).to receive(:block_changes?).and_return(true)
allow(subscribable).to receive(:block_changes_at).and_return(expired_date)
end
context "when the subscription hasn't been properly downgraded yet" do
let(:plan_name) { ::Plan::SILVER }
it "shows the expiring message" do
Timecop.freeze(today) do
expect(subject).to include('Your subscription expired! No worries, you can still use all the Silver features for now. You have 0 days to renew your subscription.')
end
end
end
it 'has a nice subject' do
Timecop.freeze(today) do
expect(subject).to include('Your subscription has been downgraded.')
......@@ -82,7 +95,7 @@ RSpec.describe Gitlab::ExpiringSubscriptionMessage do
context 'no namespace' do
it 'has an expiration blocking message' do
Timecop.freeze(today) do
expect(subject).to include("You didn't renew your Ultimate subscription so it was downgraded to the GitLab Core Plan")
expect(subject).to include("You didn't renew your subscription so it was downgraded to the GitLab Core Plan")
end
end
end
......@@ -92,7 +105,7 @@ RSpec.describe Gitlab::ExpiringSubscriptionMessage do
it 'has an expiration blocking message' do
Timecop.freeze(today) do
expect(subject).to include("You didn't renew your Ultimate subscription for No Limit Records so it was downgraded to the free plan")
expect(subject).to include("You didn't renew your subscription for No Limit Records so it was downgraded to the free plan")
end
end
......@@ -107,7 +120,7 @@ RSpec.describe Gitlab::ExpiringSubscriptionMessage do
it 'has an expiration blocking message' do
Timecop.freeze(today) do
expect(subject).to include("We tried to automatically renew your Ultimate subscription for No Limit Records on 2020-03-01 but something went wrong so your subscription was downgraded to the free plan. Don't worry, your data is safe. We suggest you check your payment method and get in touch with our support team (support@gitlab.com). They'll gladly help with your subscription renewal.")
expect(subject).to include("We tried to automatically renew your subscription for No Limit Records on 2020-03-01 but something went wrong so your subscription was downgraded to the free plan. Don't worry, your data is safe. We suggest you check your payment method and get in touch with our support team (support@gitlab.com). They'll gladly help with your subscription renewal.")
end
end
end
......@@ -115,8 +128,11 @@ RSpec.describe Gitlab::ExpiringSubscriptionMessage do
end
context 'when it is not currently blocking changes' do
let(:plan_name) { ::Plan::GOLD }
before do
allow(subscribable).to receive(:block_changes?).and_return(false)
allow(subscribable).to receive(:block_changes_at).and_return((today + 4.days).to_date)
end
it 'has a nice subject' do
......@@ -132,7 +148,7 @@ RSpec.describe Gitlab::ExpiringSubscriptionMessage do
allow(subscribable).to receive(:is_a?).with(::License).and_return(true)
Timecop.freeze(today) do
expect(subject).to include('No worries, you can still use all the Ultimate features for now. You have 2 days to renew your subscription.')
expect(subject).to include('No worries, you can still use all the Gold features for now. You have 2 days to renew your subscription.')
end
end
end
......@@ -155,7 +171,7 @@ RSpec.describe Gitlab::ExpiringSubscriptionMessage do
context 'without namespace' do
it 'has an expiration blocking message' do
Timecop.freeze(today) do
expect(subject).to include('Your Ultimate subscription will expire on 2020-03-09. After that, you will not to be able to create issues or merge requests as well as many other features.')
expect(subject).to include('Your Gold subscription will expire on 2020-03-09. After that, you will not to be able to create issues or merge requests as well as many other features.')
end
end
end
......@@ -215,6 +231,7 @@ RSpec.describe Gitlab::ExpiringSubscriptionMessage do
allow(subscribable).to receive(:expired?).and_return(true)
allow(subscribable).to receive(:will_block_changes?).and_return(true)
allow(subscribable).to receive(:block_changes?).and_return(true)
allow(subscribable).to receive(:plan).and_return('free')
end
context 'and is past the cutoff date' do
......
......@@ -27829,7 +27829,7 @@ msgstr ""
msgid "We sent you an email with reset password instructions"
msgstr ""
msgid "We tried to automatically renew your %{strong}%{plan_name}%{strong_close} subscription for %{strong}%{namespace_name}%{strong_close} on %{expires_on} but something went wrong so your subscription was downgraded to the free plan. Don't worry, your data is safe. We suggest you check your payment method and get in touch with our support team (%{support_link}). They'll gladly help with your subscription renewal."
msgid "We tried to automatically renew your subscription for %{strong}%{namespace_name}%{strong_close} on %{expires_on} but something went wrong so your subscription was downgraded to the free plan. Don't worry, your data is safe. We suggest you check your payment method and get in touch with our support team (%{support_link}). They'll gladly help with your subscription renewal."
msgstr ""
msgid "We want to be sure it is you, please confirm you are not a robot."
......@@ -28512,10 +28512,10 @@ msgstr ""
msgid "You could not create a new trigger."
msgstr ""
msgid "You didn't renew your %{strong}%{plan_name}%{strong_close} subscription for %{strong}%{namespace_name}%{strong_close} so it was downgraded to the free plan."
msgid "You didn't renew your subscription for %{strong}%{namespace_name}%{strong_close} so it was downgraded to the free plan."
msgstr ""
msgid "You didn't renew your %{strong}%{plan_name}%{strong_close} subscription so it was downgraded to the GitLab Core Plan."
msgid "You didn't renew your subscription so it was downgraded to the GitLab Core Plan."
msgstr ""
msgid "You do not have an active license"
......
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