Commit d798a739 authored by Aakriti Gupta's avatar Aakriti Gupta

Display read-only mode message when in maintenance

parent 0e357760
......@@ -34,7 +34,9 @@ export default {
<gl-form-textarea
id="maintenanceBannerMessage"
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>
<div class="mt-4">
......
......@@ -11,10 +11,26 @@ module EE
override :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 = "#{message} #{lag_message}".html_safe if lag_message
......@@ -114,6 +130,11 @@ module EE
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
::Appearance.current
end
......
......@@ -26,6 +26,6 @@ RSpec.describe 'Geo read-only message', :geo do
stub_application_setting(maintenance_mode: true)
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
......@@ -6,6 +6,8 @@ RSpec.describe ApplicationHelper do
include EE::GeoHelpers
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
it 'returns a fallback message if database is readonly' do
expect(Gitlab::Database).to receive(:read_only?) { true }
......@@ -16,6 +18,54 @@ RSpec.describe ApplicationHelper do
it 'returns nil when database is not read_only' do
expect(helper.read_only_message).to be_nil
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
context 'when in a Geo Secondary' do
......
......@@ -12802,9 +12802,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."
msgstr ""
msgid "GitLab is undergoing maintenance and is operating in a read-only mode."
msgstr ""
msgid "GitLab member or Email address"
msgstr ""
......@@ -27710,6 +27707,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."
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"
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