mirror of
https://github.com/discourse/discourse.git
synced 2025-05-30 15:28:37 +08:00
FEATURE: add clean support for running Discourse in a subfolder
To setup set DISCOURSE_RELATIVE_URL_ROOT to the folder you wish
This commit is contained in:
@ -88,7 +88,7 @@ class ApplicationController < ActionController::Base
|
||||
if (request.format && request.format.json?) || request.xhr? || !request.get?
|
||||
rescue_discourse_actions(:not_logged_in, 403, true)
|
||||
else
|
||||
redirect_to "/"
|
||||
redirect_to path("/")
|
||||
end
|
||||
|
||||
end
|
||||
@ -379,7 +379,7 @@ class ApplicationController < ActionController::Base
|
||||
# redirect user to the SSO page if we need to log in AND SSO is enabled
|
||||
if SiteSetting.login_required?
|
||||
if SiteSetting.enable_sso?
|
||||
redirect_to '/session/sso'
|
||||
redirect_to path('/session/sso')
|
||||
else
|
||||
redirect_to :login
|
||||
end
|
||||
@ -387,7 +387,7 @@ class ApplicationController < ActionController::Base
|
||||
end
|
||||
|
||||
def block_if_readonly_mode
|
||||
return if request.fullpath.start_with?("/admin/backups")
|
||||
return if request.fullpath.start_with?(path "/admin/backups")
|
||||
raise Discourse::ReadOnly.new if !request.get? && Discourse.readonly_mode?
|
||||
end
|
||||
|
||||
@ -404,6 +404,10 @@ class ApplicationController < ActionController::Base
|
||||
|
||||
protected
|
||||
|
||||
def path(p)
|
||||
"#{GlobalSetting.relative_url_root}#{p}"
|
||||
end
|
||||
|
||||
def render_post_json(post, add_raw=true)
|
||||
post_serializer = PostSerializer.new(post, scope: guardian, root: false)
|
||||
post_serializer.add_raw = add_raw
|
||||
|
@ -7,7 +7,7 @@ class CategoriesController < ApplicationController
|
||||
skip_before_filter :check_xhr, only: [:index, :redirect]
|
||||
|
||||
def redirect
|
||||
redirect_to "/c/#{params[:path]}"
|
||||
redirect_to path("/c/#{params[:path]}")
|
||||
end
|
||||
|
||||
def index
|
||||
|
@ -17,7 +17,7 @@ class ForumsController < ApplicationController
|
||||
end
|
||||
|
||||
def home_redirect
|
||||
redirect_to '/'
|
||||
redirect_to path('/')
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -19,13 +19,13 @@ class InvitesController < ApplicationController
|
||||
|
||||
topic = invite.topics.first
|
||||
if topic.present?
|
||||
redirect_to "#{Discourse.base_uri}#{topic.relative_url}"
|
||||
redirect_to path("#{topic.relative_url}")
|
||||
return
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
redirect_to "/"
|
||||
redirect_to path("/")
|
||||
end
|
||||
|
||||
def create
|
||||
@ -40,7 +40,7 @@ class InvitesController < ApplicationController
|
||||
guardian.ensure_can_send_multiple_invites!(current_user)
|
||||
end
|
||||
|
||||
if Invite.invite_by_email(params[:email], current_user, topic=nil, group_ids)
|
||||
if Invite.invite_by_email(params[:email], current_user, _topic=nil, group_ids)
|
||||
render json: success_json
|
||||
else
|
||||
render json: failed_json, status: 422
|
||||
@ -77,13 +77,13 @@ class InvitesController < ApplicationController
|
||||
|
||||
topic = invite.topics.first
|
||||
if topic.present?
|
||||
redirect_to "#{Discourse.base_uri}#{topic.relative_url}"
|
||||
redirect_to path("#{topic.relative_url}")
|
||||
return
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
redirect_to "/"
|
||||
redirect_to path("/")
|
||||
end
|
||||
|
||||
def destroy
|
||||
|
@ -12,7 +12,7 @@ class SessionController < ApplicationController
|
||||
|
||||
def sso
|
||||
if SiteSetting.enable_sso
|
||||
redirect_to DiscourseSingleSignOn.generate_url(params[:return_path] || '/')
|
||||
redirect_to DiscourseSingleSignOn.generate_url(params[:return_path] || path('/'))
|
||||
else
|
||||
render nothing: true, status: 404
|
||||
end
|
||||
@ -32,7 +32,7 @@ class SessionController < ApplicationController
|
||||
redirect_to sso.to_url(sso.return_sso_url)
|
||||
else
|
||||
session[:sso_payload] = request.query_string
|
||||
redirect_to '/login'
|
||||
redirect_to path('/login')
|
||||
end
|
||||
else
|
||||
render nothing: true, status: 404
|
||||
@ -47,7 +47,7 @@ class SessionController < ApplicationController
|
||||
raise "User #{params[:session_id]} not found" if user.blank?
|
||||
|
||||
log_on_user(user)
|
||||
redirect_to "/"
|
||||
redirect_to path("/")
|
||||
end
|
||||
|
||||
def sso_login
|
||||
@ -80,9 +80,9 @@ class SessionController < ApplicationController
|
||||
if return_path !~ /^\/[^\/]/
|
||||
begin
|
||||
uri = URI(return_path)
|
||||
return_path = "/" unless uri.host == Discourse.current_hostname
|
||||
return_path = path("/") unless uri.host == Discourse.current_hostname
|
||||
rescue
|
||||
return_path = "/"
|
||||
return_path = path("/")
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -4,7 +4,7 @@ class StaticController < ApplicationController
|
||||
skip_before_filter :verify_authenticity_token, only: [:enter]
|
||||
|
||||
def show
|
||||
return redirect_to('/') if current_user && params[:id] == 'login'
|
||||
return redirect_to(path '/') if current_user && params[:id] == 'login'
|
||||
|
||||
map = {
|
||||
"faq" => {redirect: "faq_url", topic_id: "guidelines_topic_id"},
|
||||
@ -60,15 +60,17 @@ class StaticController < ApplicationController
|
||||
params.delete(:username)
|
||||
params.delete(:password)
|
||||
|
||||
destination = "/"
|
||||
destination = path("/")
|
||||
|
||||
if params[:redirect].present? && !params[:redirect].match(login_path)
|
||||
begin
|
||||
forum_uri = URI(Discourse.base_url)
|
||||
uri = URI(params[:redirect])
|
||||
|
||||
if uri.path.present? &&
|
||||
(uri.host.blank? || uri.host == forum_uri.host) &&
|
||||
uri.path !~ /\./
|
||||
|
||||
destination = uri.path
|
||||
end
|
||||
rescue URI::InvalidURIError
|
||||
|
@ -58,7 +58,7 @@ class UserAvatarsController < ApplicationController
|
||||
upload ||= user.uploaded_avatar if user.uploaded_avatar_id == version
|
||||
|
||||
if user.uploaded_avatar && !upload
|
||||
return redirect_to "/user_avatar/#{hostname}/#{user.username_lower}/#{size}/#{user.uploaded_avatar_id}.png"
|
||||
return redirect_to path("/user_avatar/#{hostname}/#{user.username_lower}/#{size}/#{user.uploaded_avatar_id}.png")
|
||||
elsif upload
|
||||
original = Discourse.store.path_for(upload)
|
||||
if Discourse.store.external? || File.exists?(original)
|
||||
|
@ -142,7 +142,7 @@ class UsersController < ApplicationController
|
||||
|
||||
def my_redirect
|
||||
if current_user.present? && params[:path] =~ /^[a-z\-\/]+$/
|
||||
redirect_to "/users/#{current_user.username}/#{params[:path]}"
|
||||
redirect_to path("/users/#{current_user.username}/#{params[:path]}")
|
||||
return
|
||||
end
|
||||
raise Discourse::NotFound.new
|
||||
|
Reference in New Issue
Block a user