Commit d6628cd7 authored by Bob Van Landuyt's avatar Bob Van Landuyt

Merge branch 'sh-fix-issue-217031' into 'master'

Fix errors when pushing with an expired license

Closes #217031

See merge request gitlab-org/gitlab!34458
parents dc7b40af 11c5d33f
---
title: Fix errors when pushing with an expired license
merge_request: 34458
author:
type: fixed
...@@ -5,8 +5,8 @@ module EE ...@@ -5,8 +5,8 @@ module EE
module GitAccess module GitAccess
prepend GeoGitAccess prepend GeoGitAccess
extend ::Gitlab::Utils::Override extend ::Gitlab::Utils::Override
include ActionView::Helpers::SanitizeHelper
include PathLocksHelper include PathLocksHelper
include SubscribableBannerHelper
override :check override :check
def check(cmd, changes) def check(cmd, changes)
...@@ -98,11 +98,15 @@ module EE ...@@ -98,11 +98,15 @@ module EE
def check_if_license_blocks_changes! def check_if_license_blocks_changes!
if ::License.block_changes? if ::License.block_changes?
message = ::LicenseHelper.license_message(signed_in: true, is_admin: (user && user.admin?)) message = license_message(signed_in: true, is_admin: (user && user.admin?))
raise ::Gitlab::GitAccess::ForbiddenError, strip_tags(message) raise ::Gitlab::GitAccess::ForbiddenError, strip_tags(message)
end end
end end
def strip_tags(html)
Rails::Html::FullSanitizer.new.sanitize(html)
end
override :check_size_limit? override :check_size_limit?
def check_size_limit? def check_size_limit?
strong_memoize(:check_size_limit) do strong_memoize(:check_size_limit) do
......
...@@ -36,9 +36,9 @@ module Gitlab ...@@ -36,9 +36,9 @@ 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.')
end end
else else
_('Your subscription expired!') _('Your subscription expired!')
...@@ -49,9 +49,9 @@ module Gitlab ...@@ -49,9 +49,9 @@ module Gitlab
remaining_days = pluralize(subscribable.remaining_days, 'day') remaining_days = pluralize(subscribable.remaining_days, 'day')
if auto_renew? if auto_renew?
_('Your subscription will automatically renew in %{remaining_days}') % { remaining_days: remaining_days } _('Your subscription will automatically renew in %{remaining_days}.') % { remaining_days: remaining_days }
else else
_('Your subscription will expire in %{remaining_days}') % { remaining_days: remaining_days } _('Your subscription will expire in %{remaining_days}.') % { remaining_days: remaining_days }
end end
end end
......
...@@ -67,7 +67,7 @@ RSpec.describe Gitlab::ExpiringSubscriptionMessage do ...@@ -67,7 +67,7 @@ RSpec.describe Gitlab::ExpiringSubscriptionMessage do
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.')
end end
end end
...@@ -187,7 +187,7 @@ RSpec.describe Gitlab::ExpiringSubscriptionMessage do ...@@ -187,7 +187,7 @@ 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 will automatically renew in 4 days') expect(subject).to include('Your subscription will automatically renew in 4 days.')
end end
it 'has an expiration blocking message' do it 'has an expiration blocking message' do
......
...@@ -600,6 +600,18 @@ RSpec.describe Gitlab::GitAccess do ...@@ -600,6 +600,18 @@ RSpec.describe Gitlab::GitAccess do
end end
end end
context "when license blocks changes" do
before do
create_current_license(starts_at: 1.month.ago.to_date, block_changes_at: Date.current, notify_admins_at: Date.current)
user.update_attribute(:admin, true)
project.add_role(user, :developer)
end
it 'raises an error' do
expect { push_changes(changes[:any]) }.to raise_error(Gitlab::GitAccess::ForbiddenError, /Your subscription will expire/)
end
end
context "group-specific access control" do context "group-specific access control" do
let(:user) { create(:user) } let(:user) { create(:user) }
let(:group) { create(:group) } let(:group) { create(:group) }
......
...@@ -20845,7 +20845,7 @@ msgstr "" ...@@ -20845,7 +20845,7 @@ msgstr ""
msgid "Something went wrong while updating your list settings" msgid "Something went wrong while updating your list settings"
msgstr "" msgstr ""
msgid "Something went wrong with your automatic subscription renewal" msgid "Something went wrong with your automatic subscription renewal."
msgstr "" msgstr ""
msgid "Something went wrong, unable to add %{project} to dashboard" msgid "Something went wrong, unable to add %{project} to dashboard"
...@@ -26201,13 +26201,13 @@ msgstr "" ...@@ -26201,13 +26201,13 @@ msgstr ""
msgid "Your subscription expired!" msgid "Your subscription expired!"
msgstr "" msgstr ""
msgid "Your subscription has been downgraded" msgid "Your subscription has been downgraded."
msgstr "" msgstr ""
msgid "Your subscription will automatically renew in %{remaining_days}" msgid "Your subscription will automatically renew in %{remaining_days}."
msgstr "" msgstr ""
msgid "Your subscription will expire in %{remaining_days}" msgid "Your subscription will expire in %{remaining_days}."
msgstr "" msgstr ""
msgid "Zoom meeting added" msgid "Zoom meeting added"
......
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