Commit ce6431f6 authored by Gabriel Mazetto's avatar Gabriel Mazetto

Requires a specific license Add-On to use Geo.

parent 8dce2158
class Admin::GeoNodesController < Admin::ApplicationController
before_action :check_license
def index
@nodes = GeoNode.all
@node = GeoNode.new
......@@ -41,4 +43,11 @@ class Admin::GeoNodesController < Admin::ApplicationController
def geo_node_params
params.require(:geo_node).permit(:url, :primary, geo_node_key_attributes: [:key])
end
def check_license
unless Gitlab::Geo.license_allows?
flash[:alert] = 'You need a diferent license to enable Geo replication'
redirect_to admin_license_path
end
end
end
......@@ -22,6 +22,10 @@ module Gitlab
RequestStore.store[:geo_node_enabled] ||= GeoNode.exists?
end
def self.license_allows?
::License.current && ::License.current.add_on?('GitLab_Geo')
end
def self.primary?
RequestStore.store[:geo_node_primary?] ||= self.enabled? && self.current_node && self.current_node.primary?
end
......
......@@ -70,6 +70,10 @@ module Gitlab
return build_status_object(false, 'The project you were looking for could not be found.')
end
if Gitlab::Geo.secondary? && !Gitlab::Geo.license_allows?
return build_status_object(false, 'Your current license does not have GitLab Geo add-on enabled.')
end
case cmd
when *DOWNLOAD_COMMANDS
download_access_check
......@@ -94,7 +98,7 @@ module Gitlab
def push_access_check(changes)
if Gitlab::Geo.enabled? && Gitlab::Geo.secondary?
if Gitlab::Geo.secondary?
return build_status_object(false, "You can't push code on a secondary GitLab Geo node.")
end
......
......@@ -68,4 +68,21 @@ describe Gitlab::Geo, lib: true do
expect(described_class.geo_node?(host: 'inexistent', port: 1234)).to be_falsey
end
end
describe 'license_allows?' do
it 'returns true if license has Geo addon' do
allow_any_instance_of(License).to receive(:add_on?).with('GitLab_Geo') { true }
expect(described_class.license_allows?).to be_truthy
end
it 'returns false if license doesnt have Geo addon' do
allow_any_instance_of(License).to receive(:add_on?).with('GitLab_Geo') { false }
expect(described_class.license_allows?).to be_falsey
end
it 'returns false if no license is present' do
allow(License).to receive(:current) { nil }
expect(described_class.license_allows?).to be_falsey
end
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