Commit db03a959 authored by Jay Swain's avatar Jay Swain

Don't show subscribable banner to auto_renew:nil

This is a bugfix. While 1576 has already been closed, we were informed
that we were displaying the banner to customers who's subscription was
auto_renew:nil. The problem ended up being that we were coercing the
value from nil to false while doing the check.

I've updated the code to use the attribute directly. I've also updated a
few of the method names to reflect that the value can be nil.

part of: https://gitlab.com/gitlab-org/growth/product/-/issues/1576
parent e0a6caa9
...@@ -494,7 +494,7 @@ class License < ApplicationRecord ...@@ -494,7 +494,7 @@ class License < ApplicationRecord
starts_at > Date.current starts_at > Date.current
end end
def auto_renew? def auto_renew
false false
end end
......
---
title: Only show subscribable banner when auto-renew is set
merge_request: 38962
author:
type: fixed
...@@ -9,6 +9,8 @@ module Gitlab ...@@ -9,6 +9,8 @@ module Gitlab
attr_reader :subscribable, :signed_in, :is_admin, :namespace attr_reader :subscribable, :signed_in, :is_admin, :namespace
delegate :auto_renew, to: :subscribable
def initialize(subscribable:, signed_in:, is_admin:, namespace: nil) def initialize(subscribable:, signed_in:, is_admin:, namespace: nil)
@subscribable = subscribable @subscribable = subscribable
@signed_in = signed_in @signed_in = signed_in
...@@ -38,7 +40,7 @@ module Gitlab ...@@ -38,7 +40,7 @@ module Gitlab
def expired_subject def expired_subject
if subscribable.block_changes? if subscribable.block_changes?
if auto_renew? if auto_renew
_('Something went wrong with your automatic subscription renewal.') _('Something went wrong with your automatic subscription renewal.')
else else
_('Your subscription has been downgraded.') _('Your subscription has been downgraded.')
...@@ -73,7 +75,7 @@ module Gitlab ...@@ -73,7 +75,7 @@ module Gitlab
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 %{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") }
...@@ -124,11 +126,11 @@ module Gitlab ...@@ -124,11 +126,11 @@ module Gitlab
end end
def auto_renew_choice_exists? def auto_renew_choice_exists?
auto_renew? != nil !auto_renew.nil?
end end
def expiring_auto_renew? def expiring_auto_renew?
auto_renew? && !expired_but_within_cutoff? !!auto_renew && !expired_but_within_cutoff?
end end
def expired_subscribable_within_notification_window? def expired_subscribable_within_notification_window?
...@@ -149,10 +151,6 @@ module Gitlab ...@@ -149,10 +151,6 @@ module Gitlab
'</strong>'.html_safe '</strong>'.html_safe
end end
def auto_renew?
subscribable.auto_renew?
end
def grace_period_effective_from def grace_period_effective_from
Date.parse('2020-07-22') Date.parse('2020-07-22')
end end
......
...@@ -33,7 +33,7 @@ RSpec.describe Gitlab::ExpiringSubscriptionMessage do ...@@ -33,7 +33,7 @@ RSpec.describe Gitlab::ExpiringSubscriptionMessage do
before do before do
allow(subscribable).to receive(:plan).and_return('ultimate') allow(subscribable).to receive(:plan).and_return('ultimate')
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
context 'subscribable should not notify admins' do context 'subscribable should not notify admins' do
......
...@@ -964,9 +964,9 @@ RSpec.describe License do ...@@ -964,9 +964,9 @@ RSpec.describe License do
end end
end end
describe '#auto_renew?' do describe '#auto_renew' do
it 'is false' do it 'is false' do
expect(license.auto_renew?).to be false expect(license.auto_renew).to be false
end end
end end
end end
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