Commit 7a6f9958 authored by Toon Claes's avatar Toon Claes Committed by Stan Hu

Extract some basics to Geo::ApplicationController

Create Admin::Geo::ApplicationController that contains some base logic
for all Geo admin controllers (i.e. license check).
parent df1d62c2
# frozen_string_literal: true
class Admin::Geo::ApplicationController < Admin::ApplicationController
helper ::EE::GeoHelper
protected
def check_license!
unless Gitlab::Geo.license_allows?
flash[:alert] = _('You need a different license to use Geo replication.')
redirect_to admin_license_path
end
end
end
# frozen_string_literal: true # frozen_string_literal: true
class Admin::Geo::NodesController < Admin::ApplicationController class Admin::Geo::NodesController < Admin::Geo::ApplicationController
before_action :check_license, except: :index before_action :check_license!, except: :index
before_action :load_node, only: [:edit, :update] before_action :load_node, only: [:edit, :update]
helper EE::GeoHelper
# rubocop: disable CodeReuse/ActiveRecord # rubocop: disable CodeReuse/ActiveRecord
def index def index
@nodes = GeoNode.all.order(:id) @nodes = GeoNode.all.order(:id)
@node = GeoNode.new @node = GeoNode.new
unless Gitlab::Geo.license_allows? unless Gitlab::Geo.license_allows?
flash.now[:alert] = _('You need a different license to enable Geo replication.') flash.now[:alert] = _('You need a different license to use Geo replication.')
end end
unless Gitlab::Database.postgresql_minimum_supported_version? unless Gitlab::Database.postgresql_minimum_supported_version?
...@@ -63,13 +61,6 @@ class Admin::Geo::NodesController < Admin::ApplicationController ...@@ -63,13 +61,6 @@ class Admin::Geo::NodesController < Admin::ApplicationController
) )
end end
def check_license
unless Gitlab::Geo.license_allows?
flash[:alert] = 'You need a different license to enable Geo replication'
redirect_to admin_license_path
end
end
def load_node def load_node
@node = GeoNode.find(params[:id]) @node = GeoNode.find(params[:id])
end end
......
# frozen_string_literal: true # frozen_string_literal: true
class Admin::Geo::ProjectsController < Admin::ApplicationController class Admin::Geo::ProjectsController < Admin::Geo::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! before_action :limited_actions_message!
helper ::EE::GeoHelper
def index def index
finder = ::Geo::ProjectRegistryStatusFinder.new finder = ::Geo::ProjectRegistryStatusFinder.new
...@@ -70,12 +68,6 @@ class Admin::Geo::ProjectsController < Admin::ApplicationController ...@@ -70,12 +68,6 @@ class Admin::Geo::ProjectsController < Admin::ApplicationController
private private
def check_license
unless Gitlab::Geo.license_allows?
redirect_to admin_license_path, alert: s_('Geo|You need a different license to use Geo replication')
end
end
def load_registry def load_registry
@registry = ::Geo::ProjectRegistry.find_by_id(params[:id]) @registry = ::Geo::ProjectRegistry.find_by_id(params[:id])
end end
......
...@@ -8,7 +8,7 @@ describe Admin::Geo::NodesController, :postgresql do ...@@ -8,7 +8,7 @@ describe Admin::Geo::NodesController, :postgresql do
end end
it 'displays a flash message' do it 'displays a flash message' do
expect(controller).to set_flash[:alert].to('You need a different license to enable Geo replication') expect(controller).to set_flash[:alert].to('You need a different license to use Geo replication.')
end end
end end
...@@ -55,7 +55,7 @@ describe Admin::Geo::NodesController, :postgresql do ...@@ -55,7 +55,7 @@ describe Admin::Geo::NodesController, :postgresql do
allow(Gitlab::Geo).to receive(:license_allows?).and_return(false) allow(Gitlab::Geo).to receive(:license_allows?).and_return(false)
end end
it_behaves_like 'with flash message', :alert, 'You need a different license to enable Geo replication' it_behaves_like 'with flash message', :alert, 'You need a different license to use Geo replication'
it 'does not redirects to the license page' do it 'does not redirects to the license page' do
go go
......
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