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
class Admin::Geo::NodesController < Admin::ApplicationController
before_action :check_license, except: :index
class Admin::Geo::NodesController < Admin::Geo::ApplicationController
before_action :check_license!, except: :index
before_action :load_node, only: [:edit, :update]
helper EE::GeoHelper
# rubocop: disable CodeReuse/ActiveRecord
def index
@nodes = GeoNode.all.order(:id)
@node = GeoNode.new
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
unless Gitlab::Database.postgresql_minimum_supported_version?
......@@ -63,13 +61,6 @@ class Admin::Geo::NodesController < Admin::ApplicationController
)
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
@node = GeoNode.find(params[:id])
end
......
# frozen_string_literal: true
class Admin::Geo::ProjectsController < Admin::ApplicationController
before_action :check_license
class Admin::Geo::ProjectsController < Admin::Geo::ApplicationController
before_action :check_license!
before_action :load_registry, except: [:index]
before_action :limited_actions_message!
helper ::EE::GeoHelper
def index
finder = ::Geo::ProjectRegistryStatusFinder.new
......@@ -70,12 +68,6 @@ class Admin::Geo::ProjectsController < Admin::ApplicationController
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
@registry = ::Geo::ProjectRegistry.find_by_id(params[:id])
end
......
......@@ -8,7 +8,7 @@ describe Admin::Geo::NodesController, :postgresql do
end
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
......@@ -55,7 +55,7 @@ describe Admin::Geo::NodesController, :postgresql do
allow(Gitlab::Geo).to receive(:license_allows?).and_return(false)
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
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