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
@project&.namespace || @group
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(
subscribable: license,
signed_in: signed_in,
is_admin: is_admin
is_admin: is_admin,
force_notification: force_notification
).message
end
......
......@@ -157,7 +157,7 @@ module EE
def check_if_license_blocks_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)
end
end
......
......@@ -7,15 +7,16 @@ module Gitlab
include Gitlab::Utils::StrongMemoize
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
def initialize(subscribable:, signed_in:, is_admin:, namespace: nil)
def initialize(subscribable:, signed_in:, is_admin:, namespace: nil, force_notification: false)
@subscribable = subscribable
@signed_in = signed_in
@is_admin = is_admin
@namespace = namespace
@force_notification = force_notification
end
def message
......@@ -39,7 +40,7 @@ module Gitlab
end
def expired_subject
if show_downgrade_messaging?
if show_downgrade_messaging? && namespace
if auto_renew
_('Something went wrong with your automatic subscription renewal.')
else
......@@ -71,7 +72,7 @@ module Gitlab
def block_changes_message
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
def namespace_block_changes_message
......@@ -127,6 +128,7 @@ module Gitlab
def require_notification?
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?
end
......@@ -154,7 +156,11 @@ module Gitlab
end
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
def strong
......
......@@ -48,7 +48,7 @@ RSpec.describe "Admin views license" do
travel_to(reference_date) do
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"
end
end
......@@ -61,7 +61,7 @@ RSpec.describe "Admin views license" do
travel_to(reference_date) do
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"
end
end
......
......@@ -188,7 +188,8 @@ RSpec.describe EE::SubscribableBannerHelper do
expect(Gitlab::ExpiringSubscriptionMessage).to receive(:new).with(
subscribable: license,
signed_in: true,
is_admin: false
is_admin: false,
force_notification: false
).and_return(message_mock)
expect(message_mock).to receive(:message)
......
......@@ -12,12 +12,14 @@ RSpec.describe Gitlab::ExpiringSubscriptionMessage do
let(:subscribable) { double(:license) }
let(:namespace) { nil }
let(:force_notification) { false }
let(:message) do
described_class.new(
subscribable: subscribable,
signed_in: true,
is_admin: true,
namespace: namespace
namespace: namespace,
force_notification: force_notification
).message
end
......@@ -100,12 +102,12 @@ RSpec.describe Gitlab::ExpiringSubscriptionMessage do
end
it 'has a nice subject' do
expect(subject).to include('Your subscription has been downgraded.')
expect(subject).to include('Your subscription expired!')
end
context 'no namespace' 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
......@@ -316,7 +318,7 @@ RSpec.describe Gitlab::ExpiringSubscriptionMessage do
let(:grace_period_effective_from) { today.to_date - 40.days }
it 'has a nice subject' do
expect(subject).to include('Your subscription has been downgraded')
expect(subject).to include('Your subscription expired!')
end
end
......@@ -326,6 +328,14 @@ RSpec.describe Gitlab::ExpiringSubscriptionMessage do
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
......
......@@ -24466,6 +24466,9 @@ msgstr ""
msgid "Please create an index before enabling indexing"
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}"
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."
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"
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