Commit cc505f550da83b2073adb168bcca620f656a076b
1 parent
ee0e9830
Exists in
master
and in
4 other branches
Check if a file is editied "on" a branch or a commit.
The previous behavior was a "disabled" link, which was still clickable and linked to the edit file action. If the user accesses a path like "/edit/master/README" show the file edit form (just like before). If the user accesses a path like "/edit/8d5c1f375ce99e5df84e26b0eafbf1448c6a001e/README", redirect the user to the file detail page with a note, that he cannot edit a file "on" a commit. fixes #5482
Showing
2 changed files
with
8 additions
and
1 deletions
Show diff stats
app/controllers/projects/edit_tree_controller.rb
... | ... | @@ -45,5 +45,9 @@ class Projects::EditTreeController < Projects::ApplicationController |
45 | 45 | end |
46 | 46 | |
47 | 47 | return access_denied! unless allowed |
48 | + | |
49 | + unless @repository.branch_names.include?(@ref) | |
50 | + redirect_to project_blob_path(@project, @id), notice: "You can only edit this file if you are on top of a branch" | |
51 | + end | |
48 | 52 | end |
49 | 53 | end | ... | ... |
app/views/projects/blob/_actions.html.haml
1 | 1 | .btn-group.tree-btn-group |
2 | 2 | -# only show edit link for text files |
3 | 3 | - if @blob.text? |
4 | - = link_to "edit", project_edit_tree_path(@project, @id), class: "btn btn-small", disabled: !allowed_tree_edit? | |
4 | + - if allowed_tree_edit? | |
5 | + = link_to "edit", project_edit_tree_path(@project, @id), class: "btn btn-small" | |
6 | + - else | |
7 | + %span.btn.btn-small.disabled Edit | |
5 | 8 | = link_to "raw", project_raw_path(@project, @id), class: "btn btn-small", target: "_blank" |
6 | 9 | -# only show normal/blame view links for text files |
7 | 10 | - if @blob.text? | ... | ... |