Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2014-12-20 21:19:38 +0300
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2014-12-20 21:19:38 +0300
commite007d810c9945f13817eaa5c907a5e8a72a8a0e5 (patch)
tree901525278ffd43b5847bc702dfc3cce53106198b /app/helpers/tree_helper.rb
parent8c1be08d9f789e9a5a8cddcfefc076be1f064dd0 (diff)
parent81eacd1b2a591d3ce1f14d4119527ea9b290ba8f (diff)
Merge pull request #7886 from cirosantilli/disable-blob-edit-mr
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 8e209498323..329beadbd41 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