Commit 9ab43aa7 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.

Closes gitlab-org/gitlab-ce#43937.
parent c920d165
Pipeline #19344409 passed with stages
in 47 minutes and 58 seconds
......@@ -3,23 +3,9 @@
# Automatically sets the layout and ensures an administrator is logged in
class Admin::ApplicationController < ApplicationController
before_action :authenticate_admin!
before_action :display_read_only_information
layout 'admin'
def authenticate_admin!
render_404 unless current_user.admin?
end
def display_read_only_information
return unless Gitlab::Database.read_only?
flash.now[:notice] = read_only_message
end
private
# Overridden in EE
def read_only_message
_('You are on a read-only GitLab instance.')
end
end
......@@ -323,4 +323,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
......@@ -6,6 +6,7 @@
.mobile-overlay
.alert-wrapper
= render "layouts/broadcast"
= render 'layouts/header/read_only_banner'
= yield :flash_message
- unless @hide_breadcrumbs
= render "layouts/nav/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
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