Commit d92e4830 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Allow people to remove source branch of fork project in MR

Signed-off-by: default avatarDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
parent d70939f6
...@@ -216,7 +216,7 @@ class Projects::MergeRequestsController < Projects::ApplicationController ...@@ -216,7 +216,7 @@ class Projects::MergeRequestsController < Projects::ApplicationController
end end
def allowed_to_merge? def allowed_to_merge?
allowed_to_push_code?(project) allowed_to_push_code?(project, @merge_request.target_branch)
end end
def invalid_mr def invalid_mr
...@@ -225,17 +225,17 @@ class Projects::MergeRequestsController < Projects::ApplicationController ...@@ -225,17 +225,17 @@ class Projects::MergeRequestsController < Projects::ApplicationController
end end
def allowed_to_remove_source_branch? def allowed_to_remove_source_branch?
allowed_to_push_code?(@merge_request.source_project) && allowed_to_push_code?(@merge_request.source_project, @merge_request.source_branch) &&
!@merge_request.disallow_source_branch_removal? !@merge_request.disallow_source_branch_removal?
end end
def allowed_to_push_code?(project) def allowed_to_push_code?(project, branch)
action = if project.protected_branch?(@merge_request.target_branch) action = if project.protected_branch?(branch)
:push_code_to_protected_branches :push_code_to_protected_branches
else else
:push_code :push_code
end end
can?(current_user, action, @project) can?(current_user, action, project)
end end
end end
...@@ -210,7 +210,7 @@ class MergeRequest < ActiveRecord::Base ...@@ -210,7 +210,7 @@ class MergeRequest < ActiveRecord::Base
end end
def disallow_source_branch_removal? def disallow_source_branch_removal?
(source_project.root_ref? source_branch) || for_fork? source_project.root_ref?(source_branch) || source_project.protected_branches.include?(source_branch)
end end
def project def project
......
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