summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Lopez <james@jameslopez.es>2018-02-23 16:52:18 +0100
committerJames Lopez <james@jameslopez.es>2018-02-23 16:52:18 +0100
commitc888e73bc6bf7c89c551a45e579a3b319d435d21 (patch)
tree3e14e77b86bdd49b6952ca9afabca786316ad9d3
parent73c4c995f90ab84ff1a3cff24d2cb189003f54a0 (diff)
downloadgitlab-ce-41255-refactoring-of-blob-link-methods-in-blob_helper.tar.gz
-rw-r--r--app/helpers/blob_helper.rb12
-rw-r--r--app/views/projects/tree/_tree_header.html.haml2
-rw-r--r--spec/helpers/blob_helper_spec.rb2
3 files changed, 8 insertions, 8 deletions
diff --git a/app/helpers/blob_helper.rb b/app/helpers/blob_helper.rb
index 551af3301db..0e806d16bc5 100644
--- a/app/helpers/blob_helper.rb
+++ b/app/helpers/blob_helper.rb
@@ -16,6 +16,10 @@ module BlobHelper
options[:link_opts])
end
+ def ide_edit_path(project = @project, ref = @ref, path = @path, options = {})
+ "#{ide_path}/project#{edit_blob_path(project, ref, path, options)}"
+ end
+
def edit_blob_button(project = @project, ref = @ref, path = @path, options = {})
return unless blob = readable_blob(options, path, project, ref)
@@ -29,10 +33,6 @@ module BlobHelper
ref)
end
- def display_modify_blob?(blob, project, ref)
- !current_user || (current_user && can_modify_blob?(blob, project, ref))
- end
-
def ide_edit_button(project = @project, ref = @ref, path = @path, options = {})
return unless show_new_ide?
return unless blob = readable_blob(options, path, project, ref)
@@ -42,7 +42,7 @@ module BlobHelper
edit_button_tag(blob,
common_classes,
_('Web IDE'),
- "#{ide_path}/project#{edit_blob_path(project, ref, path, options)}",
+ ide_edit_path(project, ref, path, options),
project,
ref)
end
@@ -335,7 +335,7 @@ module BlobHelper
edit_disabled_button_tag(text, common_classes)
# This condition only applies to users who are logged in
# Web IDE (Beta) requires the user to have this feature enabled
- elsif display_modify_blob?(blob, project, ref)
+ elsif !current_user || (current_user && can_modify_blob?(blob, project, ref))
edit_link_tag(text, edit_path, common_classes)
elsif current_user && can?(current_user, :fork_project, project)
edit_fork_button_tag(common_classes, project, text, edit_blob_fork_params(edit_path))
diff --git a/app/views/projects/tree/_tree_header.html.haml b/app/views/projects/tree/_tree_header.html.haml
index ff3928552af..39511435508 100644
--- a/app/views/projects/tree/_tree_header.html.haml
+++ b/app/views/projects/tree/_tree_header.html.haml
@@ -74,7 +74,7 @@
.tree-controls
- if show_new_ide?
= succeed " " do
- = link_to "#{ide_path}/project#{edit_blob_path(@project, @id, @path, {})}", class: 'btn btn-default' do
+ = link_to ide_edit_path(@project, @id), class: 'btn btn-default' do
= _('Web IDE')
= link_to s_('Commits|History'), project_commits_path(@project, @id), class: 'btn'
diff --git a/spec/helpers/blob_helper_spec.rb b/spec/helpers/blob_helper_spec.rb
index 0548e71c89d..1fa194fe1b8 100644
--- a/spec/helpers/blob_helper_spec.rb
+++ b/spec/helpers/blob_helper_spec.rb
@@ -74,7 +74,7 @@ describe BlobHelper do
end
end
- describe "#edit_blob_element" do
+ describe "#edit_blob_link" do
let(:namespace) { create(:namespace, name: 'gitlab' )}
let(:project) { create(:project, :repository, namespace: namespace) }