Commit 06fad53d authored by Jay Swain's avatar Jay Swain

Only display downgraded message if on free plan

We've become aware that sometimes Zuora => Customers => GitLab fall out
of sync. It certain contexts a user will receive a false message stating
their account has been downgraded when in fact we haven't downgraded
them.

This commit ensures that the user is on the Free plan, before displaying
the downgraded message.

part of: https://gitlab.com/gitlab-org/growth/engineering/-/issues/5405
parent 8f2f7442
---
title: Only display downgraded message if on free plan
merge_request: 41213
author:
type: changed
...@@ -39,7 +39,7 @@ module Gitlab ...@@ -39,7 +39,7 @@ module Gitlab
end end
def expired_subject def expired_subject
if subscribable.block_changes? if show_downgrade_messaging?
if auto_renew if auto_renew
_('Something went wrong with your automatic subscription renewal.') _('Something went wrong with your automatic subscription renewal.')
else else
...@@ -63,7 +63,7 @@ module Gitlab ...@@ -63,7 +63,7 @@ module Gitlab
end end
def expired_message 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 } _('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 end
...@@ -71,16 +71,16 @@ module Gitlab ...@@ -71,16 +71,16 @@ module Gitlab
def block_changes_message def block_changes_message
return namespace_block_changes_message if namespace 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 end
def namespace_block_changes_message def namespace_block_changes_message
if auto_renew if auto_renew
support_link = '<a href="mailto:support@gitlab.com">support@gitlab.com</a>'.html_safe 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 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
end end
...@@ -143,6 +143,14 @@ module Gitlab ...@@ -143,6 +143,14 @@ module Gitlab
@plan_name ||= subscribable.plan.titleize @plan_name ||= subscribable.plan.titleize
end end
def plan_downgraded?
plan_name.downcase == ::Plan::FREE
end
def show_downgrade_messaging?
subscribable.block_changes? && (self_managed? || plan_downgraded?)
end
def strong def strong
'<strong>'.html_safe '<strong>'.html_safe
end end
...@@ -186,6 +194,8 @@ module Gitlab ...@@ -186,6 +194,8 @@ module Gitlab
(expires_at_or_cutoff_at - Date.today).to_i (expires_at_or_cutoff_at - Date.today).to_i
end end
days = days < 0 ? 0 : days
pluralize(days, 'day') pluralize(days, 'day')
end end
end end
......
...@@ -40,7 +40,7 @@ RSpec.describe "Admin views license" do ...@@ -40,7 +40,7 @@ RSpec.describe "Admin views license" do
context "when license blocks changes" 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) } 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
end end
......
...@@ -22,6 +22,7 @@ RSpec.describe Gitlab::ExpiringSubscriptionMessage do ...@@ -22,6 +22,7 @@ RSpec.describe Gitlab::ExpiringSubscriptionMessage do
let(:grace_period_effective_from) { expired_date - 35.days } let(:grace_period_effective_from) { expired_date - 35.days }
let(:today) { Time.utc(2020, 3, 7, 10) } let(:today) { Time.utc(2020, 3, 7, 10) }
let(:expired_date) { Time.utc(2020, 3, 9, 10).to_date } let(:expired_date) { Time.utc(2020, 3, 9, 10).to_date }
let(:plan_name) { ::Plan::GOLD }
before do before do
allow_any_instance_of(Gitlab::ExpiringSubscriptionMessage).to receive(:grace_period_effective_from).and_return(grace_period_effective_from) 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 ...@@ -31,7 +32,7 @@ RSpec.describe Gitlab::ExpiringSubscriptionMessage do
let(:auto_renew) { false } let(:auto_renew) { false }
before do 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(:expires_at).and_return(expired_date)
allow(subscribable).to receive(:auto_renew).and_return(auto_renew) allow(subscribable).to receive(:auto_renew).and_return(auto_renew)
end end
...@@ -68,11 +69,23 @@ RSpec.describe Gitlab::ExpiringSubscriptionMessage do ...@@ -68,11 +69,23 @@ RSpec.describe Gitlab::ExpiringSubscriptionMessage do
end end
context 'when it is currently blocking changes' do context 'when it is currently blocking changes' do
let(:plan_name) { ::Plan::FREE }
before do before do
allow(subscribable).to receive(:block_changes?).and_return(true) allow(subscribable).to receive(:block_changes?).and_return(true)
allow(subscribable).to receive(:block_changes_at).and_return(expired_date) allow(subscribable).to receive(:block_changes_at).and_return(expired_date)
end 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 it 'has a nice subject' do
Timecop.freeze(today) do Timecop.freeze(today) do
expect(subject).to include('Your subscription has been downgraded.') expect(subject).to include('Your subscription has been downgraded.')
...@@ -82,7 +95,7 @@ RSpec.describe Gitlab::ExpiringSubscriptionMessage do ...@@ -82,7 +95,7 @@ RSpec.describe Gitlab::ExpiringSubscriptionMessage do
context 'no namespace' do context 'no namespace' do
it 'has an expiration blocking message' do it 'has an expiration blocking message' do
Timecop.freeze(today) 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 end
end end
...@@ -92,7 +105,7 @@ RSpec.describe Gitlab::ExpiringSubscriptionMessage do ...@@ -92,7 +105,7 @@ RSpec.describe Gitlab::ExpiringSubscriptionMessage do
it 'has an expiration blocking message' do it 'has an expiration blocking message' do
Timecop.freeze(today) 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
end end
...@@ -107,7 +120,7 @@ RSpec.describe Gitlab::ExpiringSubscriptionMessage do ...@@ -107,7 +120,7 @@ RSpec.describe Gitlab::ExpiringSubscriptionMessage do
it 'has an expiration blocking message' do it 'has an expiration blocking message' do
Timecop.freeze(today) 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 end
end end
...@@ -115,8 +128,11 @@ RSpec.describe Gitlab::ExpiringSubscriptionMessage do ...@@ -115,8 +128,11 @@ RSpec.describe Gitlab::ExpiringSubscriptionMessage do
end end
context 'when it is not currently blocking changes' do context 'when it is not currently blocking changes' do
let(:plan_name) { ::Plan::GOLD }
before do before do
allow(subscribable).to receive(:block_changes?).and_return(false) allow(subscribable).to receive(:block_changes?).and_return(false)
allow(subscribable).to receive(:block_changes_at).and_return((today + 4.days).to_date)
end end
it 'has a nice subject' do it 'has a nice subject' do
...@@ -132,7 +148,7 @@ RSpec.describe Gitlab::ExpiringSubscriptionMessage do ...@@ -132,7 +148,7 @@ RSpec.describe Gitlab::ExpiringSubscriptionMessage do
allow(subscribable).to receive(:is_a?).with(::License).and_return(true) allow(subscribable).to receive(:is_a?).with(::License).and_return(true)
Timecop.freeze(today) do 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 end
end end
...@@ -155,7 +171,7 @@ RSpec.describe Gitlab::ExpiringSubscriptionMessage do ...@@ -155,7 +171,7 @@ RSpec.describe Gitlab::ExpiringSubscriptionMessage do
context 'without namespace' do context 'without namespace' do
it 'has an expiration blocking message' do it 'has an expiration blocking message' do
Timecop.freeze(today) 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 end
end end
...@@ -215,6 +231,7 @@ RSpec.describe Gitlab::ExpiringSubscriptionMessage do ...@@ -215,6 +231,7 @@ RSpec.describe Gitlab::ExpiringSubscriptionMessage do
allow(subscribable).to receive(:expired?).and_return(true) allow(subscribable).to receive(:expired?).and_return(true)
allow(subscribable).to receive(:will_block_changes?).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(:block_changes?).and_return(true)
allow(subscribable).to receive(:plan).and_return('free')
end end
context 'and is past the cutoff date' do context 'and is past the cutoff date' do
......
...@@ -27697,7 +27697,7 @@ msgstr "" ...@@ -27697,7 +27697,7 @@ msgstr ""
msgid "We sent you an email with reset password instructions" msgid "We sent you an email with reset password instructions"
msgstr "" 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 "" msgstr ""
msgid "We want to be sure it is you, please confirm you are not a robot." msgid "We want to be sure it is you, please confirm you are not a robot."
...@@ -28305,10 +28305,10 @@ msgstr "" ...@@ -28305,10 +28305,10 @@ msgstr ""
msgid "You could not create a new trigger." msgid "You could not create a new trigger."
msgstr "" 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 "" 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 "" msgstr ""
msgid "You do not have an active license" 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