Commit 4d85a180 authored by Toon Claes's avatar Toon Claes

Add read-only banner to all pages

When the database is in a read-only state, display a banner on each
page informing the user they cannot write to that GitLab instance.

EE counterpart of gitlab-org/gitlab-ce!17798.
parent 4dc6892e
......@@ -2,6 +2,8 @@ require 'digest/md5'
require 'uri'
module ApplicationHelper
prepend EE::ApplicationHelper
# Check if a particular controller is the current one
#
# args - One or more controller names to check
......@@ -327,4 +329,11 @@ module ApplicationHelper
def locale_path
asset_path("locale/#{Gitlab::I18n.locale}/app.js")
end
# Overridden in EE
def read_only_message
return unless Gitlab::Database.read_only?
_('You are on a read-only GitLab instance.')
end
end
......@@ -7,7 +7,7 @@
.alert-wrapper
= render "layouts/header/ee_license_banner"
= render "layouts/broadcast"
= render 'layouts/header/ee/geo_secondary_banner'
= render 'layouts/header/read_only_banner'
= render "layouts/nav/ee/classification_level_banner"
= yield :flash_message
- unless @hide_breadcrumbs
......
- message = read_only_message
- if message
.flash-container.flash-container-page
.flash-notice
%div{ class: (container_class) }
%span
= message
---
title: Add read-only banner to all pages
merge_request: 17798
author:
type: fixed
module EE
module ApplicationHelper
extend ::Gitlab::Utils::Override
override :read_only_message
def read_only_message
return super unless ::Gitlab::Geo.secondary_with_primary?
(_('You are on a secondary (read-only) Geo node. If you want to make any changes, you must visit the %{primary_node}.') %
{ primary_node: link_to('primary node', ::Gitlab::Geo.primary_node.url) }).html_safe
end
end
end
- if ::Gitlab::Geo.secondary? && ::Gitlab::Geo.primary_node
- primary_node = link_to('primary node', ::Gitlab::Geo.primary_node.url)
.flash-container.flash-container-page
.flash-notice
%div{ class: (container_class) }
%span You are on a secondary (read-only) Geo node. If you want to make any changes, you must visit the #{primary_node}.
require 'rails_helper'
describe 'Geo read-only message' do
include ::EE::GeoHelpers
set(:user) { create(:user) }
set(:primary) { create(:geo_node, :primary) }
set(:secondary) { create(:geo_node) }
before do
sign_in(user)
end
it 'shows read-only banner when on a Geo secondary' do
stub_current_geo_node(secondary)
visit root_dashboard_path
expect(page).to have_content('You are on a secondary (read-only) Geo node')
end
end
require 'rails_helper'
describe 'read-only message' do
set(:user) { create(:user) }
before do
sign_in(user)
end
it 'shows read-only banner when database is read-only' do
allow(Gitlab::Database).to receive(:read_only?).and_return(true)
visit root_dashboard_path
expect(page).to have_content('You are on a read-only GitLab instance.')
end
it 'does not show read-only banner when database is able to read-write' do
allow(Gitlab::Database).to receive(:read_only?).and_return(false)
visit root_dashboard_path
expect(page).not_to have_content('You are on a read-only GitLab instance.')
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