Commit 34cae340 authored by Michael Kozono's avatar Michael Kozono

Merge branch 'ag-block-non-get-http-in-read-only-mode' into 'master'

Maintenance mode displays a banner message

See merge request gitlab-org/gitlab!44773
parents 1d66df80 d798a739
...@@ -34,7 +34,9 @@ export default { ...@@ -34,7 +34,9 @@ export default {
<gl-form-textarea <gl-form-textarea
id="maintenanceBannerMessage" id="maintenanceBannerMessage"
v-model="bannerMessage" v-model="bannerMessage"
:placeholder="__(`GitLab is undergoing maintenance and is operating in a read-only mode.`)" :placeholder="
__('This GitLab instance is undergoing maintenance and is operating in read-only mode.')
"
/> />
</gl-form-group> </gl-form-group>
<div class="mt-4"> <div class="mt-4">
......
...@@ -11,10 +11,26 @@ module EE ...@@ -11,10 +11,26 @@ module EE
override :read_only_message override :read_only_message
def read_only_message def read_only_message
return _('You are on a read-only GitLab instance.') if maintenance_mode? message = ::Gitlab::Geo.secondary? ? geo_secondary_read_only_message : super
return super unless ::Gitlab::Geo.secondary? return message unless maintenance_mode?
return maintenance_mode_message.concat(message) if message
maintenance_mode_message
end
def maintenance_mode_message
html = tag.div do
tag.p(class: 'gl-mb-3') do
concat(sprite_icon('information-o', css_class: 'gl-icon gl-mr-3'))
concat(custom_maintenance_mode_message)
end
end
html
end
def geo_secondary_read_only_message
message = @limited_actions_message ? s_('Geo|You may be able to make a limited amount of changes or perform a limited amount of actions on this page.') : s_('Geo|If you want to make changes, you must visit the primary site.') message = @limited_actions_message ? s_('Geo|You may be able to make a limited amount of changes or perform a limited amount of actions on this page.') : s_('Geo|If you want to make changes, you must visit the primary site.')
message = "#{message} #{lag_message}".html_safe if lag_message message = "#{message} #{lag_message}".html_safe if lag_message
...@@ -114,6 +130,11 @@ module EE ...@@ -114,6 +130,11 @@ module EE
private private
def custom_maintenance_mode_message
::Gitlab::CurrentSettings.maintenance_mode_message&.html_safe ||
s_('This GitLab instance is undergoing maintenance and is operating in read-only mode.')
end
def appearance def appearance
::Appearance.current ::Appearance.current
end end
......
...@@ -26,6 +26,6 @@ RSpec.describe 'Geo read-only message', :geo do ...@@ -26,6 +26,6 @@ RSpec.describe 'Geo read-only message', :geo do
stub_application_setting(maintenance_mode: true) stub_application_setting(maintenance_mode: true)
end end
it_behaves_like 'Read-only instance', /You are on a read\-only GitLab instance./ it_behaves_like 'Read-only instance', /This GitLab instance is undergoing maintenance and is operating in read\-only mode./
end end
end end
...@@ -6,6 +6,8 @@ RSpec.describe ApplicationHelper do ...@@ -6,6 +6,8 @@ RSpec.describe ApplicationHelper do
include EE::GeoHelpers include EE::GeoHelpers
describe '#read_only_message', :geo do describe '#read_only_message', :geo do
let(:default_maintenance_mode_message) { 'This GitLab instance is undergoing maintenance and is operating in read-only mode.' }
context 'when not in a Geo secondary' do context 'when not in a Geo secondary' do
it 'returns a fallback message if database is readonly' do it 'returns a fallback message if database is readonly' do
expect(Gitlab::Database).to receive(:read_only?) { true } expect(Gitlab::Database).to receive(:read_only?) { true }
...@@ -16,6 +18,54 @@ RSpec.describe ApplicationHelper do ...@@ -16,6 +18,54 @@ RSpec.describe ApplicationHelper do
it 'returns nil when database is not read_only' do it 'returns nil when database is not read_only' do
expect(helper.read_only_message).to be_nil expect(helper.read_only_message).to be_nil
end end
context 'maintenance mode' do
context 'enabled' do
before do
stub_application_setting(maintenance_mode: true)
end
it 'returns default message' do
expect(helper.read_only_message).to match(default_maintenance_mode_message)
end
it 'returns user set custom maintenance mode message' do
custom_message = 'Maintenance window ends at 00:00.'
stub_application_setting(maintenance_mode_message: custom_message)
expect(helper.read_only_message).to match(/#{custom_message}/)
end
context 'when database is read-only' do
it 'stacks read-only and maintenance mode messages' do
expect(Gitlab::Database).to receive(:read_only?).twice { true }
expect(helper.read_only_message).to match('You are on a read-only GitLab instance')
expect(helper.read_only_message).to match(/#{default_maintenance_mode_message}/)
end
end
end
context 'disabled' do
it 'returns nil' do
stub_application_setting(maintenance_mode: false)
expect(helper.read_only_message).to be_nil
end
end
end
end
context 'on a geo secondary' do
context 'maintenance mode on' do
it 'returns messages for both' do
expect(Gitlab::Geo).to receive(:secondary?).twice { true }
stub_application_setting(maintenance_mode: true)
expect(helper.read_only_message).to match(/you must visit the primary site/)
expect(helper.read_only_message).to match(/#{default_maintenance_mode_message}/)
end
end
end end
context 'when in a Geo Secondary' do context 'when in a Geo Secondary' do
......
...@@ -12836,9 +12836,6 @@ msgstr "" ...@@ -12836,9 +12836,6 @@ msgstr ""
msgid "GitLab is obtaining a Let's Encrypt SSL certificate for this domain. This process can take some time. Please try again later." msgid "GitLab is obtaining a Let's Encrypt SSL certificate for this domain. This process can take some time. Please try again later."
msgstr "" msgstr ""
msgid "GitLab is undergoing maintenance and is operating in a read-only mode."
msgstr ""
msgid "GitLab member or Email address" msgid "GitLab member or Email address"
msgstr "" msgstr ""
...@@ -27804,6 +27801,9 @@ msgstr "" ...@@ -27804,6 +27801,9 @@ msgstr ""
msgid "This GitLab instance is licensed at the %{insufficient_license} tier. Geo is only available for users who have at least a Premium license." msgid "This GitLab instance is licensed at the %{insufficient_license} tier. Geo is only available for users who have at least a Premium license."
msgstr "" msgstr ""
msgid "This GitLab instance is undergoing maintenance and is operating in read-only mode."
msgstr ""
msgid "This Project is currently archived and read-only. Please unarchive the project first if you want to resume Pull mirroring" msgid "This Project is currently archived and read-only. Please unarchive the project first if you want to resume Pull mirroring"
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