Commit d514833a1579d50070fc687acc2af4f135b25a56

Authored by Dmitriy Zaporozhets
1 parent 2c46b35b

Dont show new file link on protected branch for developers

Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
app/helpers/branches_helper.rb
1 1 module BranchesHelper
2 2 def can_remove_branch?(project, branch_name)
3   - if project.protected_branch? branch_name
4   - false
5   - elsif branch_name == project.repository.root_ref
6   - false
7   - else
8   - can?(current_user, :push_code, project)
9   - end
  3 + if project.protected_branch? branch_name
  4 + false
  5 + elsif branch_name == project.repository.root_ref
  6 + false
  7 + else
  8 + can?(current_user, :push_code, project)
  9 + end
  10 + end
  11 +
  12 + def can_push_branch?(project, branch_name)
  13 + return false unless project.repository.branch_names.include?(branch_name)
  14 + action = if project.protected_branch?(branch_name)
  15 + :push_code_to_protected_branches
  16 + else
  17 + :push_code
  18 + end
  19 +
  20 + current_user.can?(action, project)
10 21 end
11 22 end
... ...
app/views/projects/tree/_tree.html.haml
... ... @@ -9,7 +9,7 @@
9 9 = link_to truncate(title, length: 40), project_tree_path(@project, path)
10 10 - else
11 11 = link_to title, '#'
12   - - if current_user && @repository.branch_names.include?(@ref) && current_user.can?(:push_code, @project)
  12 + - if current_user && can_push_branch?(@project, @ref)
13 13 %li
14 14 = link_to project_new_tree_path(@project, @id), title: 'New file', id: 'new-file-link' do
15 15 %small
... ...