Commit 6bd114a700b90a9686294e91b7c5a6bee25f0cdf
Exists in
spb-stable
and in
2 other branches
Merge branch 'remove-branch-btn' into 'master'
Don't show remove branch button if you are not allowed to remove it Fixes #1213
Showing
4 changed files
with
2 additions
and
12 deletions
Show diff stats
app/controllers/projects/merge_requests_controller.rb
@@ -225,7 +225,6 @@ class Projects::MergeRequestsController < Projects::ApplicationController | @@ -225,7 +225,6 @@ class Projects::MergeRequestsController < Projects::ApplicationController | ||
225 | @merge_request_diff = @merge_request.merge_request_diff | 225 | @merge_request_diff = @merge_request.merge_request_diff |
226 | @allowed_to_merge = allowed_to_merge? | 226 | @allowed_to_merge = allowed_to_merge? |
227 | @show_merge_controls = @merge_request.open? && @commits.any? && @allowed_to_merge | 227 | @show_merge_controls = @merge_request.open? && @commits.any? && @allowed_to_merge |
228 | - @allowed_to_remove_source_branch = allowed_to_remove_source_branch? | ||
229 | @source_branch = @merge_request.source_project.repository.find_branch(@merge_request.source_branch).try(:name) | 228 | @source_branch = @merge_request.source_project.repository.find_branch(@merge_request.source_branch).try(:name) |
230 | end | 229 | end |
231 | 230 | ||
@@ -238,11 +237,6 @@ class Projects::MergeRequestsController < Projects::ApplicationController | @@ -238,11 +237,6 @@ class Projects::MergeRequestsController < Projects::ApplicationController | ||
238 | render 'invalid' | 237 | render 'invalid' |
239 | end | 238 | end |
240 | 239 | ||
241 | - def allowed_to_remove_source_branch? | ||
242 | - allowed_to_push_code?(@merge_request.source_project, @merge_request.source_branch) && | ||
243 | - !@merge_request.disallow_source_branch_removal? | ||
244 | - end | ||
245 | - | ||
246 | def allowed_to_push_code?(project, branch) | 240 | def allowed_to_push_code?(project, branch) |
247 | action = if project.protected_branch?(branch) | 241 | action = if project.protected_branch?(branch) |
248 | :push_code_to_protected_branches | 242 | :push_code_to_protected_branches |
app/models/merge_request.rb
@@ -212,10 +212,6 @@ class MergeRequest < ActiveRecord::Base | @@ -212,10 +212,6 @@ class MergeRequest < ActiveRecord::Base | ||
212 | target_project != source_project | 212 | target_project != source_project |
213 | end | 213 | end |
214 | 214 | ||
215 | - def disallow_source_branch_removal? | ||
216 | - source_project.root_ref?(source_branch) || source_project.protected_branches.include?(source_branch) | ||
217 | - end | ||
218 | - | ||
219 | def project | 215 | def project |
220 | target_project | 216 | target_project |
221 | end | 217 | end |
app/views/projects/merge_requests/show/_mr_accept.html.haml
@@ -38,7 +38,7 @@ | @@ -38,7 +38,7 @@ | ||
38 | .accept-group | 38 | .accept-group |
39 | .pull-left | 39 | .pull-left |
40 | = f.submit "Accept Merge Request", class: "btn btn-create accept_merge_request" | 40 | = f.submit "Accept Merge Request", class: "btn btn-create accept_merge_request" |
41 | - - unless @merge_request.disallow_source_branch_removal? | 41 | + - if can_remove_branch?(@merge_request.source_project, @merge_request.source_branch) |
42 | .remove_branch_holder.pull-left | 42 | .remove_branch_holder.pull-left |
43 | = label_tag :should_remove_source_branch, class: "checkbox" do | 43 | = label_tag :should_remove_source_branch, class: "checkbox" do |
44 | = check_box_tag :should_remove_source_branch | 44 | = check_box_tag :should_remove_source_branch |
app/views/projects/merge_requests/show/_remove_source_branch.html.haml
1 | - if @source_branch.blank? | 1 | - if @source_branch.blank? |
2 | Source branch has been removed | 2 | Source branch has been removed |
3 | 3 | ||
4 | -- elsif @allowed_to_remove_source_branch && @merge_request.merged? | 4 | +- elsif can_remove_branch?(@merge_request.source_project, @merge_request.source_branch) && @merge_request.merged? |
5 | .remove_source_branch_widget | 5 | .remove_source_branch_widget |
6 | %p Changes merged into #{@merge_request.target_branch}. You can remove source branch now | 6 | %p Changes merged into #{@merge_request.target_branch}. You can remove source branch now |
7 | = link_to project_branch_path(@merge_request.source_project, @source_branch), remote: true, method: :delete, class: "btn btn-primary btn-small remove_source_branch" do | 7 | = link_to project_branch_path(@merge_request.source_project, @source_branch), remote: true, method: :delete, class: "btn btn-primary btn-small remove_source_branch" do |