Commit 1e7a2d16 authored by Kamil Trzciński's avatar Kamil Trzciński

Merge branch 'dz/330988-cleanup-cutoff-logic-for-grace-period' into 'master'

Remove cutoff logic for expiration message

See merge request gitlab-org/gitlab!70584
parents 111ae4c1 6ff13cf0
...@@ -32,7 +32,7 @@ module Gitlab ...@@ -32,7 +32,7 @@ module Gitlab
private private
def license_message_subject def license_message_subject
message = expired_but_within_cutoff? ? expired_subject : expiring_subject message = subscribable.expired? ? expired_subject : expiring_subject
message = content_tag(:strong, message) message = content_tag(:strong, message)
...@@ -58,7 +58,7 @@ module Gitlab ...@@ -58,7 +58,7 @@ module Gitlab
def expiration_blocking_message def expiration_blocking_message
return '' unless subscribable.will_block_changes? return '' unless subscribable.will_block_changes?
message = expired_but_within_cutoff? ? expired_message : expiring_message message = subscribable.expired? ? expired_message : expiring_message
content_tag(:p, message.html_safe) content_tag(:p, message.html_safe)
end end
...@@ -83,7 +83,7 @@ module Gitlab ...@@ -83,7 +83,7 @@ module Gitlab
if auto_renew if auto_renew
support_link = '<a href="https://support.gitlab.com">support.gitlab.com</a>'.html_safe support_link = '<a href="https://support.gitlab.com">support.gitlab.com</a>'.html_safe
_('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") } _('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: subscribable.expires_at.strftime("%Y-%m-%d") }
else else
pricing_url = 'https://about.gitlab.com/pricing/' pricing_url = 'https://about.gitlab.com/pricing/'
pricing_link_start = '<a href="%{url}">'.html_safe % { url: pricing_url } pricing_link_start = '<a href="%{url}">'.html_safe % { url: pricing_url }
...@@ -96,13 +96,13 @@ module Gitlab ...@@ -96,13 +96,13 @@ module Gitlab
def expiring_message def expiring_message
return namespace_expiring_message if namespace return namespace_expiring_message if namespace
_('Your %{strong}%{plan_name}%{strong_close} subscription expires on %{strong}%{expires_on}%{strong_close}. After that date, you cannot create issues or merge requests, or use many other features.') % { expires_on: expires_at_or_cutoff_at.strftime("%Y-%m-%d"), plan_name: plan_name, strong: strong, strong_close: strong_close } _('Your %{strong}%{plan_name}%{strong_close} subscription expires on %{strong}%{expires_on}%{strong_close}. After that date, you cannot create issues or merge requests, or use many other features.') % { expires_on: subscribable.expires_at.strftime("%Y-%m-%d"), plan_name: plan_name, strong: strong, strong_close: strong_close }
end end
def namespace_expiring_message def namespace_expiring_message
message = [] message = []
message << _('Your %{strong}%{plan_name}%{strong_close} subscription for %{strong}%{namespace_name}%{strong_close} will expire on %{strong}%{expires_on}%{strong_close}.') % { expires_on: expires_at_or_cutoff_at.strftime("%Y-%m-%d"), plan_name: plan_name, strong: strong, strong_close: strong_close, namespace_name: namespace.name } message << _('Your %{strong}%{plan_name}%{strong_close} subscription for %{strong}%{namespace_name}%{strong_close} will expire on %{strong}%{expires_on}%{strong_close}.') % { expires_on: subscribable.expires_at.strftime("%Y-%m-%d"), plan_name: plan_name, strong: strong, strong_close: strong_close, namespace_name: namespace.name }
message << expiring_features_message message << expiring_features_message
...@@ -146,13 +146,13 @@ module Gitlab ...@@ -146,13 +146,13 @@ module Gitlab
end end
def expiring_auto_renew? def expiring_auto_renew?
!!auto_renew && !expired_but_within_cutoff? !!auto_renew && !subscribable.expired?
end end
def expired_subscribable_within_notification_window? def expired_subscribable_within_notification_window?
return true unless expired_but_within_cutoff? return true unless subscribable.expired?
(expires_at_or_cutoff_at + GRACE_PERIOD_EXTENSION_DAYS) > Date.today (subscribable.expires_at + GRACE_PERIOD_EXTENSION_DAYS) > Date.today
end end
def plan_name def plan_name
...@@ -179,39 +179,16 @@ module Gitlab ...@@ -179,39 +179,16 @@ module Gitlab
'</strong>'.html_safe '</strong>'.html_safe
end end
def grace_period_effective_from
Date.parse('2020-07-22')
end
def self_managed? def self_managed?
subscribable.is_a?(::License) subscribable.is_a?(::License)
end end
def expires_at_or_cutoff_at
strong_memoize(:expires_at_or_cutoff_at) do
# self-managed licenses are unconcerned of our announcement.
if self_managed?
subscribable.expires_at
else
cutoff_at = grace_period_effective_from + GRACE_PERIOD_EXTENSION_DAYS
[subscribable.expires_at, cutoff_at].max
end
end
end
def expired_but_within_cutoff?
strong_memoize(:expired) do
subscribable.expired? && expires_at_or_cutoff_at < Date.today
end
end
def remaining_days def remaining_days
strong_memoize(:remaining_days) do strong_memoize(:remaining_days) do
days = if expired_but_within_cutoff? days = if subscribable.expired?
(subscribable.block_changes_at - Date.today).to_i (subscribable.block_changes_at - Date.today).to_i
else else
(expires_at_or_cutoff_at - Date.today).to_i (subscribable.expires_at - Date.today).to_i
end end
days < 0 ? 0 : days days < 0 ? 0 : days
......
...@@ -23,7 +23,6 @@ RSpec.describe Gitlab::ExpiringSubscriptionMessage do ...@@ -23,7 +23,6 @@ RSpec.describe Gitlab::ExpiringSubscriptionMessage do
).message ).message
end end
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 }
...@@ -35,10 +34,6 @@ RSpec.describe Gitlab::ExpiringSubscriptionMessage do ...@@ -35,10 +34,6 @@ RSpec.describe Gitlab::ExpiringSubscriptionMessage do
end end
with_them do with_them do
before do
allow_any_instance_of(Gitlab::ExpiringSubscriptionMessage).to receive(:grace_period_effective_from).and_return(grace_period_effective_from)
end
around do |example| around do |example|
travel_to(today) do travel_to(today) do
example.run example.run
...@@ -300,50 +295,6 @@ RSpec.describe Gitlab::ExpiringSubscriptionMessage do ...@@ -300,50 +295,6 @@ RSpec.describe Gitlab::ExpiringSubscriptionMessage do
end end
end end
end end
context 'subscribable expired a long time ago' do
let(:expired_date) { today.to_date - 1.year }
let(:grace_period_effective_from) { today.to_date - 25.days }
before do
allow(subscribable).to receive(:expires_at).and_return(expired_date)
allow(subscribable).to receive(:block_changes_at).and_return(expired_date)
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
let(:grace_period_effective_from) { today.to_date - 40.days }
it 'has a nice subject' do
expect(subject).to include('Your subscription expired!')
end
end
context 'and is 30 days past the cutoff date' do
let(:grace_period_effective_from) { today.to_date - 60.days }
it 'stops displaying' do
expect(subject).to be nil
end
context 'and force_notification is true' do
let(:force_notification) { true }
it 'returns a message' do
expect(subject).to include('Your subscription expired!')
end
end
end
context 'and not past the cutoff date' do
it 'has a nice subject' do
expect(subject).to include('Your subscription will expire in 5 days')
end
end
end
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