summaryrefslogtreecommitdiff
path: root/app/helpers/tree_helper.rb
diff options
context:
space:
mode:
authorCiro Santilli <ciro.santilli@gmail.com>2014-09-28 11:02:29 +0200
committerCiro Santilli <ciro.santilli@gmail.com>2014-10-02 12:12:51 +0200
commit81eacd1b2a591d3ce1f14d4119527ea9b290ba8f (patch)
treebe7ce9b312f1e0b24f6e29b4c07dbff5eff718e8 /app/helpers/tree_helper.rb
parentb0349915e2615617aff9c5291f7e305d59ea3992 (diff)
downloadgitlab-ce-81eacd1b2a591d3ce1f14d4119527ea9b290ba8f.tar.gz
Disable / hide MR edit blob button if cannot edit.
Diffstat (limited to 'app/helpers/tree_helper.rb')
-rw-r--r--app/helpers/tree_helper.rb31
1 files changed, 26 insertions, 5 deletions
diff --git a/app/helpers/tree_helper.rb b/app/helpers/tree_helper.rb
index d815257a4e3..7d616589519 100644
--- a/app/helpers/tree_helper.rb
+++ b/app/helpers/tree_helper.rb
@@ -53,13 +53,34 @@ module TreeHelper
File.join(*args)
end
- def allowed_tree_edit?
- return false unless @repository.branch_names.include?(@ref)
+ def allowed_tree_edit?(project = nil, ref = nil)
+ project ||= @project
+ ref ||= @ref
+ return false unless project.repository.branch_names.include?(ref)
- if @project.protected_branch? @ref
- can?(current_user, :push_code_to_protected_branches, @project)
+ if project.protected_branch? ref
+ can?(current_user, :push_code_to_protected_branches, project)
else
- can?(current_user, :push_code, @project)
+ can?(current_user, :push_code, project)
+ end
+ end
+
+ def edit_blob_link(project, ref, path, options = {})
+ if project.repository.blob_at(ref, path).text?
+ text = 'Edit'
+ after = options[:after] || ''
+ from_mr = options[:from_merge_request_id]
+ link_opts = {}
+ link_opts[:from_merge_request_id] = from_mr if from_mr
+ cls = 'btn btn-small'
+ if allowed_tree_edit?(project, ref)
+ link_to text, project_edit_tree_path(project, tree_join(ref, path),
+ link_opts), class: cls
+ else
+ content_tag :span, text, class: cls + ' disabled'
+ end + after.html_safe
+ else
+ ''
end
end