2012-01-18 15:15:45 -05:00
|
|
|
class HelpController < ApplicationController
|
2016-07-27 15:43:29 -04:00
|
|
|
skip_before_action :authenticate_user!, :reject_blocked!
|
2015-09-08 09:42:30 -04:00
|
|
|
|
2015-05-01 04:39:11 -04:00
|
|
|
layout 'help'
|
2015-04-30 15:28:07 -04:00
|
|
|
|
2012-01-18 15:15:45 -05:00
|
|
|
def index
|
2015-09-22 18:26:51 -04:00
|
|
|
@help_index = File.read(Rails.root.join('doc', 'README.md'))
|
2015-09-23 00:24:17 -04:00
|
|
|
|
2016-11-18 06:57:25 -05:00
|
|
|
# Prefix Markdown links with `help/` unless they are external links
|
2016-12-01 06:07:52 -05:00
|
|
|
# See http://rubular.com/r/X3baHTbPO2
|
|
|
|
@help_index.gsub!(%r{(?<delim>\]\()(?!.+://)(?!/)(?<link>[^\)\(]+\))}) do
|
|
|
|
"#{$~[:delim]}#{Gitlab.config.gitlab.relative_url_root}/help/#{$~[:link]}"
|
|
|
|
end
|
2012-01-18 15:15:45 -05:00
|
|
|
end
|
2013-06-06 06:19:23 -04:00
|
|
|
|
2014-04-18 11:21:21 -04:00
|
|
|
def show
|
2016-07-11 15:12:55 -04:00
|
|
|
@path = clean_path_info(path_params[:path])
|
2014-04-18 11:21:21 -04:00
|
|
|
|
2015-04-15 12:45:31 -04:00
|
|
|
respond_to do |format|
|
|
|
|
format.any(:markdown, :md, :html) do
|
2015-08-18 12:08:03 -04:00
|
|
|
# Note: We are purposefully NOT using `Rails.root.join`
|
2016-05-16 18:06:26 -04:00
|
|
|
path = File.join(Rails.root, 'doc', "#{@path}.md")
|
2015-04-15 12:45:31 -04:00
|
|
|
|
|
|
|
if File.exist?(path)
|
|
|
|
@markdown = File.read(path)
|
|
|
|
|
|
|
|
render 'show.html.haml'
|
|
|
|
else
|
|
|
|
# Force template to Haml
|
|
|
|
render 'errors/not_found.html.haml', layout: 'errors', status: 404
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# Allow access to images in the doc folder
|
2016-07-12 13:28:39 -04:00
|
|
|
format.any(:png, :gif, :jpeg, :mp4) do
|
2015-08-18 12:08:03 -04:00
|
|
|
# Note: We are purposefully NOT using `Rails.root.join`
|
2016-05-16 18:06:26 -04:00
|
|
|
path = File.join(Rails.root, 'doc', "#{@path}.#{params[:format]}")
|
2015-04-15 12:45:31 -04:00
|
|
|
|
|
|
|
if File.exist?(path)
|
|
|
|
send_file(path, disposition: 'inline')
|
|
|
|
else
|
|
|
|
head :not_found
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# Any other format we don't recognize, just respond 404
|
|
|
|
format.any { head :not_found }
|
2014-04-18 11:21:21 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-04-15 12:24:44 -04:00
|
|
|
def shortcuts
|
2013-06-30 15:10:52 -04:00
|
|
|
end
|
2015-03-08 17:46:22 -04:00
|
|
|
|
|
|
|
def ui
|
2016-04-16 16:00:30 -04:00
|
|
|
@user = User.new(id: 0, name: 'John Doe', username: '@johndoe')
|
2015-03-08 17:46:22 -04:00
|
|
|
end
|
2015-04-10 12:16:46 -04:00
|
|
|
|
2015-04-15 12:24:44 -04:00
|
|
|
private
|
|
|
|
|
2015-04-15 12:45:31 -04:00
|
|
|
def path_params
|
2016-05-16 18:06:26 -04:00
|
|
|
params.require(:path)
|
2015-04-15 12:45:31 -04:00
|
|
|
|
|
|
|
params
|
|
|
|
end
|
|
|
|
|
2015-04-10 12:16:46 -04:00
|
|
|
PATH_SEPS = Regexp.union(*[::File::SEPARATOR, ::File::ALT_SEPARATOR].compact)
|
|
|
|
|
2015-04-14 07:07:15 -04:00
|
|
|
# Taken from ActionDispatch::FileHandler
|
|
|
|
# Cleans up the path, to prevent directory traversal outside the doc folder.
|
2015-04-10 12:16:46 -04:00
|
|
|
def clean_path_info(path_info)
|
2015-04-14 07:07:15 -04:00
|
|
|
parts = path_info.split(PATH_SEPS)
|
2015-04-10 12:16:46 -04:00
|
|
|
|
|
|
|
clean = []
|
|
|
|
|
2015-04-14 07:07:15 -04:00
|
|
|
# Walk over each part of the path
|
2015-04-10 12:16:46 -04:00
|
|
|
parts.each do |part|
|
2015-04-14 07:07:15 -04:00
|
|
|
# Turn `one//two` or `one/./two` into `one/two`.
|
2015-04-10 12:16:46 -04:00
|
|
|
next if part.empty? || part == '.'
|
2015-04-14 07:07:15 -04:00
|
|
|
|
|
|
|
if part == '..'
|
|
|
|
# Turn `one/two/../` into `one`
|
|
|
|
clean.pop
|
|
|
|
else
|
|
|
|
# Add simple folder names to the clean path.
|
|
|
|
clean << part
|
|
|
|
end
|
2015-04-10 12:16:46 -04:00
|
|
|
end
|
|
|
|
|
2015-04-14 07:07:15 -04:00
|
|
|
# If the path was an absolute path (i.e. `/` or `/one/two`),
|
|
|
|
# add `/` to the front of the clean path.
|
2015-04-10 12:16:46 -04:00
|
|
|
clean.unshift '/' if parts.empty? || parts.first.empty?
|
|
|
|
|
2015-04-14 07:07:15 -04:00
|
|
|
# Join all the clean path parts by the path separator.
|
2015-04-10 12:16:46 -04:00
|
|
|
::File.join(*clean)
|
|
|
|
end
|
2012-01-18 15:15:45 -05:00
|
|
|
end
|