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
end
def allowed_to_merge?
allowed_to_push_code?(project)
allowed_to_push_code?(project, @merge_request.target_branch)
end
def invalid_mr
......@@ -225,17 +225,17 @@ class Projects::MergeRequestsController < Projects::ApplicationController
end
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?
end
def allowed_to_push_code?(project)
action = if project.protected_branch?(@merge_request.target_branch)
def allowed_to_push_code?(project, branch)
action = if project.protected_branch?(branch)
:push_code_to_protected_branches
else
:push_code
end
can?(current_user, action, @project)
can?(current_user, action, project)
end
end
......@@ -210,7 +210,7 @@ class MergeRequest < ActiveRecord::Base
end
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
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