Commit 67e0c38c authored by Aakriti Gupta's avatar Aakriti Gupta

Re-factor check for maintenance mode

parent c69f85f2
......@@ -13,7 +13,7 @@ module EE
def read_only_message
message = ::Gitlab::Geo.secondary? ? geo_secondary_read_only_message : super
return message unless maintenance_mode?
return message unless ::Gitlab.maintenance_mode?
return maintenance_mode_message.concat(message) if message
maintenance_mode_message
......@@ -156,11 +156,5 @@ module EE
next_unprocessed_event.created_at < EVENT_LAG_SHOW_THRESHOLD.ago
end
end
def maintenance_mode?
return unless ::Feature.enabled?(:maintenance_mode)
::Gitlab::CurrentSettings.maintenance_mode
end
end
end
......@@ -96,15 +96,11 @@ module EE
def check_maintenance_mode!(cmd)
return unless cmd == 'git-receive-pack'
return unless maintenance_mode?
return unless ::Gitlab.maintenance_mode?
raise ::Gitlab::GitAccess::ForbiddenError, 'Git push is not allowed because this GitLab instance is currently in (read-only) maintenance mode.'
end
def maintenance_mode?
::Gitlab::CurrentSettings.current_application_settings.maintenance_mode
end
def can_access_without_new_smartcard_login?
return true unless user
......
......@@ -36,7 +36,7 @@ module EE
allowed = super || geo_node_update_route? || geo_api_route?
return true if allowed
return false if maintenance_mode?
return false if ::Gitlab.maintenance_mode?
return false unless ::Gitlab::Geo.secondary?
git_write_routes
......@@ -90,13 +90,7 @@ module EE
override :read_only?
def read_only?
maintenance_mode? || super
end
def maintenance_mode?
return unless ::Feature.enabled?(:maintenance_mode)
::Gitlab::CurrentSettings.maintenance_mode
::Gitlab.maintenance_mode? || super
end
end
end
......
......@@ -115,4 +115,10 @@ module Gitlab
'web'
end
def self.maintenance_mode?
return false unless ::Feature.enabled?(:maintenance_mode)
::Gitlab::CurrentSettings.maintenance_mode
end
end
......@@ -329,4 +329,24 @@ RSpec.describe Gitlab do
expect(described_class.http_proxy_env?).to eq(false)
end
end
describe '.maintenance_mode?' do
it 'returns true when maintenance mode is enabled' do
stub_application_setting(maintenance_mode: true)
expect(described_class.maintenance_mode?).to eq(true)
end
it 'returns false when maintenance mode is disabled' do
stub_application_setting(maintenance_mode: false)
expect(described_class.maintenance_mode?).to eq(false)
end
it 'returns false when maintenance mode feature flag is disabled' do
stub_feature_flags(maintenance_mode: false)
expect(described_class.maintenance_mode?).to eq(false)
end
end
end
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