Commit 39d8a64d authored by amouhzi's avatar amouhzi Committed by Hassan Amouhzi

Fixes grack authentification under relative_url_root

Ref: https://github.com/gitlabhq/gitlabhq/commit/e6159b8725f99af78f446f8d33fa0e52b7780430
Ref: https://github.com/gitlabhq/gitlabhq/pull/3204
Ref: https://github.com/gitlabhq/gitlabhq/issues/1228

Add Rails' variable in application.rb to support relative url

This variable is used by assets compilation and other modules.

Note that user needs to change application.rb too

Restrict session cookie to the relative path if set.

Ref: https://github.com/gitlabhq/gitlabhq/commit/2c2f1e31856a4decdae469974f5bea8245316f7e

Fix Update attachment_uploader.rb bug with relative URL

See: https://github.com/gitlabhq/gitlabhq/commit/161afda3fa4fca58f396e9c3acbd72bc14490ace

Fix Wall relative bug with attachement files (javascript)
parent 55582047
...@@ -64,7 +64,7 @@ class Wall ...@@ -64,7 +64,7 @@ class Wall
template = template.replace('{{text}}', simpleFormat(note.body)) template = template.replace('{{text}}', simpleFormat(note.body))
if note.attachment if note.attachment
file = '<i class="icon-paper-clip"/><a href="/files/note/' + note.id + '/' + note.attachment + '">' + note.attachment + '</a>' file = '<i class="icon-paper-clip"/><a href="' + gon.relative_url_root + '/files/note/' + note.id + '/' + note.attachment + '">' + note.attachment + '</a>'
else else
file = '' file = ''
template = template.replace('{{file}}', file) template = template.replace('{{file}}', file)
......
...@@ -21,7 +21,7 @@ class AttachmentUploader < CarrierWave::Uploader::Base ...@@ -21,7 +21,7 @@ class AttachmentUploader < CarrierWave::Uploader::Base
end end
def secure_url def secure_url
"/files/#{model.class.to_s.underscore}/#{model.id}/#{file.filename}" Gitlab.config.gitlab.relative_url_root + "/files/#{model.class.to_s.underscore}/#{model.id}/#{file.filename}"
end end
def file_storage? def file_storage?
......
...@@ -67,5 +67,9 @@ module Gitlab ...@@ -67,5 +67,9 @@ module Gitlab
# Version of your assets, change this if you want to expire all your assets # Version of your assets, change this if you want to expire all your assets
config.assets.version = '1.0' config.assets.version = '1.0'
# Uncomment this if you are using a subdirectory
# Note that ENV['RAILS_RELATIVE_URL_ROOT'] in config/puma.rb may need to be changed
# config.relative_url_root = "/gitlab"
end end
end end
...@@ -21,6 +21,7 @@ production: &base ...@@ -21,6 +21,7 @@ production: &base
# WARNING: This feature is no longer supported # WARNING: This feature is no longer supported
# Uncomment and customize to run in non-root path # Uncomment and customize to run in non-root path
# Note that ENV['RAILS_RELATIVE_URL_ROOT'] in config/puma.rb may need to be changed # Note that ENV['RAILS_RELATIVE_URL_ROOT'] in config/puma.rb may need to be changed
# You need to uncomment config.relative_url_root in config/application.rb
# relative_url_root: /gitlab # relative_url_root: /gitlab
# Uncomment and customize if you can't use the default user to run GitLab (default: 'git') # Uncomment and customize if you can't use the default user to run GitLab (default: 'git')
......
...@@ -2,7 +2,8 @@ ...@@ -2,7 +2,8 @@
Gitlab::Application.config.session_store :cookie_store, key: '_gitlab_session', Gitlab::Application.config.session_store :cookie_store, key: '_gitlab_session',
secure: Gitlab::Application.config.force_ssl, secure: Gitlab::Application.config.force_ssl,
httponly: true httponly: true,
path: (Rails.application.config.relative_url_root.nil?) ? '/' : Rails.application.config.relative_url_root
# Use the database for sessions instead of the cookie-based default, # Use the database for sessions instead of the cookie-based default,
# which shouldn't be used to store highly confidential information # which shouldn't be used to store highly confidential information
......
...@@ -15,7 +15,15 @@ module Grack ...@@ -15,7 +15,15 @@ module Grack
@auth = Request.new(env) @auth = Request.new(env)
# Need this patch due to the rails mount # Need this patch due to the rails mount
# Need this if under RELATIVE_URL_ROOT
unless Gitlab.config.gitlab.relative_url_root.empty?
# If website is mounted using relative_url_root need to remove it first
@env['PATH_INFO'] = @request.path.sub(Gitlab.config.gitlab.relative_url_root,'')
else
@env['PATH_INFO'] = @request.path @env['PATH_INFO'] = @request.path
end
@env['SCRIPT_NAME'] = "" @env['SCRIPT_NAME'] = ""
auth! auth!
......
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