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,7 +216,7 @@ class Projects::MergeRequestsController < Projects::ApplicationController | ||
216 | end | 216 | end |
217 | 217 | ||
218 | def allowed_to_merge? | 218 | def allowed_to_merge? |
219 | - allowed_to_push_code?(project) | 219 | + allowed_to_push_code?(project, @merge_request.target_branch) |
220 | end | 220 | end |
221 | 221 | ||
222 | def invalid_mr | 222 | def invalid_mr |
@@ -225,17 +225,17 @@ class Projects::MergeRequestsController < Projects::ApplicationController | @@ -225,17 +225,17 @@ class Projects::MergeRequestsController < Projects::ApplicationController | ||
225 | end | 225 | end |
226 | 226 | ||
227 | def allowed_to_remove_source_branch? | 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 | !@merge_request.disallow_source_branch_removal? | 229 | !@merge_request.disallow_source_branch_removal? |
230 | end | 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 | :push_code_to_protected_branches | 234 | :push_code_to_protected_branches |
235 | else | 235 | else |
236 | :push_code | 236 | :push_code |
237 | end | 237 | end |
238 | 238 | ||
239 | - can?(current_user, action, @project) | 239 | + can?(current_user, action, project) |
240 | end | 240 | end |
241 | end | 241 | end |
app/models/merge_request.rb
@@ -210,7 +210,7 @@ class MergeRequest < ActiveRecord::Base | @@ -210,7 +210,7 @@ class MergeRequest < ActiveRecord::Base | ||
210 | end | 210 | end |
211 | 211 | ||
212 | def disallow_source_branch_removal? | 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 | end | 214 | end |
215 | 215 | ||
216 | def project | 216 | def project |