diff options
-rw-r--r-- | lib/api/merge_requests.rb | 21 | ||||
-rw-r--r-- | lib/gitlab/satellite/satellite.rb | 1 | ||||
-rw-r--r-- | spec/models/merge_request_spec.rb | 1 |
3 files changed, 16 insertions, 7 deletions
diff --git a/lib/api/merge_requests.rb b/lib/api/merge_requests.rb index f9fb9cb8c13..d690f1d07e7 100644 --- a/lib/api/merge_requests.rb +++ b/lib/api/merge_requests.rb @@ -14,6 +14,14 @@ module API end not_found! end + + def not_fork?(target_project_id, user_project) + target_project_id.nil? || target_project_id == user_project.id.to_s + end + + def target_matches_fork(target_project_id,user_project) + user_project.forked? && user_project.forked_from_project.id.to_s == target_project_id + end end # List merge requests @@ -69,13 +77,16 @@ module API merge_request.author = current_user merge_request.source_project = user_project target_project_id = attrs[:target_project_id] - if !target_project_id.nil? && user_project.forked? && user_project.forked_from_project.id.to_s == target_project_id - merge_request.target_project = Project.find_by_id(attrs[:target_project_id]) - elsif target_project_id.nil? || target_project_id == user_project.id.to_s + if not_fork?(target_project_id, user_project) merge_request.target_project = user_project - elsif !target_project_id.nil? - render_api_error!('(Bad Request) Specified target project that is not the source project, or the source fork of the project.', 400) + else + if target_matches_fork(target_project_id,user_project) + merge_request.target_project = Project.find_by_id(attrs[:target_project_id]) + else + render_api_error!('(Bad Request) Specified target project that is not the source project, or the source fork of the project.', 400) + end end + if merge_request.save merge_request.reload_code present merge_request, with: Entities::MergeRequest diff --git a/lib/gitlab/satellite/satellite.rb b/lib/gitlab/satellite/satellite.rb index 758cf726413..ed6920b23ec 100644 --- a/lib/gitlab/satellite/satellite.rb +++ b/lib/gitlab/satellite/satellite.rb @@ -130,7 +130,6 @@ module Gitlab repo.git.fetch(default_options, :origin) end - def default_options(options = {}) {raise: true, timeout: true}.merge(options) end diff --git a/spec/models/merge_request_spec.rb b/spec/models/merge_request_spec.rb index cb15d250c12..68f3f920e06 100644 --- a/spec/models/merge_request_spec.rb +++ b/spec/models/merge_request_spec.rb @@ -83,7 +83,6 @@ describe MergeRequest do end end - describe '#allow_source_branch_removal?' do it 'should not allow removal when mr is a fork' do |