Commit 699607f2 authored by James Lopez's avatar James Lopez

initial refactor

parent 58a312f5
...@@ -17,10 +17,7 @@ module BlobHelper ...@@ -17,10 +17,7 @@ module BlobHelper
end end
def edit_blob_link(project = @project, ref = @ref, path = @path, options = {}) def edit_blob_link(project = @project, ref = @ref, path = @path, options = {})
blob = options.delete(:blob) return unless readable_blob?(options, path, project, ref)
blob ||= project.repository.blob_at(ref, path) rescue nil
return unless blob && blob.readable_text?
common_classes = "btn js-edit-blob #{options[:extra_class]}" common_classes = "btn js-edit-blob #{options[:extra_class]}"
...@@ -30,16 +27,7 @@ module BlobHelper ...@@ -30,16 +27,7 @@ module BlobHelper
elsif !current_user || (current_user && can_modify_blob?(blob, project, ref)) elsif !current_user || (current_user && can_modify_blob?(blob, project, ref))
link_to 'Edit', edit_blob_path(project, ref, path, options), class: "#{common_classes} btn-sm" link_to 'Edit', edit_blob_path(project, ref, path, options), class: "#{common_classes} btn-sm"
elsif current_user && can?(current_user, :fork_project, project) elsif current_user && can?(current_user, :fork_project, project)
continue_params = { edit_blob_fork(common_classes, options, path, project, ref)
to: edit_blob_path(project, ref, path, options),
notice: edit_in_new_fork_notice,
notice_now: edit_in_new_fork_notice_now
}
fork_path = project_forks_path(project, namespace_key: current_user.namespace.id, continue: continue_params)
button_tag 'Edit',
class: "#{common_classes} js-edit-blob-link-fork-toggler",
data: { action: 'edit', fork_path: fork_path }
end end
end end
...@@ -332,4 +320,24 @@ module BlobHelper ...@@ -332,4 +320,24 @@ module BlobHelper
options options
end end
def readable_blob?(options, path, project, ref)
blob = options.delete(:blob)
blob ||= project.repository.blob_at(ref, path) rescue nil
blob && blob.readable_text?
end
def edit_blob_fork(common_classes, options, path, project, ref)
continue_params = {
to: edit_blob_path(project, ref, path, options),
notice: edit_in_new_fork_notice,
notice_now: edit_in_new_fork_notice_now
}
fork_path = project_forks_path(project, namespace_key: current_user.namespace.id, continue: continue_params)
button_tag 'Edit',
class: "#{common_classes} js-edit-blob-link-fork-toggler",
data: { action: 'edit', fork_path: fork_path }
end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment