Commit c1e16db6 authored by Dmitriy Zaporozhets (DZ)'s avatar Dmitriy Zaporozhets (DZ)

Merge branch '235392-when-license-is-expired-git-push-error-is-nil' into 'master'

Add option to force notification on expired subscriptions

See merge request gitlab-org/gitlab!64838
parents a8ef2fdb 5a6b8656
...@@ -37,11 +37,12 @@ module EE ...@@ -37,11 +37,12 @@ module EE
@project&.namespace || @group @project&.namespace || @group
end end
def license_message(signed_in: signed_in?, is_admin: current_user&.admin?, license: License.current) def license_message(signed_in: signed_in?, is_admin: current_user&.admin?, license: License.current, force_notification: false)
::Gitlab::ExpiringSubscriptionMessage.new( ::Gitlab::ExpiringSubscriptionMessage.new(
subscribable: license, subscribable: license,
signed_in: signed_in, signed_in: signed_in,
is_admin: is_admin is_admin: is_admin,
force_notification: force_notification
).message ).message
end end
......
...@@ -157,7 +157,7 @@ module EE ...@@ -157,7 +157,7 @@ module EE
def check_if_license_blocks_changes! def check_if_license_blocks_changes!
if ::License.block_changes? if ::License.block_changes?
message = license_message(signed_in: true, is_admin: (user && user.admin?)) message = license_message(signed_in: true, is_admin: (user && user.admin?), force_notification: true)
raise ::Gitlab::GitAccess::ForbiddenError, strip_tags(message) raise ::Gitlab::GitAccess::ForbiddenError, strip_tags(message)
end end
end end
......
...@@ -7,15 +7,16 @@ module Gitlab ...@@ -7,15 +7,16 @@ module Gitlab
include Gitlab::Utils::StrongMemoize include Gitlab::Utils::StrongMemoize
include ActionView::Helpers::TextHelper include ActionView::Helpers::TextHelper
attr_reader :subscribable, :signed_in, :is_admin, :namespace attr_reader :subscribable, :signed_in, :is_admin, :namespace, :force_notification
delegate :auto_renew, to: :subscribable delegate :auto_renew, to: :subscribable
def initialize(subscribable:, signed_in:, is_admin:, namespace: nil) def initialize(subscribable:, signed_in:, is_admin:, namespace: nil, force_notification: false)
@subscribable = subscribable @subscribable = subscribable
@signed_in = signed_in @signed_in = signed_in
@is_admin = is_admin @is_admin = is_admin
@namespace = namespace @namespace = namespace
@force_notification = force_notification
end end
def message def message
...@@ -39,7 +40,7 @@ module Gitlab ...@@ -39,7 +40,7 @@ module Gitlab
end end
def expired_subject def expired_subject
if show_downgrade_messaging? if show_downgrade_messaging? && namespace
if auto_renew if auto_renew
_('Something went wrong with your automatic subscription renewal.') _('Something went wrong with your automatic subscription renewal.')
else else
...@@ -71,7 +72,7 @@ module Gitlab ...@@ -71,7 +72,7 @@ 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 subscription so it was downgraded to the GitLab Core Plan.') _('Please delete your current license if you want to downgrade to the free plan.')
end end
def namespace_block_changes_message def namespace_block_changes_message
...@@ -127,6 +128,7 @@ module Gitlab ...@@ -127,6 +128,7 @@ module Gitlab
def require_notification? def require_notification?
return false if expiring_auto_renew? || ::License.future_dated.present? return false if expiring_auto_renew? || ::License.future_dated.present?
return true if force_notification && subscribable.block_changes?
auto_renew_choice_exists? && expired_subscribable_within_notification_window? && !subscription_future_renewal? auto_renew_choice_exists? && expired_subscribable_within_notification_window? && !subscription_future_renewal?
end end
...@@ -154,7 +156,11 @@ module Gitlab ...@@ -154,7 +156,11 @@ module Gitlab
end end
def show_downgrade_messaging? def show_downgrade_messaging?
subscribable.block_changes? && (self_managed? || plan_downgraded?) if self_managed?
subscribable.block_changes?
else
subscribable.block_changes? && plan_downgraded?
end
end end
def strong def strong
......
...@@ -48,7 +48,7 @@ RSpec.describe "Admin views license" do ...@@ -48,7 +48,7 @@ RSpec.describe "Admin views license" do
travel_to(reference_date) do travel_to(reference_date) do
visit(admin_license_path) visit(admin_license_path)
expect(page).to have_content "You have 7 days to renew your subscription." expect(page).to have_content 'You have 7 days to renew your subscription.'
expect(page).to have_link 'Renew subscription', href: "#{EE::SUBSCRIPTIONS_URL}/subscriptions" expect(page).to have_link 'Renew subscription', href: "#{EE::SUBSCRIPTIONS_URL}/subscriptions"
end end
end end
...@@ -61,7 +61,7 @@ RSpec.describe "Admin views license" do ...@@ -61,7 +61,7 @@ RSpec.describe "Admin views license" do
travel_to(reference_date) do travel_to(reference_date) do
visit(admin_license_path) visit(admin_license_path)
expect(page).to have_content "You didn't renew your subscription so it was downgraded to the GitLab Core Plan" expect(page).to have_content 'Please delete your current license if you want to downgrade to the free plan'
expect(page).to have_link 'Upgrade your plan', href: "#{EE::SUBSCRIPTIONS_URL}/subscriptions" expect(page).to have_link 'Upgrade your plan', href: "#{EE::SUBSCRIPTIONS_URL}/subscriptions"
end end
end end
......
...@@ -188,7 +188,8 @@ RSpec.describe EE::SubscribableBannerHelper do ...@@ -188,7 +188,8 @@ RSpec.describe EE::SubscribableBannerHelper do
expect(Gitlab::ExpiringSubscriptionMessage).to receive(:new).with( expect(Gitlab::ExpiringSubscriptionMessage).to receive(:new).with(
subscribable: license, subscribable: license,
signed_in: true, signed_in: true,
is_admin: false is_admin: false,
force_notification: false
).and_return(message_mock) ).and_return(message_mock)
expect(message_mock).to receive(:message) expect(message_mock).to receive(:message)
......
...@@ -12,12 +12,14 @@ RSpec.describe Gitlab::ExpiringSubscriptionMessage do ...@@ -12,12 +12,14 @@ RSpec.describe Gitlab::ExpiringSubscriptionMessage do
let(:subscribable) { double(:license) } let(:subscribable) { double(:license) }
let(:namespace) { nil } let(:namespace) { nil }
let(:force_notification) { false }
let(:message) do let(:message) do
described_class.new( described_class.new(
subscribable: subscribable, subscribable: subscribable,
signed_in: true, signed_in: true,
is_admin: true, is_admin: true,
namespace: namespace namespace: namespace,
force_notification: force_notification
).message ).message
end end
...@@ -100,12 +102,12 @@ RSpec.describe Gitlab::ExpiringSubscriptionMessage do ...@@ -100,12 +102,12 @@ RSpec.describe Gitlab::ExpiringSubscriptionMessage do
end end
it 'has a nice subject' do it 'has a nice subject' do
expect(subject).to include('Your subscription has been downgraded.') expect(subject).to include('Your subscription expired!')
end end
context 'no namespace' do context 'no namespace' do
it 'has an expiration blocking message' do it 'has an expiration blocking message' do
expect(subject).to include("You didn't renew your subscription so it was downgraded to the GitLab Core Plan") expect(subject).to include('Please delete your current license if you want to downgrade to the free plan')
end end
end end
...@@ -316,7 +318,7 @@ RSpec.describe Gitlab::ExpiringSubscriptionMessage do ...@@ -316,7 +318,7 @@ RSpec.describe Gitlab::ExpiringSubscriptionMessage do
let(:grace_period_effective_from) { today.to_date - 40.days } let(:grace_period_effective_from) { today.to_date - 40.days }
it 'has a nice subject' do it 'has a nice subject' do
expect(subject).to include('Your subscription has been downgraded') expect(subject).to include('Your subscription expired!')
end end
end end
...@@ -326,6 +328,14 @@ RSpec.describe Gitlab::ExpiringSubscriptionMessage do ...@@ -326,6 +328,14 @@ RSpec.describe Gitlab::ExpiringSubscriptionMessage do
it 'stops displaying' do it 'stops displaying' do
expect(subject).to be nil expect(subject).to be nil
end 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 end
context 'and not past the cutoff date' do context 'and not past the cutoff date' do
......
...@@ -24466,6 +24466,9 @@ msgstr "" ...@@ -24466,6 +24466,9 @@ msgstr ""
msgid "Please create an index before enabling indexing" msgid "Please create an index before enabling indexing"
msgstr "" msgstr ""
msgid "Please delete your current license if you want to downgrade to the free plan."
msgstr ""
msgid "Please enable and migrate to hashed storage to avoid security issues and ensure data integrity. %{migrate_link}" msgid "Please enable and migrate to hashed storage to avoid security issues and ensure data integrity. %{migrate_link}"
msgstr "" msgstr ""
...@@ -37424,9 +37427,6 @@ msgstr "" ...@@ -37424,9 +37427,6 @@ msgstr ""
msgid "You didn't renew your 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 subscription so it was downgraded to the GitLab Core Plan."
msgstr ""
msgid "You do not have an active license" msgid "You do not have an active license"
msgstr "" 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