Commit d92e4830f78018b3a38bc448aaec4a045f4d3d62
1 parent
d70939f6
Exists in
spb-stable
and in
3 other branches
Allow people to remove source branch of fork project in MR
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
Showing
2 changed files
with
6 additions
and
6 deletions
Show diff stats
app/controllers/projects/merge_requests_controller.rb
... | ... | @@ -216,7 +216,7 @@ class Projects::MergeRequestsController < Projects::ApplicationController |
216 | 216 | end |
217 | 217 | |
218 | 218 | def allowed_to_merge? |
219 | - allowed_to_push_code?(project) | |
219 | + allowed_to_push_code?(project, @merge_request.target_branch) | |
220 | 220 | end |
221 | 221 | |
222 | 222 | def invalid_mr |
... | ... | @@ -225,17 +225,17 @@ class Projects::MergeRequestsController < Projects::ApplicationController |
225 | 225 | end |
226 | 226 | |
227 | 227 | def allowed_to_remove_source_branch? |
228 | - allowed_to_push_code?(@merge_request.source_project) && | |
228 | + allowed_to_push_code?(@merge_request.source_project, @merge_request.source_branch) && | |
229 | 229 | !@merge_request.disallow_source_branch_removal? |
230 | 230 | end |
231 | 231 | |
232 | - def allowed_to_push_code?(project) | |
233 | - action = if project.protected_branch?(@merge_request.target_branch) | |
232 | + def allowed_to_push_code?(project, branch) | |
233 | + action = if project.protected_branch?(branch) | |
234 | 234 | :push_code_to_protected_branches |
235 | 235 | else |
236 | 236 | :push_code |
237 | 237 | end |
238 | 238 | |
239 | - can?(current_user, action, @project) | |
239 | + can?(current_user, action, project) | |
240 | 240 | end |
241 | 241 | end | ... | ... |
app/models/merge_request.rb
... | ... | @@ -210,7 +210,7 @@ class MergeRequest < ActiveRecord::Base |
210 | 210 | end |
211 | 211 | |
212 | 212 | def disallow_source_branch_removal? |
213 | - (source_project.root_ref? source_branch) || for_fork? | |
213 | + source_project.root_ref?(source_branch) || source_project.protected_branches.include?(source_branch) | |
214 | 214 | end |
215 | 215 | |
216 | 216 | def project | ... | ... |