mirror of
https://github.com/discourse/discourse.git
synced 2024-11-22 15:16:08 +08:00
Replace base_uri
with base_path
(#10879)
DEV: Replace instances of Discourse.base_uri with Discourse.base_path
This is clearer because the base_uri is actually just a path prefix. This continues the work started in 555f467
.
This commit is contained in:
parent
5e3130ac26
commit
721ee36425
|
@ -329,7 +329,7 @@ class ApplicationController < ActionController::Base
|
||||||
current_user.reload
|
current_user.reload
|
||||||
current_user.publish_notifications_state
|
current_user.publish_notifications_state
|
||||||
cookie_args = {}
|
cookie_args = {}
|
||||||
cookie_args[:path] = Discourse.base_uri if Discourse.base_uri.present?
|
cookie_args[:path] = Discourse.base_path if Discourse.base_path.present?
|
||||||
cookies.delete('cn', cookie_args)
|
cookies.delete('cn', cookie_args)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -45,7 +45,7 @@ class ExtraLocalesController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.url(bundle)
|
def self.url(bundle)
|
||||||
"#{Discourse.base_uri}/extra-locales/#{bundle}?v=#{bundle_js_hash(bundle)}"
|
"#{Discourse.base_path}/extra-locales/#{bundle}?v=#{bundle_js_hash(bundle)}"
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.client_overrides_exist?
|
def self.client_overrides_exist?
|
||||||
|
|
|
@ -45,8 +45,8 @@ class RobotsTxtController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.fetch_default_robots_info
|
def self.fetch_default_robots_info
|
||||||
deny_paths = DISALLOWED_PATHS.map { |p| Discourse.base_uri + p }
|
deny_paths = DISALLOWED_PATHS.map { |p| Discourse.base_path + p }
|
||||||
deny_all = [ "#{Discourse.base_uri}/" ]
|
deny_all = [ "#{Discourse.base_path}/" ]
|
||||||
|
|
||||||
result = {
|
result = {
|
||||||
header: "# See http://www.robotstxt.org/robotstxt.html for documentation on how to use the robots.txt file",
|
header: "# See http://www.robotstxt.org/robotstxt.html for documentation on how to use the robots.txt file",
|
||||||
|
|
|
@ -478,7 +478,7 @@ class TagsController < ::ApplicationController
|
||||||
permalink = Permalink.find_by_url(url)
|
permalink = Permalink.find_by_url(url)
|
||||||
|
|
||||||
if permalink.present? && permalink.category_id
|
if permalink.present? && permalink.category_id
|
||||||
redirect_to "#{Discourse::base_uri}/tags#{permalink.target_url}/#{params[:tag_id]}", status: :moved_permanently
|
redirect_to "#{Discourse.base_path}/tags#{permalink.target_url}/#{params[:tag_id]}", status: :moved_permanently
|
||||||
else
|
else
|
||||||
# redirect to 404
|
# redirect to 404
|
||||||
raise Discourse::NotFound
|
raise Discourse::NotFound
|
||||||
|
|
|
@ -32,7 +32,7 @@ class Users::OmniauthCallbacksController < ApplicationController
|
||||||
# Save to redis, with a secret token, then redirect to confirmation screen
|
# Save to redis, with a secret token, then redirect to confirmation screen
|
||||||
token = SecureRandom.hex
|
token = SecureRandom.hex
|
||||||
Discourse.redis.setex "#{Users::AssociateAccountsController::REDIS_PREFIX}_#{current_user.id}_#{token}", 10.minutes, auth.to_json
|
Discourse.redis.setex "#{Users::AssociateAccountsController::REDIS_PREFIX}_#{current_user.id}_#{token}", 10.minutes, auth.to_json
|
||||||
return redirect_to "#{Discourse.base_uri}/associate/#{token}"
|
return redirect_to "#{Discourse.base_path}/associate/#{token}"
|
||||||
else
|
else
|
||||||
@auth_result = authenticator.after_authenticate(auth)
|
@auth_result = authenticator.after_authenticate(auth)
|
||||||
DiscourseEvent.trigger(:after_auth, authenticator, @auth_result)
|
DiscourseEvent.trigger(:after_auth, authenticator, @auth_result)
|
||||||
|
@ -55,14 +55,14 @@ class Users::OmniauthCallbacksController < ApplicationController
|
||||||
|
|
||||||
if parsed && # Valid
|
if parsed && # Valid
|
||||||
(parsed.host == nil || parsed.host == Discourse.current_hostname) && # Local
|
(parsed.host == nil || parsed.host == Discourse.current_hostname) && # Local
|
||||||
!parsed.path.starts_with?("#{Discourse.base_uri}/auth/") # Not /auth URL
|
!parsed.path.starts_with?("#{Discourse.base_path}/auth/") # Not /auth URL
|
||||||
@origin = +"#{parsed.path}"
|
@origin = +"#{parsed.path}"
|
||||||
@origin << "?#{parsed.query}" if parsed.query
|
@origin << "?#{parsed.query}" if parsed.query
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if @origin.blank?
|
if @origin.blank?
|
||||||
@origin = Discourse.base_uri("/")
|
@origin = Discourse.base_path("/")
|
||||||
end
|
end
|
||||||
|
|
||||||
@auth_result.destination_url = @origin
|
@auth_result.destination_url = @origin
|
||||||
|
@ -76,7 +76,7 @@ class Users::OmniauthCallbacksController < ApplicationController
|
||||||
cookies['_bypass_cache'] = true
|
cookies['_bypass_cache'] = true
|
||||||
cookies[:authentication_data] = {
|
cookies[:authentication_data] = {
|
||||||
value: @auth_result.to_client_hash.to_json,
|
value: @auth_result.to_client_hash.to_json,
|
||||||
path: Discourse.base_uri("/")
|
path: Discourse.base_path("/")
|
||||||
}
|
}
|
||||||
redirect_to @origin
|
redirect_to @origin
|
||||||
end
|
end
|
||||||
|
|
|
@ -300,7 +300,7 @@ module ApplicationHelper
|
||||||
end
|
end
|
||||||
|
|
||||||
def login_path
|
def login_path
|
||||||
"#{Discourse::base_uri}/login"
|
"#{Discourse.base_path}/login"
|
||||||
end
|
end
|
||||||
|
|
||||||
def mobile_view?
|
def mobile_view?
|
||||||
|
@ -488,7 +488,7 @@ module ApplicationHelper
|
||||||
setup_data = {
|
setup_data = {
|
||||||
cdn: Rails.configuration.action_controller.asset_host,
|
cdn: Rails.configuration.action_controller.asset_host,
|
||||||
base_url: Discourse.base_url,
|
base_url: Discourse.base_url,
|
||||||
base_uri: Discourse::base_uri,
|
base_uri: Discourse.base_path,
|
||||||
environment: Rails.env,
|
environment: Rails.env,
|
||||||
letter_avatar_version: LetterAvatar.version,
|
letter_avatar_version: LetterAvatar.version,
|
||||||
markdown_it_url: script_asset_path('markdown-it-bundle'),
|
markdown_it_url: script_asset_path('markdown-it-bundle'),
|
||||||
|
|
|
@ -98,11 +98,11 @@ module UserNotificationsHelper
|
||||||
end
|
end
|
||||||
|
|
||||||
def email_image_url(basename)
|
def email_image_url(basename)
|
||||||
UrlHelper.absolute("#{Discourse.base_uri}/images/emails/#{basename}")
|
UrlHelper.absolute("#{Discourse.base_path}/images/emails/#{basename}")
|
||||||
end
|
end
|
||||||
|
|
||||||
def url_for_email(href)
|
def url_for_email(href)
|
||||||
URI(href).host.present? ? href : UrlHelper.absolute("#{Discourse.base_uri}#{href}")
|
URI(href).host.present? ? href : UrlHelper.absolute("#{Discourse.base_path}#{href}")
|
||||||
rescue URI::Error
|
rescue URI::Error
|
||||||
href
|
href
|
||||||
end
|
end
|
||||||
|
|
|
@ -200,7 +200,7 @@ class AdminDashboardData
|
||||||
end
|
end
|
||||||
|
|
||||||
def subfolder_ends_in_slash_check
|
def subfolder_ends_in_slash_check
|
||||||
I18n.t('dashboard.subfolder_ends_in_slash') if Discourse.base_uri =~ /\/$/
|
I18n.t('dashboard.subfolder_ends_in_slash') if Discourse.base_path =~ /\/$/
|
||||||
end
|
end
|
||||||
|
|
||||||
def pop3_polling_configuration
|
def pop3_polling_configuration
|
||||||
|
|
|
@ -263,7 +263,7 @@ class Badge < ActiveRecord::Base
|
||||||
|
|
||||||
def long_description
|
def long_description
|
||||||
key = "badges.#{i18n_name}.long_description"
|
key = "badges.#{i18n_name}.long_description"
|
||||||
I18n.t(key, default: self[:long_description] || '', base_uri: Discourse.base_uri, max_likes_per_day: SiteSetting.max_likes_per_day)
|
I18n.t(key, default: self[:long_description] || '', base_uri: Discourse.base_path, max_likes_per_day: SiteSetting.max_likes_per_day)
|
||||||
end
|
end
|
||||||
|
|
||||||
def long_description=(val)
|
def long_description=(val)
|
||||||
|
@ -273,7 +273,7 @@ class Badge < ActiveRecord::Base
|
||||||
|
|
||||||
def description
|
def description
|
||||||
key = "badges.#{i18n_name}.description"
|
key = "badges.#{i18n_name}.description"
|
||||||
I18n.t(key, default: self[:description] || '', base_uri: Discourse.base_uri, max_likes_per_day: SiteSetting.max_likes_per_day)
|
I18n.t(key, default: self[:description] || '', base_uri: Discourse.base_path, max_likes_per_day: SiteSetting.max_likes_per_day)
|
||||||
end
|
end
|
||||||
|
|
||||||
def description=(val)
|
def description=(val)
|
||||||
|
|
|
@ -724,7 +724,7 @@ class Category < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def full_slug(separator = "-")
|
def full_slug(separator = "-")
|
||||||
start_idx = "#{Discourse.base_uri}/c/".size
|
start_idx = "#{Discourse.base_path}/c/".size
|
||||||
url[start_idx..-1].gsub("/", separator)
|
url[start_idx..-1].gsub("/", separator)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -735,7 +735,7 @@ class Category < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def url
|
def url
|
||||||
@@url_cache[self.id] ||= "#{Discourse.base_uri}/c/#{slug_path.join('/')}/#{self.id}"
|
@@url_cache[self.id] ||= "#{Discourse.base_path}/c/#{slug_path.join('/')}/#{self.id}"
|
||||||
end
|
end
|
||||||
|
|
||||||
def url_with_id
|
def url_with_id
|
||||||
|
@ -756,7 +756,7 @@ class Category < ActiveRecord::Base
|
||||||
def create_category_permalink
|
def create_category_permalink
|
||||||
old_slug = saved_changes.transform_values(&:first)["slug"]
|
old_slug = saved_changes.transform_values(&:first)["slug"]
|
||||||
|
|
||||||
url = +"#{Discourse.base_uri}/c"
|
url = +"#{Discourse.base_path}/c"
|
||||||
url << "/#{parent_category.slug_path.join('/')}" if parent_category_id
|
url << "/#{parent_category.slug_path.join('/')}" if parent_category_id
|
||||||
url << "/#{old_slug}/#{id}"
|
url << "/#{old_slug}/#{id}"
|
||||||
url = Permalink.normalize_url(url)
|
url = Permalink.normalize_url(url)
|
||||||
|
|
|
@ -73,7 +73,7 @@ class Emoji
|
||||||
|
|
||||||
def self.url_for(name)
|
def self.url_for(name)
|
||||||
name = name.delete_prefix(':').delete_suffix(':').gsub(/(.+):t([1-6])/, '\1/\2')
|
name = name.delete_prefix(':').delete_suffix(':').gsub(/(.+):t([1-6])/, '\1/\2')
|
||||||
"#{Discourse.base_uri}/images/emoji/#{SiteSetting.emoji_set}/#{name}.png?v=#{EMOJI_VERSION}"
|
"#{Discourse.base_path}/images/emoji/#{SiteSetting.emoji_set}/#{name}.png?v=#{EMOJI_VERSION}"
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.cache_key(name)
|
def self.cache_key(name)
|
||||||
|
@ -115,7 +115,7 @@ class Emoji
|
||||||
emojis.each do |name, url|
|
emojis.each do |name, url|
|
||||||
result << Emoji.new.tap do |e|
|
result << Emoji.new.tap do |e|
|
||||||
e.name = name
|
e.name = name
|
||||||
url = (Discourse.base_uri + url) if url[/^\/[^\/]/]
|
url = (Discourse.base_path + url) if url[/^\/[^\/]/]
|
||||||
e.url = url
|
e.url = url
|
||||||
e.group = group || DEFAULT_GROUP
|
e.group = group || DEFAULT_GROUP
|
||||||
end
|
end
|
||||||
|
@ -135,7 +135,7 @@ class Emoji
|
||||||
|
|
||||||
def self.base_url
|
def self.base_url
|
||||||
db = RailsMultisite::ConnectionManagement.current_db
|
db = RailsMultisite::ConnectionManagement.current_db
|
||||||
"#{Discourse.base_uri}/uploads/#{db}/_emoji"
|
"#{Discourse.base_path}/uploads/#{db}/_emoji"
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.replacement_code(code)
|
def self.replacement_code(code)
|
||||||
|
|
|
@ -8,7 +8,7 @@ class JavascriptCache < ActiveRecord::Base
|
||||||
before_save :update_digest
|
before_save :update_digest
|
||||||
|
|
||||||
def url
|
def url
|
||||||
"#{GlobalSetting.cdn_url}#{Discourse.base_uri}/theme-javascripts/#{digest}.js?__ws=#{Discourse.current_hostname}"
|
"#{GlobalSetting.cdn_url}#{Discourse.base_path}/theme-javascripts/#{digest}.js?__ws=#{Discourse.current_hostname}"
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
|
@ -78,7 +78,7 @@ class Permalink < ActiveRecord::Base
|
||||||
|
|
||||||
def target_url
|
def target_url
|
||||||
return external_url if external_url
|
return external_url if external_url
|
||||||
return "#{Discourse::base_uri}#{post.url}" if post
|
return "#{Discourse.base_path}#{post.url}" if post
|
||||||
return topic.relative_url if topic
|
return topic.relative_url if topic
|
||||||
return category.url if category
|
return category.url if category
|
||||||
return tag.full_url if tag
|
return tag.full_url if tag
|
||||||
|
|
|
@ -1230,7 +1230,7 @@ class Topic < ActiveRecord::Base
|
||||||
# NOTE: These are probably better off somewhere else.
|
# NOTE: These are probably better off somewhere else.
|
||||||
# Having a model know about URLs seems a bit strange.
|
# Having a model know about URLs seems a bit strange.
|
||||||
def last_post_url
|
def last_post_url
|
||||||
"#{Discourse.base_uri}/t/#{slug}/#{id}/#{posts_count}"
|
"#{Discourse.base_path}/t/#{slug}/#{id}/#{posts_count}"
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.url(id, slug, post_number = nil)
|
def self.url(id, slug, post_number = nil)
|
||||||
|
@ -1244,7 +1244,7 @@ class Topic < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.relative_url(id, slug, post_number = nil)
|
def self.relative_url(id, slug, post_number = nil)
|
||||||
url = +"#{Discourse.base_uri}/t/"
|
url = +"#{Discourse.base_path}/t/"
|
||||||
url << "#{slug}/" if slug.present?
|
url << "#{slug}/" if slug.present?
|
||||||
url << id.to_s
|
url << id.to_s
|
||||||
url << "/#{post_number}" if post_number.to_i > 1
|
url << "/#{post_number}" if post_number.to_i > 1
|
||||||
|
|
|
@ -826,14 +826,14 @@ class User < ActiveRecord::Base
|
||||||
# TODO it may be worth caching this in a distributed cache, should be benched
|
# TODO it may be worth caching this in a distributed cache, should be benched
|
||||||
if SiteSetting.external_system_avatars_enabled
|
if SiteSetting.external_system_avatars_enabled
|
||||||
url = SiteSetting.external_system_avatars_url.dup
|
url = SiteSetting.external_system_avatars_url.dup
|
||||||
url = +"#{Discourse::base_uri}#{url}" unless url =~ /^https?:\/\//
|
url = +"#{Discourse.base_path}#{url}" unless url =~ /^https?:\/\//
|
||||||
url.gsub! "{color}", letter_avatar_color(normalized_username)
|
url.gsub! "{color}", letter_avatar_color(normalized_username)
|
||||||
url.gsub! "{username}", UrlHelper.encode_component(username)
|
url.gsub! "{username}", UrlHelper.encode_component(username)
|
||||||
url.gsub! "{first_letter}", UrlHelper.encode_component(normalized_username.grapheme_clusters.first)
|
url.gsub! "{first_letter}", UrlHelper.encode_component(normalized_username.grapheme_clusters.first)
|
||||||
url.gsub! "{hostname}", Discourse.current_hostname
|
url.gsub! "{hostname}", Discourse.current_hostname
|
||||||
url
|
url
|
||||||
else
|
else
|
||||||
"#{Discourse.base_uri}/letter_avatar/#{normalized_username}/{size}/#{LetterAvatar.version}.png"
|
"#{Discourse.base_path}/letter_avatar/#{normalized_username}/{size}/#{LetterAvatar.version}.png"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -78,7 +78,7 @@ class UserAvatar < ActiveRecord::Base
|
||||||
|
|
||||||
def self.local_avatar_template(hostname, username, upload_id)
|
def self.local_avatar_template(hostname, username, upload_id)
|
||||||
version = self.version(upload_id)
|
version = self.version(upload_id)
|
||||||
"#{Discourse.base_uri}/user_avatar/#{hostname}/#{username}/{size}/#{version}.png"
|
"#{Discourse.base_path}/user_avatar/#{hostname}/#{username}/{size}/#{version}.png"
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.external_avatar_url(user_id, upload_id, size)
|
def self.external_avatar_url(user_id, upload_id, size)
|
||||||
|
|
|
@ -8,8 +8,8 @@
|
||||||
<%- end %>
|
<%- end %>
|
||||||
<meta name="theme-color" content="#<%= ColorScheme.hex_for_name('header_background', scheme_id) %>">
|
<meta name="theme-color" content="#<%= ColorScheme.hex_for_name('header_background', scheme_id) %>">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, user-scalable=yes, viewport-fit=cover">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, user-scalable=yes, viewport-fit=cover">
|
||||||
<%- if Discourse.base_uri.present? %>
|
<%- if Discourse.base_path.present? %>
|
||||||
<meta name="discourse-base-uri" content="<%= Discourse.base_uri %>">
|
<meta name="discourse-base-uri" content="<%= Discourse.base_path %>">
|
||||||
<% end %>
|
<% end %>
|
||||||
<%= canonical_link_tag %>
|
<%= canonical_link_tag %>
|
||||||
<%= render_sitelinks_search_tag %>
|
<%= render_sitelinks_search_tag %>
|
||||||
|
|
|
@ -45,7 +45,7 @@
|
||||||
|
|
||||||
<%= render_google_tag_manager_head_code %>
|
<%= render_google_tag_manager_head_code %>
|
||||||
<%= render_google_universal_analytics_code %>
|
<%= render_google_universal_analytics_code %>
|
||||||
<link rel="manifest" href="<%= Discourse.base_uri %>/manifest.webmanifest" crossorigin="use-credentials">
|
<link rel="manifest" href="<%= Discourse.base_path %>/manifest.webmanifest" crossorigin="use-credentials">
|
||||||
|
|
||||||
<%- if include_ios_native_app_banner? %>
|
<%- if include_ios_native_app_banner? %>
|
||||||
<meta name="apple-itunes-app" content="app-id=<%= SiteSetting.ios_app_id %><%= ios_app_argument %>">
|
<meta name="apple-itunes-app" content="app-id=<%= SiteSetting.ios_app_id %><%= ios_app_argument %>">
|
||||||
|
@ -59,7 +59,7 @@
|
||||||
|
|
||||||
<%= tag.meta id: 'data-discourse-setup', data: client_side_setup_data %>
|
<%= tag.meta id: 'data-discourse-setup', data: client_side_setup_data %>
|
||||||
|
|
||||||
<%- if !current_user && (data = cookies.delete(:authentication_data, path: Discourse.base_uri("/"))) %>
|
<%- if !current_user && (data = cookies.delete(:authentication_data, path: Discourse.base_path("/"))) %>
|
||||||
<meta id="data-authentication" data-authentication-data="<%= data %>">
|
<meta id="data-authentication" data-authentication-data="<%= data %>">
|
||||||
<%- end %>
|
<%- end %>
|
||||||
</head>
|
</head>
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
<%= @robots_info[:header] %>
|
<%= @robots_info[:header] %>
|
||||||
<% if Discourse.base_uri.present? %>
|
<% if Discourse.base_path.present? %>
|
||||||
# This robots.txt file is not used. Please append the content below in the robots.txt file located at the root
|
# This robots.txt file is not used. Please append the content below in the robots.txt file located at the root
|
||||||
<% end %>
|
<% end %>
|
||||||
#
|
#
|
||||||
|
|
|
@ -5,9 +5,9 @@
|
||||||
# we return the X-Robots-Tag with noindex, nofollow which will ensure
|
# we return the X-Robots-Tag with noindex, nofollow which will ensure
|
||||||
# indexing is minimized and nothing shows up in Google search results
|
# indexing is minimized and nothing shows up in Google search results
|
||||||
User-agent: googlebot
|
User-agent: googlebot
|
||||||
Allow: <%= Discourse.base_uri + "/" %>
|
Allow: <%= Discourse.base_path + "/" %>
|
||||||
Disallow: <%= Discourse.base_uri + "/uploads/*" %>
|
Disallow: <%= Discourse.base_path + "/uploads/*" %>
|
||||||
|
|
||||||
User-agent: *
|
User-agent: *
|
||||||
Disallow: <%= Discourse.base_uri + "/" %>
|
Disallow: <%= Discourse.base_path + "/" %>
|
||||||
|
|
||||||
|
|
|
@ -3,15 +3,15 @@
|
||||||
module ConfigurableUrls
|
module ConfigurableUrls
|
||||||
|
|
||||||
def faq_path
|
def faq_path
|
||||||
SiteSetting.faq_url.blank? ? "#{Discourse::base_uri}/faq" : SiteSetting.faq_url
|
SiteSetting.faq_url.blank? ? "#{Discourse.base_path}/faq" : SiteSetting.faq_url
|
||||||
end
|
end
|
||||||
|
|
||||||
def tos_path
|
def tos_path
|
||||||
SiteSetting.tos_url.blank? ? "#{Discourse::base_uri}/tos" : SiteSetting.tos_url
|
SiteSetting.tos_url.blank? ? "#{Discourse.base_path}/tos" : SiteSetting.tos_url
|
||||||
end
|
end
|
||||||
|
|
||||||
def privacy_path
|
def privacy_path
|
||||||
SiteSetting.privacy_policy_url.blank? ? "#{Discourse::base_uri}/privacy" : SiteSetting.privacy_policy_url
|
SiteSetting.privacy_policy_url.blank? ? "#{Discourse.base_path}/privacy" : SiteSetting.privacy_policy_url
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -40,7 +40,7 @@ class ContentSecurityPolicy
|
||||||
if can_use_s3_cdn && s3_cdn
|
if can_use_s3_cdn && s3_cdn
|
||||||
s3_cdn + dir
|
s3_cdn + dir
|
||||||
elsif can_use_cdn && cdn
|
elsif can_use_cdn && cdn
|
||||||
cdn + Discourse.base_uri + dir
|
cdn + Discourse.base_path + dir
|
||||||
else
|
else
|
||||||
base + dir
|
base + dir
|
||||||
end
|
end
|
||||||
|
|
|
@ -15,7 +15,7 @@ class ContentSecurityPolicy
|
||||||
|
|
||||||
# The EnforceHostname middleware ensures request.host_with_port can be trusted
|
# The EnforceHostname middleware ensures request.host_with_port can be trusted
|
||||||
protocol = (SiteSetting.force_https || request.ssl?) ? "https://" : "http://"
|
protocol = (SiteSetting.force_https || request.ssl?) ? "https://" : "http://"
|
||||||
base_url = protocol + request.host_with_port + Discourse.base_uri
|
base_url = protocol + request.host_with_port + Discourse.base_path
|
||||||
|
|
||||||
theme_ids = env[:resolved_theme_ids]
|
theme_ids = env[:resolved_theme_ids]
|
||||||
|
|
||||||
|
|
|
@ -380,10 +380,15 @@ module Discourse
|
||||||
SiteSetting.force_hostname.presence || RailsMultisite::ConnectionManagement.current_hostname
|
SiteSetting.force_hostname.presence || RailsMultisite::ConnectionManagement.current_hostname
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.base_uri(default_value = "")
|
def self.base_path(default_value = "")
|
||||||
ActionController::Base.config.relative_url_root.presence || default_value
|
ActionController::Base.config.relative_url_root.presence || default_value
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.base_uri(default_value = "")
|
||||||
|
deprecate("Discourse.base_uri is deprecated, use Discourse.base_path instead")
|
||||||
|
base_path(default_value)
|
||||||
|
end
|
||||||
|
|
||||||
def self.base_protocol
|
def self.base_protocol
|
||||||
SiteSetting.force_https? ? "https" : "http"
|
SiteSetting.force_https? ? "https" : "http"
|
||||||
end
|
end
|
||||||
|
@ -401,7 +406,7 @@ module Discourse
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.base_url
|
def self.base_url
|
||||||
base_url_no_prefix + base_uri
|
base_url_no_prefix + base_path
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.route_for(uri)
|
def self.route_for(uri)
|
||||||
|
@ -415,8 +420,8 @@ module Discourse
|
||||||
return unless uri
|
return unless uri
|
||||||
|
|
||||||
path = +(uri.path || "")
|
path = +(uri.path || "")
|
||||||
if !uri.host || (uri.host == Discourse.current_hostname && path.start_with?(Discourse.base_uri))
|
if !uri.host || (uri.host == Discourse.current_hostname && path.start_with?(Discourse.base_path))
|
||||||
path.slice!(Discourse.base_uri)
|
path.slice!(Discourse.base_path)
|
||||||
return Rails.application.routes.recognize_path(path)
|
return Rails.application.routes.recognize_path(path)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -426,7 +431,6 @@ module Discourse
|
||||||
end
|
end
|
||||||
|
|
||||||
class << self
|
class << self
|
||||||
alias_method :base_path, :base_uri
|
|
||||||
alias_method :base_url_no_path, :base_url_no_prefix
|
alias_method :base_url_no_path, :base_url_no_prefix
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,7 @@ module FileStore
|
||||||
|
|
||||||
def store_file(file, path)
|
def store_file(file, path)
|
||||||
copy_file(file, "#{public_dir}#{path}")
|
copy_file(file, "#{public_dir}#{path}")
|
||||||
"#{Discourse.base_uri}#{path}"
|
"#{Discourse.base_path}#{path}"
|
||||||
end
|
end
|
||||||
|
|
||||||
def remove_file(url, _)
|
def remove_file(url, _)
|
||||||
|
@ -36,7 +36,7 @@ module FileStore
|
||||||
end
|
end
|
||||||
|
|
||||||
def relative_base_url
|
def relative_base_url
|
||||||
File.join(Discourse.base_uri, upload_path)
|
File.join(Discourse.base_path, upload_path)
|
||||||
end
|
end
|
||||||
|
|
||||||
def external?
|
def external?
|
||||||
|
|
|
@ -200,7 +200,7 @@ module PrettyText
|
||||||
|
|
||||||
def self.paths_json
|
def self.paths_json
|
||||||
paths = {
|
paths = {
|
||||||
baseUri: Discourse::base_uri,
|
baseUri: Discourse.base_path,
|
||||||
CDN: Rails.configuration.action_controller.asset_host,
|
CDN: Rails.configuration.action_controller.asset_host,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -490,13 +490,13 @@ module PrettyText
|
||||||
|
|
||||||
case type
|
case type
|
||||||
when USER_TYPE
|
when USER_TYPE
|
||||||
element['href'] = "#{Discourse::base_uri}/u/#{UrlHelper.encode_component(name)}"
|
element['href'] = "#{Discourse.base_path}/u/#{UrlHelper.encode_component(name)}"
|
||||||
when GROUP_MENTIONABLE_TYPE
|
when GROUP_MENTIONABLE_TYPE
|
||||||
element['class'] = 'mention-group notify'
|
element['class'] = 'mention-group notify'
|
||||||
element['href'] = "#{Discourse::base_uri}/groups/#{UrlHelper.encode_component(name)}"
|
element['href'] = "#{Discourse.base_path}/groups/#{UrlHelper.encode_component(name)}"
|
||||||
when GROUP_TYPE
|
when GROUP_TYPE
|
||||||
element['class'] = 'mention-group'
|
element['class'] = 'mention-group'
|
||||||
element['href'] = "#{Discourse::base_uri}/groups/#{UrlHelper.encode_component(name)}"
|
element['href'] = "#{Discourse.base_path}/groups/#{UrlHelper.encode_component(name)}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -38,7 +38,7 @@ class UrlHelper
|
||||||
def self.is_local(url)
|
def self.is_local(url)
|
||||||
url.present? && (
|
url.present? && (
|
||||||
Discourse.store.has_been_uploaded?(url) ||
|
Discourse.store.has_been_uploaded?(url) ||
|
||||||
!!(url =~ Regexp.new("^#{Discourse.base_uri}/(assets|plugins|images)/")) ||
|
!!(url =~ Regexp.new("^#{Discourse.base_path}/(assets|plugins|images)/")) ||
|
||||||
url.start_with?(Discourse.asset_host || Discourse.base_url_no_prefix)
|
url.start_with?(Discourse.asset_host || Discourse.base_url_no_prefix)
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
|
@ -280,7 +280,7 @@ class Wizard
|
||||||
|
|
||||||
EmojiSetSiteSetting.values.each do |set|
|
EmojiSetSiteSetting.values.each do |set|
|
||||||
imgs = emoji.map do |e|
|
imgs = emoji.map do |e|
|
||||||
"<img src='#{Discourse.base_uri}/images/emoji/#{set[:value]}/#{e}.png'>"
|
"<img src='#{Discourse.base_path}/images/emoji/#{set[:value]}/#{e}.png'>"
|
||||||
end
|
end
|
||||||
|
|
||||||
sets.add_choice(set[:value],
|
sets.add_choice(set[:value],
|
||||||
|
|
|
@ -184,7 +184,7 @@ module DiscourseNarrativeBot
|
||||||
end
|
end
|
||||||
|
|
||||||
def i18n_post_args(extra = {})
|
def i18n_post_args(extra = {})
|
||||||
{ base_uri: Discourse.base_uri }.merge(extra)
|
{ base_uri: Discourse.base_path }.merge(extra)
|
||||||
end
|
end
|
||||||
|
|
||||||
def valid_topic?(topic_id)
|
def valid_topic?(topic_id)
|
||||||
|
|
|
@ -11,14 +11,14 @@ module DiscourseNarrativeBot
|
||||||
begin: {
|
begin: {
|
||||||
init: {
|
init: {
|
||||||
next_state: :tutorial_bookmark,
|
next_state: :tutorial_bookmark,
|
||||||
next_instructions: Proc.new { I18n.t("#{I18N_KEY}.bookmark.instructions", base_uri: Discourse.base_uri) },
|
next_instructions: Proc.new { I18n.t("#{I18N_KEY}.bookmark.instructions", base_uri: Discourse.base_path) },
|
||||||
action: :say_hello
|
action: :say_hello
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
tutorial_bookmark: {
|
tutorial_bookmark: {
|
||||||
next_state: :tutorial_onebox,
|
next_state: :tutorial_onebox,
|
||||||
next_instructions: Proc.new { I18n.t("#{I18N_KEY}.onebox.instructions", base_uri: Discourse.base_uri) },
|
next_instructions: Proc.new { I18n.t("#{I18N_KEY}.onebox.instructions", base_uri: Discourse.base_path) },
|
||||||
|
|
||||||
bookmark: {
|
bookmark: {
|
||||||
action: :reply_to_bookmark
|
action: :reply_to_bookmark
|
||||||
|
@ -32,7 +32,7 @@ module DiscourseNarrativeBot
|
||||||
|
|
||||||
tutorial_onebox: {
|
tutorial_onebox: {
|
||||||
next_state: :tutorial_emoji,
|
next_state: :tutorial_emoji,
|
||||||
next_instructions: Proc.new { I18n.t("#{I18N_KEY}.emoji.instructions", base_uri: Discourse.base_uri) },
|
next_instructions: Proc.new { I18n.t("#{I18N_KEY}.emoji.instructions", base_uri: Discourse.base_path) },
|
||||||
|
|
||||||
reply: {
|
reply: {
|
||||||
action: :reply_to_onebox
|
action: :reply_to_onebox
|
||||||
|
@ -45,7 +45,7 @@ module DiscourseNarrativeBot
|
||||||
next_instructions: Proc.new {
|
next_instructions: Proc.new {
|
||||||
I18n.t("#{I18N_KEY}.mention.instructions",
|
I18n.t("#{I18N_KEY}.mention.instructions",
|
||||||
discobot_username: self.discobot_username,
|
discobot_username: self.discobot_username,
|
||||||
base_uri: Discourse.base_uri)
|
base_uri: Discourse.base_path)
|
||||||
},
|
},
|
||||||
reply: {
|
reply: {
|
||||||
action: :reply_to_emoji
|
action: :reply_to_emoji
|
||||||
|
@ -55,7 +55,7 @@ module DiscourseNarrativeBot
|
||||||
tutorial_mention: {
|
tutorial_mention: {
|
||||||
prerequisite: Proc.new { SiteSetting.enable_mentions },
|
prerequisite: Proc.new { SiteSetting.enable_mentions },
|
||||||
next_state: :tutorial_formatting,
|
next_state: :tutorial_formatting,
|
||||||
next_instructions: Proc.new { I18n.t("#{I18N_KEY}.formatting.instructions", base_uri: Discourse.base_uri) },
|
next_instructions: Proc.new { I18n.t("#{I18N_KEY}.formatting.instructions", base_uri: Discourse.base_path) },
|
||||||
|
|
||||||
reply: {
|
reply: {
|
||||||
action: :reply_to_mention
|
action: :reply_to_mention
|
||||||
|
@ -64,7 +64,7 @@ module DiscourseNarrativeBot
|
||||||
|
|
||||||
tutorial_formatting: {
|
tutorial_formatting: {
|
||||||
next_state: :tutorial_quote,
|
next_state: :tutorial_quote,
|
||||||
next_instructions: Proc.new { I18n.t("#{I18N_KEY}.quoting.instructions", base_uri: Discourse.base_uri) },
|
next_instructions: Proc.new { I18n.t("#{I18N_KEY}.quoting.instructions", base_uri: Discourse.base_path) },
|
||||||
|
|
||||||
reply: {
|
reply: {
|
||||||
action: :reply_to_formatting
|
action: :reply_to_formatting
|
||||||
|
@ -73,7 +73,7 @@ module DiscourseNarrativeBot
|
||||||
|
|
||||||
tutorial_quote: {
|
tutorial_quote: {
|
||||||
next_state: :tutorial_images,
|
next_state: :tutorial_images,
|
||||||
next_instructions: Proc.new { I18n.t("#{I18N_KEY}.images.instructions", base_uri: Discourse.base_uri) },
|
next_instructions: Proc.new { I18n.t("#{I18N_KEY}.images.instructions", base_uri: Discourse.base_path) },
|
||||||
|
|
||||||
reply: {
|
reply: {
|
||||||
action: :reply_to_quote
|
action: :reply_to_quote
|
||||||
|
@ -85,7 +85,7 @@ module DiscourseNarrativeBot
|
||||||
tutorial_images: {
|
tutorial_images: {
|
||||||
prerequisite: Proc.new { @user.has_trust_level?(SiteSetting.min_trust_to_post_embedded_media) },
|
prerequisite: Proc.new { @user.has_trust_level?(SiteSetting.min_trust_to_post_embedded_media) },
|
||||||
next_state: :tutorial_likes,
|
next_state: :tutorial_likes,
|
||||||
next_instructions: Proc.new { I18n.t("#{I18N_KEY}.likes.instructions", base_uri: Discourse.base_uri) },
|
next_instructions: Proc.new { I18n.t("#{I18N_KEY}.likes.instructions", base_uri: Discourse.base_path) },
|
||||||
reply: {
|
reply: {
|
||||||
action: :reply_to_image
|
action: :reply_to_image
|
||||||
},
|
},
|
||||||
|
@ -101,7 +101,7 @@ module DiscourseNarrativeBot
|
||||||
I18n.t("#{I18N_KEY}.flag.instructions",
|
I18n.t("#{I18N_KEY}.flag.instructions",
|
||||||
guidelines_url: url_helpers(:guidelines_url),
|
guidelines_url: url_helpers(:guidelines_url),
|
||||||
about_url: url_helpers(:about_index_url),
|
about_url: url_helpers(:about_index_url),
|
||||||
base_uri: Discourse.base_uri)
|
base_uri: Discourse.base_path)
|
||||||
},
|
},
|
||||||
like: {
|
like: {
|
||||||
action: :reply_to_likes
|
action: :reply_to_likes
|
||||||
|
@ -115,7 +115,7 @@ module DiscourseNarrativeBot
|
||||||
tutorial_flag: {
|
tutorial_flag: {
|
||||||
prerequisite: Proc.new { SiteSetting.allow_flagging_staff },
|
prerequisite: Proc.new { SiteSetting.allow_flagging_staff },
|
||||||
next_state: :tutorial_search,
|
next_state: :tutorial_search,
|
||||||
next_instructions: Proc.new { I18n.t("#{I18N_KEY}.search.instructions", base_uri: Discourse.base_uri) },
|
next_instructions: Proc.new { I18n.t("#{I18N_KEY}.search.instructions", base_uri: Discourse.base_path) },
|
||||||
flag: {
|
flag: {
|
||||||
action: :reply_to_flag
|
action: :reply_to_flag
|
||||||
},
|
},
|
||||||
|
|
|
@ -108,7 +108,7 @@ after_initialize do
|
||||||
private
|
private
|
||||||
|
|
||||||
def fetch_avatar(user)
|
def fetch_avatar(user)
|
||||||
avatar_url = UrlHelper.absolute(Discourse.base_uri + user.avatar_template.gsub('{size}', '250'))
|
avatar_url = UrlHelper.absolute(Discourse.base_path + user.avatar_template.gsub('{size}', '250'))
|
||||||
FileHelper.download(
|
FileHelper.download(
|
||||||
avatar_url.to_s,
|
avatar_url.to_s,
|
||||||
max_file_size: SiteSetting.max_image_size_kb.kilobytes,
|
max_file_size: SiteSetting.max_image_size_kb.kilobytes,
|
||||||
|
|
|
@ -745,7 +745,7 @@ describe DiscourseNarrativeBot::NewUserNarrative do
|
||||||
|
|
||||||
it "should use correct path to images on subfolder installs" do
|
it "should use correct path to images on subfolder installs" do
|
||||||
GlobalSetting.stubs(:relative_url_root).returns('/forum')
|
GlobalSetting.stubs(:relative_url_root).returns('/forum')
|
||||||
Discourse.stubs(:base_uri).returns("/forum")
|
Discourse.stubs(:base_path).returns("/forum")
|
||||||
|
|
||||||
post.update!(raw: skip_trigger)
|
post.update!(raw: skip_trigger)
|
||||||
|
|
||||||
|
|
|
@ -69,7 +69,7 @@ describe Oneboxer do
|
||||||
expect(onebox).to include(%{data-post="2"})
|
expect(onebox).to include(%{data-post="2"})
|
||||||
expect(onebox).to include(PrettyText.avatar_img(replier.avatar_template, "tiny"))
|
expect(onebox).to include(PrettyText.avatar_img(replier.avatar_template, "tiny"))
|
||||||
|
|
||||||
short_url = "#{Discourse.base_uri}/t/#{public_topic.id}"
|
short_url = "#{Discourse.base_path}/t/#{public_topic.id}"
|
||||||
expect(preview(short_url, user, public_category)).to include(public_topic.title)
|
expect(preview(short_url, user, public_category)).to include(public_topic.title)
|
||||||
|
|
||||||
onebox = preview(public_moderator_action.url, user, public_category)
|
onebox = preview(public_moderator_action.url, user, public_category)
|
||||||
|
|
|
@ -1363,7 +1363,7 @@ describe Post do
|
||||||
fab!(:attachment_upload_2) { Fabricate(:upload) }
|
fab!(:attachment_upload_2) { Fabricate(:upload) }
|
||||||
fab!(:attachment_upload_3) { Fabricate(:upload, extension: nil) }
|
fab!(:attachment_upload_3) { Fabricate(:upload, extension: nil) }
|
||||||
|
|
||||||
let(:base_url) { "#{Discourse.base_url_no_prefix}#{Discourse.base_uri}" }
|
let(:base_url) { "#{Discourse.base_url_no_prefix}#{Discourse.base_path}" }
|
||||||
let(:video_url) { "#{base_url}#{video_upload.url}" }
|
let(:video_url) { "#{base_url}#{video_upload.url}" }
|
||||||
let(:audio_url) { "#{base_url}#{audio_upload.url}" }
|
let(:audio_url) { "#{base_url}#{audio_upload.url}" }
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user