Commit 304aebc2 authored by Stan Hu's avatar Stan Hu

Define Gitlab::Geo.primary_node_configured? abstraction

parent 9e19864b
......@@ -12,7 +12,7 @@ class Admin::ApplicationController < ApplicationController
def display_geo_information
return unless Gitlab::Geo.secondary?
return unless Gitlab::Geo.primary_node.present?
return unless Gitlab::Geo.primary_node_configured?
primary_node = view_context.link_to('primary node', Gitlab::Geo.primary_node.url)
flash.now[:notice] = "You are on a secondary (read-only) Geo node. If you want to make any changes, you must visit the #{primary_node}.".html_safe
......
......@@ -60,7 +60,7 @@
= link_to sherlock_transactions_path, class: 'admin-icon', title: 'Sherlock Transactions',
data: {toggle: 'tooltip', placement: 'bottom', container: 'body'} do
= icon('tachometer fw')
- if Gitlab::Geo.secondary? && Gitlab::Geo.primary_node.present?
- if Gitlab::Geo.secondary? && Gitlab::Geo.primary_node_configured?
%li
= link_to Gitlab::Geo.primary_node.url, title: 'Go to primary node', data: {toggle: 'tooltip', placement: 'bottom', container: 'body'} do
= icon('globe fw')
......@@ -50,6 +50,10 @@ module Gitlab
Rails.configuration.respond_to?(:geo_database)
end
def self.primary_node_configured?
Gitlab::Geo.primary_node.present?
end
def self.license_allows?
::License.feature_available?(:geo)
end
......
......@@ -43,6 +43,20 @@ describe Gitlab::Geo do
end
end
describe 'primary_node_configured?' do
context 'when current node is a primary node' do
it 'returns true' do
primary_node
expect(described_class.primary_node_configured?).to be_truthy
end
it 'returns false when primary does not exist' do
expect(described_class.primary_node_configured?).to be_falsey
end
end
end
describe 'secondary?' do
context 'when current node is a secondary node' do
before do
......
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