Commit 7f9b7767 authored by Nick Thomas's avatar Nick Thomas

Namespace license checks for fast-forward merge (EES)

parent 842aebb9
......@@ -331,6 +331,16 @@ module EE
super unless mirror?
end
def merge_requests_rebase_enabled
super && feature_available?(:merge_request_rebase)
end
alias_method :merge_requests_rebase_enabled?, :merge_requests_rebase_enabled
def merge_requests_ff_only_enabled
super && feature_available?(:fast_forward_merge)
end
alias_method :merge_requests_ff_only_enabled?, :merge_requests_ff_only_enabled
private
def licensed_feature_available?(feature)
......
......@@ -12,6 +12,7 @@ class License < ActiveRecord::Base
EXPORT_ISSUES_FEATURE = 'GitLab_ExportIssues'.freeze
MERGE_REQUEST_REBASE_FEATURE = 'GitLab_MergeRequestRebase'.freeze
MERGE_REQUEST_SQUASH_FEATURE = 'GitLab_MergeRequestSquash'.freeze
FAST_FORWARD_MERGE_FEATURE = 'GitLab_FastForwardMerge'.freeze
FEATURE_CODES = {
geo: GEO_FEATURE,
......@@ -21,6 +22,7 @@ class License < ActiveRecord::Base
elastic_search: ELASTIC_SEARCH_FEATURE,
related_issues: RELATED_ISSUES_FEATURE,
# Features that make sense to Namespace:
fast_forward_merge: FAST_FORWARD_MERGE_FEATURE,
deploy_board: DEPLOY_BOARD_FEATURE,
file_lock: FILE_LOCK_FEATURE,
export_issues: EXPORT_ISSUES_FEATURE,
......@@ -36,6 +38,7 @@ class License < ActiveRecord::Base
EES_FEATURES = [
{ ELASTIC_SEARCH_FEATURE => 1 },
{ RELATED_ISSUES_FEATURE => 1 },
{ FAST_FORWARD_MERGE_FEATURE => 1 },
{ EXPORT_ISSUES_FEATURE => 1 },
{ MERGE_REQUEST_REBASE_FEATURE => 1 },
{ MERGE_REQUEST_SQUASH_FEATURE => 1 }
......@@ -71,6 +74,7 @@ class License < ActiveRecord::Base
{ AUDITOR_USER_FEATURE => 1 },
{ SERVICE_DESK_FEATURE => 1 },
{ OBJECT_STORAGE_FEATURE => 1 },
{ FAST_FORWARD_MERGE_FEATURE => 1 },
{ EXPORT_ISSUES_FEATURE => 1 },
{ MERGE_REQUEST_REBASE_FEATURE => 1 },
{ MERGE_REQUEST_SQUASH_FEATURE => 1 }
......
- form = local_assigns.fetch(:form)
- project = local_assigns.fetch(:project)
.form-group
- if project.feature_available?(:merge_request_rebase) || project.feature_available?(:fast_forward_merge)
.form-group
= label_tag :merge_method_merge, class: 'label-light' do
Merge method
.radio
......@@ -12,6 +13,7 @@
%span.descr
A merge commit is created for every merge, and merging is allowed as long as there are no conflicts.
- if project.feature_available?(:merge_request_rebase)
.radio
= label_tag :project_merge_method_rebase_merge do
= form.radio_button :merge_method, :rebase_merge, class: "js-merge-method-radio"
......@@ -20,11 +22,11 @@
%span.descr
A merge commit is created for every merge, but merging is only allowed if fast-forward merge is possible.
This way you could make sure that if this merge request would build, after merging to target branch it would also build.
- if project.feature_available?(:merge_request_rebase)
%br
%span.descr
When fast-forward merge is not possible, the user is given the option to rebase.
- if project.feature_available?(:fast_forward_merge)
.radio
= label_tag :project_merge_method_ff do
= form.radio_button :merge_method, :ff, class: "js-merge-method-radio"
......
---
title: Namespace license checks for fast-forward merge (EES)
merge_request: 2272
author:
......@@ -16,13 +16,13 @@ describe MergeRequest, models: true do
let(:project) { create(:project, merge_requests_rebase_enabled: true) }
it 'returns false when the project feature is unavailable' do
expect(merge_request.target_project).to receive(:feature_available?).with(:merge_request_rebase).and_return(false)
expect(merge_request.target_project).to receive(:feature_available?).with(:merge_request_rebase).at_least(:once).and_return(false)
is_expected.to be_falsy
end
it 'returns true when the project feature is available' do
expect(merge_request.target_project).to receive(:feature_available?).with(:merge_request_rebase).and_return(true)
expect(merge_request.target_project).to receive(:feature_available?).with(:merge_request_rebase).at_least(:once).and_return(true)
is_expected.to be_truthy
end
......
......@@ -266,4 +266,38 @@ describe Project, models: true do
expect(project.service_desk_address).to eq("test+#{project.full_path}@mail.com")
end
end
describe '#merge_method' do
[
{ ff: true, rebase: true, ff_licensed: true, rebase_licensed: true, method: :ff },
{ ff: true, rebase: true, ff_licensed: true, rebase_licensed: false, method: :ff },
{ ff: true, rebase: true, ff_licensed: false, rebase_licensed: true, method: :rebase_merge },
{ ff: true, rebase: true, ff_licensed: false, rebase_licensed: false, method: :merge },
{ ff: true, rebase: false, ff_licensed: true, rebase_licensed: true, method: :ff },
{ ff: true, rebase: false, ff_licensed: true, rebase_licensed: false, method: :ff },
{ ff: true, rebase: false, ff_licensed: false, rebase_licensed: true, method: :merge },
{ ff: true, rebase: false, ff_licensed: false, rebase_licensed: false, method: :merge },
{ ff: false, rebase: true, ff_licensed: true, rebase_licensed: true, method: :rebase_merge },
{ ff: false, rebase: true, ff_licensed: true, rebase_licensed: false, method: :merge },
{ ff: false, rebase: true, ff_licensed: false, rebase_licensed: true, method: :rebase_merge },
{ ff: false, rebase: true, ff_licensed: false, rebase_licensed: false, method: :merge },
{ ff: false, rebase: false, ff_licensed: true, rebase_licensed: true, method: :merge },
{ ff: false, rebase: false, ff_licensed: true, rebase_licensed: false, method: :merge },
{ ff: false, rebase: false, ff_licensed: false, rebase_licensed: true, method: :merge },
{ ff: false, rebase: false, ff_licensed: false, rebase_licensed: false, method: :merge }
].each do |spec|
context spec.inspect do
let(:project) { build(:empty_project, merge_requests_rebase_enabled: spec[:rebase], merge_requests_ff_only_enabled: spec[:ff]) }
let(:spec) { spec }
subject { project.merge_method }
before do
stub_licensed_features(merge_request_rebase: spec[:rebase_licensed], fast_forward_merge: spec[:ff_licensed])
end
it { is_expected.to eq(spec[:method]) }
end
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