Commit e39961a4 authored by Gabriel Mazetto's avatar Gabriel Mazetto Committed by Douglas Barbosa Alexandre

Geo: Improve read-only message in secondary nodes for actionable screens

parent b3e6e8c8
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
# #
# Automatically sets the layout and ensures an administrator is logged in # Automatically sets the layout and ensures an administrator is logged in
class Admin::ApplicationController < ApplicationController class Admin::ApplicationController < ApplicationController
prepend EE::Admin::ApplicationController
before_action :authenticate_admin! before_action :authenticate_admin!
layout 'admin' layout 'admin'
......
# frozen_string_literal: true # frozen_string_literal: true
class Admin::ProjectsController < Admin::ApplicationController class Admin::ProjectsController < Admin::ApplicationController
prepend EE::Admin::ProjectsController
include MembersPresentation include MembersPresentation
before_action :project, only: [:show, :transfer, :repository_check] before_action :project, only: [:show, :transfer, :repository_check]
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
class Admin::Geo::ProjectsController < Admin::ApplicationController class Admin::Geo::ProjectsController < Admin::ApplicationController
before_action :check_license before_action :check_license
before_action :load_registry, except: [:index] before_action :load_registry, except: [:index]
before_action :limited_actions_message!
helper ::EE::GeoHelper helper ::EE::GeoHelper
......
# frozen_string_literal: true
module EE
module Admin
module ApplicationController
# This will set an instance variable that will be read by EE::ApplicationHelper
#
# @see EE::ApplicationHelper
def limited_actions_message!
@limited_actions_message = true # rubocop:disable Gitlab/ModuleWithInstanceVariables
end
end
end
end
# frozen_string_literal: true
module EE
module Admin
module ProjectsController
extend ActiveSupport::Concern
prepended do
before_action :limited_actions_message!, only: :show
end
end
end
end
...@@ -4,10 +4,14 @@ module EE ...@@ -4,10 +4,14 @@ module EE
override :read_only_message override :read_only_message
def read_only_message def read_only_message
return super unless ::Gitlab::Geo.secondary_with_primary? return super unless ::Gitlab::Geo.secondary?
(_('You are on a secondary, <b>read-only</b> Geo node. If you want to make changes, you must visit this page on the %{primary_node}.') % if @limited_actions_message
{ primary_node: link_to('primary node', ::Gitlab::Geo.primary_node.url) }).html_safe s_('Geo|You are on a secondary, <b>read-only</b> Geo node. You may be able to make a limited amount of changes or perform a limited amount of actions on this page.').html_safe
else
(s_('Geo|You are on a secondary, <b>read-only</b> Geo node. If you want to make changes, you must visit this page on the %{primary_node}.') %
{ primary_node: link_to('primary node', ::Gitlab::Geo.primary_node&.url || '#') }).html_safe
end
end end
def render_ce(partial, locals = {}) def render_ce(partial, locals = {})
......
---
title: 'Geo: Improve read-only message in secondary nodes for actionable screens'
merge_request: 8238
author:
type: changed
# frozen_string_literal: true # frozen_string_literal: true
require 'spec_helper' require 'spec_helper'
describe Admin::Geo::ProjectsController, :geo do describe Admin::Geo::ProjectsController, :geo do
include EE::GeoHelpers
set(:admin) { create(:admin) } set(:admin) { create(:admin) }
let(:synced_registry) { create(:geo_project_registry, :synced) } let(:synced_registry) { create(:geo_project_registry, :synced) }
...@@ -28,6 +31,11 @@ describe Admin::Geo::ProjectsController, :geo do ...@@ -28,6 +31,11 @@ describe Admin::Geo::ProjectsController, :geo do
before do before do
stub_licensed_features(geo: true) stub_licensed_features(geo: true)
stub_current_geo_node(create(:geo_node))
end
it 'displays a different read-only message based on skip_readonly_message' do
expect(subject.body).to match('You may be able to make a limited amount of changes or perform a limited amount of actions on this page')
end end
context 'without sync_status specified' do context 'without sync_status specified' do
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
require 'spec_helper' require 'spec_helper'
describe Admin::ProjectsController do describe Admin::ProjectsController, :geo do
include EE::GeoHelpers include EE::GeoHelpers
let!(:project_registry) { create(:geo_project_registry) } let!(:project_registry) { create(:geo_project_registry) }
...@@ -31,6 +31,10 @@ describe Admin::ProjectsController do ...@@ -31,6 +31,10 @@ describe Admin::ProjectsController do
it 'renders Geo Status widget' do it 'renders Geo Status widget' do
expect(subject.body).to match('Geo Status') expect(subject.body).to match('Geo Status')
end end
it 'displays a different read-only message based on skip_readonly_message' do
expect(subject.body).to match('You may be able to make a limited amount of changes or perform a limited amount of actions on this page')
end
end end
context 'without Geo enabled' do context 'without Geo enabled' do
......
# frozen_string_literal: true
require 'spec_helper' require 'spec_helper'
describe ApplicationHelper do describe ApplicationHelper do
include EE::GeoHelpers
describe '#read_only_message' do
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 }
expect(helper.read_only_message).to match('You are on a read-only GitLab instance')
end
it 'returns nil when database is not read_only' do
expect(helper.read_only_message).to be_nil
end
end
context 'when in a Geo Secondary' do
before do
stub_current_geo_node(create(:geo_node))
end
context 'when there is no Geo Primary node configured' do
it 'returns a read-only Geo message without a link to a primary node' do
expect(helper.read_only_message).to match(/If you want to make changes, you must visit this page on the .*primary node/)
expect(helper.read_only_message).not_to include('http://')
end
end
context 'when there is a Geo Primary node configured' do
let!(:geo_primary) { create(:geo_node, :primary) }
it 'returns a read-only Geo message with a link to primary node' do
expect(helper.read_only_message).to match(/If you want to make changes, you must visit this page on the .*primary node/)
expect(helper.read_only_message).to include(geo_primary.url)
end
it 'returns a limited actions message when @limited_actions_message is true' do
assign(:limited_actions_message, true)
expect(helper.read_only_message).to match(/You may be able to make a limited amount of changes or perform a limited amount of actions on this page/)
expect(helper.read_only_message).not_to include('http://')
end
end
end
end
describe '#autocomplete_data_sources' do describe '#autocomplete_data_sources' do
def expect_autocomplete_data_sources(object, noteable_type, source_keys) def expect_autocomplete_data_sources(object, noteable_type, source_keys)
sources = helper.autocomplete_data_sources(object, noteable_type) sources = helper.autocomplete_data_sources(object, noteable_type)
......
...@@ -3841,6 +3841,12 @@ msgstr "" ...@@ -3841,6 +3841,12 @@ msgstr ""
msgid "Geo|Waiting for scheduler" msgid "Geo|Waiting for scheduler"
msgstr "" msgstr ""
msgid "Geo|You are on a secondary, <b>read-only</b> Geo node. If you want to make changes, you must visit this page on the %{primary_node}."
msgstr ""
msgid "Geo|You are on a secondary, <b>read-only</b> Geo node. You may be able to make a limited amount of changes or perform a limited amount of actions on this page."
msgstr ""
msgid "Geo|You need a different license to use Geo replication" msgid "Geo|You need a different license to use Geo replication"
msgstr "" msgstr ""
...@@ -8992,9 +8998,6 @@ msgstr "" ...@@ -8992,9 +8998,6 @@ msgstr ""
msgid "You are on a read-only GitLab instance." msgid "You are on a read-only GitLab instance."
msgstr "" msgstr ""
msgid "You are on a secondary, <b>read-only</b> Geo node. If you want to make changes, you must visit this page on the %{primary_node}."
msgstr ""
msgid "You can %{linkStart}view the blob%{linkEnd} instead." msgid "You can %{linkStart}view the blob%{linkEnd} instead."
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