diff options
author | Bob Van Landuyt <bob@vanlanduyt.co> | 2017-09-20 17:41:11 +0200 |
---|---|---|
committer | Bob Van Landuyt <bob@vanlanduyt.co> | 2017-10-07 11:46:23 +0200 |
commit | 70716a1292ca5910908ba37a9d113c8b5a221bb7 (patch) | |
tree | ebff7a1289e85444170669761fcd2233a5757d54 /app | |
parent | d328007214786c7137c31d2c73e9ee76b025e6ed (diff) | |
download | gitlab-ce-70716a1292ca5910908ba37a9d113c8b5a221bb7.tar.gz |
Allow creating merge requests across forks of a project
Diffstat (limited to 'app')
-rw-r--r-- | app/finders/merge_request_target_project_finder.rb | 18 | ||||
-rw-r--r-- | app/helpers/merge_requests_helper.rb | 3 | ||||
-rw-r--r-- | app/models/merge_request.rb | 2 | ||||
-rw-r--r-- | app/models/project.rb | 15 |
4 files changed, 34 insertions, 4 deletions
diff --git a/app/finders/merge_request_target_project_finder.rb b/app/finders/merge_request_target_project_finder.rb new file mode 100644 index 00000000000..508b53a52c1 --- /dev/null +++ b/app/finders/merge_request_target_project_finder.rb @@ -0,0 +1,18 @@ +class MergeRequestTargetProjectFinder + attr_reader :current_user, :source_project + + def initialize(current_user: nil, source_project:, params: {}) + @current_user = current_user + @source_project = source_project + end + + def execute + if @source_project.fork_network + @source_project.fork_network.projects + .public_or_visible_to_user(current_user) + .with_feature_available_for_user(:merge_requests, current_user) + else + Project.where(id: source_project) + end + end +end diff --git a/app/helpers/merge_requests_helper.rb b/app/helpers/merge_requests_helper.rb index c31023f2d9a..5b2c58d193d 100644 --- a/app/helpers/merge_requests_helper.rb +++ b/app/helpers/merge_requests_helper.rb @@ -73,7 +73,8 @@ module MergeRequestsHelper end def target_projects(project) - [project, project.default_merge_request_target].uniq + MergeRequestTargetProjectFinder.new(current_user: current_user, source_project: project) + .execute end def merge_request_button_visibility(merge_request, closed) diff --git a/app/models/merge_request.rb b/app/models/merge_request.rb index 086226618e6..9b312f7db6c 100644 --- a/app/models/merge_request.rb +++ b/app/models/merge_request.rb @@ -403,7 +403,7 @@ class MergeRequest < ActiveRecord::Base return false unless for_fork? return true unless source_project - !source_project.forked_from?(target_project) + !source_project.in_fork_network_of?(target_project) end def reopenable? diff --git a/app/models/project.rb b/app/models/project.rb index aff8fd768f5..4a883552a8d 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -1128,8 +1128,19 @@ class Project < ActiveRecord::Base end end - def in_fork_network_of?(project) - forked? && project.fork_network == fork_network + def forked_from?(other_project) + forked? && forked_from_project == other_project + end + + def in_fork_network_of?(other_project) + # TODO: Remove this in a next release when all fork_networks are populated + # This makes sure all MergeRequests remain valid while the projects don't + # have a fork_network yet. + return true if forked_from?(other_project) + + return false if fork_network.nil? || other_project.fork_network.nil? + + fork_network == other_project.fork_network end def origin_merge_requests |