Commit d514833a1579d50070fc687acc2af4f135b25a56
1 parent
2c46b35b
Exists in
spb-stable
and in
2 other branches
Dont show new file link on protected branch for developers
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
Showing
2 changed files
with
19 additions
and
8 deletions
Show diff stats
app/helpers/branches_helper.rb
1 | module BranchesHelper | 1 | module BranchesHelper |
2 | def can_remove_branch?(project, branch_name) | 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 | end | 21 | end |
11 | end | 22 | end |
app/views/projects/tree/_tree.html.haml
@@ -9,7 +9,7 @@ | @@ -9,7 +9,7 @@ | ||
9 | = link_to truncate(title, length: 40), project_tree_path(@project, path) | 9 | = link_to truncate(title, length: 40), project_tree_path(@project, path) |
10 | - else | 10 | - else |
11 | = link_to title, '#' | 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 | %li | 13 | %li |
14 | = link_to project_new_tree_path(@project, @id), title: 'New file', id: 'new-file-link' do | 14 | = link_to project_new_tree_path(@project, @id), title: 'New file', id: 'new-file-link' do |
15 | %small | 15 | %small |