From 81eacd1b2a591d3ce1f14d4119527ea9b290ba8f Mon Sep 17 00:00:00 2001 From: Ciro Santilli Date: Sun, 28 Sep 2014 11:02:29 +0200 Subject: Disable / hide MR edit blob button if cannot edit. --- app/helpers/tree_helper.rb | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) (limited to 'app/helpers/tree_helper.rb') 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 -- cgit v1.2.1 From a56d0d47db5b11787472fbed37f23c60bf0e57fe Mon Sep 17 00:00:00 2001 From: Ciro Santilli Date: Tue, 4 Nov 2014 11:16:53 +0100 Subject: Remove unneeded backslash: "\/" == "/" --- app/helpers/tree_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app/helpers/tree_helper.rb') diff --git a/app/helpers/tree_helper.rb b/app/helpers/tree_helper.rb index 9c611a1c147..8e209498323 100644 --- a/app/helpers/tree_helper.rb +++ b/app/helpers/tree_helper.rb @@ -66,7 +66,7 @@ module TreeHelper def tree_breadcrumbs(tree, max_links = 2) if @path.present? part_path = "" - parts = @path.split("\/") + parts = @path.split('/') yield('..', nil) if parts.count > max_links -- cgit v1.2.1 From 90ed76ac3cfc64f7bfc66a90104d055ddd1bb2e7 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Tue, 23 Dec 2014 11:22:12 +0200 Subject: Prevent 500 after merge MR if you check remove source branch Signed-off-by: Dmitriy Zaporozhets --- app/helpers/tree_helper.rb | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'app/helpers/tree_helper.rb') diff --git a/app/helpers/tree_helper.rb b/app/helpers/tree_helper.rb index 329beadbd41..e32aeba5f8f 100644 --- a/app/helpers/tree_helper.rb +++ b/app/helpers/tree_helper.rb @@ -66,7 +66,14 @@ module TreeHelper end def edit_blob_link(project, ref, path, options = {}) - if project.repository.blob_at(ref, path).text? + blob = + begin + project.repository.blob_at(ref, path) + rescue + nil + end + + if blob && blob.text? text = 'Edit' after = options[:after] || '' from_mr = options[:from_merge_request_id] -- cgit v1.2.1 From 6c65b91d8c754c61fe8e50966283af5f78c1c9f0 Mon Sep 17 00:00:00 2001 From: Ciro Santilli Date: Tue, 30 Sep 2014 22:28:05 +0200 Subject: Remove or prepend _ to unused method arguments --- app/helpers/tree_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app/helpers/tree_helper.rb') diff --git a/app/helpers/tree_helper.rb b/app/helpers/tree_helper.rb index e32aeba5f8f..b86275704c9 100644 --- a/app/helpers/tree_helper.rb +++ b/app/helpers/tree_helper.rb @@ -108,7 +108,7 @@ module TreeHelper end end - def up_dir_path(tree) + def up_dir_path file = File.join(@path, "..") tree_join(@ref, file) end -- cgit v1.2.1 From 021cff67f3514b4c2cb1f7b859cbfc314afa0a0c Mon Sep 17 00:00:00 2001 From: marmis85 Date: Wed, 31 Dec 2014 03:15:04 +0100 Subject: Flatten the directory hierarchy while there is only one directory descendant --- app/helpers/tree_helper.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'app/helpers/tree_helper.rb') diff --git a/app/helpers/tree_helper.rb b/app/helpers/tree_helper.rb index e32aeba5f8f..5a96a208e93 100644 --- a/app/helpers/tree_helper.rb +++ b/app/helpers/tree_helper.rb @@ -113,6 +113,16 @@ module TreeHelper tree_join(@ref, file) end + # returns the relative path of the first subdir that doesn't have only one directory descendand + def flatten_tree(tree) + subtree = Gitlab::Git::Tree.where(@repository, @commit.id, tree.path) + if subtree.count == 1 && subtree.first.dir? + return tree_join(tree.name, flatten_tree(subtree.first)) + else + return tree.name + end + end + def leave_edit_message "Leave edit mode?\nAll unsaved changes will be lost." end -- cgit v1.2.1 From 33c9f05c6bb90a995ddc685b4a22479f17c575e5 Mon Sep 17 00:00:00 2001 From: Ciro Santilli Date: Thu, 9 Oct 2014 09:47:47 +0200 Subject: Append in place for strings and arrays --- app/helpers/tree_helper.rb | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'app/helpers/tree_helper.rb') diff --git a/app/helpers/tree_helper.rb b/app/helpers/tree_helper.rb index e32aeba5f8f..8693acad994 100644 --- a/app/helpers/tree_helper.rb +++ b/app/helpers/tree_helper.rb @@ -10,13 +10,16 @@ module TreeHelper tree = "" # Render folders if we have any - tree += render partial: 'projects/tree/tree_item', collection: folders, locals: {type: 'folder'} if folders.present? + tree << render(partial: 'projects/tree/tree_item', collection: folders, + locals: { type: 'folder' }) if folders.present? # Render files if we have any - tree += render partial: 'projects/tree/blob_item', collection: files, locals: {type: 'file'} if files.present? + tree << render(partial: 'projects/tree/blob_item', collection: files, + locals: { type: 'file' }) if files.present? # Render submodules if we have any - tree += render partial: 'projects/tree/submodule_item', collection: submodules if submodules.present? + tree << render(partial: 'projects/tree/submodule_item', + collection: submodules) if submodules.present? tree.html_safe end -- cgit v1.2.1 From 5c801602189bdf179432e9ef5885f6c6fef438f2 Mon Sep 17 00:00:00 2001 From: Steven Burgart Date: Sun, 18 Jan 2015 10:29:37 -0500 Subject: Fix various typos signe-in -> signed-in go_to_gihub_for_permissions -> go_to_github_for_permissions descendand -> descendant behavour -> behaviour recepient_email -> recipient_email generate_fingerpint -> generate_fingerprint dependes -> depends Cant't -> Can't wisit -> visit notifcation -> notification sufficent_scope -> sufficient_scope? levet -> level --- app/helpers/tree_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app/helpers/tree_helper.rb') diff --git a/app/helpers/tree_helper.rb b/app/helpers/tree_helper.rb index d316213b1fd..b614fb67acb 100644 --- a/app/helpers/tree_helper.rb +++ b/app/helpers/tree_helper.rb @@ -113,7 +113,7 @@ module TreeHelper tree_join(@ref, file) end - # returns the relative path of the first subdir that doesn't have only one directory descendand + # returns the relative path of the first subdir that doesn't have only one directory descendant def flatten_tree(tree) subtree = Gitlab::Git::Tree.where(@repository, @commit.id, tree.path) if subtree.count == 1 && subtree.first.dir? -- cgit v1.2.1 From ab7a79bf3bb47fd1c9d82da0bb29a3cdf0246cdc Mon Sep 17 00:00:00 2001 From: Valery Sizov Date: Tue, 20 Jan 2015 15:23:37 -0800 Subject: developer can push to protected branches --- app/helpers/tree_helper.rb | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'app/helpers/tree_helper.rb') diff --git a/app/helpers/tree_helper.rb b/app/helpers/tree_helper.rb index d316213b1fd..133b0dfae9b 100644 --- a/app/helpers/tree_helper.rb +++ b/app/helpers/tree_helper.rb @@ -58,11 +58,7 @@ module TreeHelper 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) - else - can?(current_user, :push_code, project) - end + ::Gitlab::GitAccess.can_push_to_branch?(current_user, project, ref) end def edit_blob_link(project, ref, path, options = {}) -- cgit v1.2.1 From 21297e78afd5ddfbfdf62f471acf1ab2f0c2a892 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Mon, 26 Jan 2015 15:03:14 -0800 Subject: Refactor blob helpers --- app/helpers/tree_helper.rb | 38 -------------------------------------- 1 file changed, 38 deletions(-) (limited to 'app/helpers/tree_helper.rb') diff --git a/app/helpers/tree_helper.rb b/app/helpers/tree_helper.rb index 1d987a6ffc0..727ec3fb231 100644 --- a/app/helpers/tree_helper.rb +++ b/app/helpers/tree_helper.rb @@ -64,32 +64,6 @@ module TreeHelper ::Gitlab::GitAccess.can_push_to_branch?(current_user, project, ref) end - def edit_blob_link(project, ref, path, options = {}) - blob = - begin - project.repository.blob_at(ref, path) - rescue - nil - end - - if blob && blob.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 - def tree_breadcrumbs(tree, max_links = 2) if @path.present? part_path = "" @@ -121,16 +95,4 @@ module TreeHelper return tree.name end end - - def leave_edit_message - "Leave edit mode?\nAll unsaved changes will be lost." - end - - def editing_preview_title(filename) - if Gitlab::MarkdownHelper.previewable?(filename) - 'Preview' - else - 'Diff' - end - end end -- cgit v1.2.1 From 4e7a4cd95696746bcab78a4f9ec071dd4089397a Mon Sep 17 00:00:00 2001 From: Robert Speicher Date: Wed, 28 Jan 2015 03:32:48 -0500 Subject: Use `icon` helper method in helper modules --- app/helpers/tree_helper.rb | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) (limited to 'app/helpers/tree_helper.rb') diff --git a/app/helpers/tree_helper.rb b/app/helpers/tree_helper.rb index 727ec3fb231..b6fb7a8aa5a 100644 --- a/app/helpers/tree_helper.rb +++ b/app/helpers/tree_helper.rb @@ -38,13 +38,8 @@ module TreeHelper # # type - String type of the tree item; either 'folder' or 'file' def tree_icon(type) - icon_class = if type == 'folder' - 'fa fa-folder' - else - 'fa fa-file-o' - end - - content_tag :i, nil, class: icon_class + icon_class = type == 'folder' ? 'folder' : 'file-o' + icon(icon_class) end def tree_hex_class(content) -- cgit v1.2.1