Rename `SiteSetting#use_https` to `force_https`.

This commit is contained in:
Guo Xiang Tan 2016-06-27 17:26:43 +08:00
parent 83b08b87d5
commit 20359788dc
No known key found for this signature in database
GPG Key ID: 19C321C8952B0F72
16 changed files with 75 additions and 18 deletions

View File

@ -120,7 +120,7 @@ class UserAvatarsController < ApplicationController
def proxy_avatar(url)
if url[0..1] == "//"
url = (SiteSetting.use_https ? "https:" : "http:") + url
url = (SiteSetting.force_https ? "https:" : "http:") + url
end
sha = Digest::SHA1.hexdigest(url)

View File

@ -18,7 +18,7 @@ class About
end
def https
SiteSetting.use_https
SiteSetting.force_https
end
def title

View File

@ -23,6 +23,7 @@ class SiteSetting < ActiveRecord::Base
end
load_settings(File.join(Rails.root, 'config', 'site_settings.yml'))
setup_deprecated_methods
unless Rails.env.test? && ENV['LOAD_PLUGINS'] != "1"
Dir[File.join(Rails.root, "plugins", "*", "config", "settings.yml")].each do |file|
@ -85,7 +86,7 @@ class SiteSetting < ActiveRecord::Base
end
def self.scheme
use_https? ? "https" : "http"
force_https? ? "https" : "http"
end
def self.default_categories_selected
@ -108,7 +109,6 @@ class SiteSetting < ActiveRecord::Base
def self.email_polling_enabled?
SiteSetting.manual_polling_enabled? || SiteSetting.pop3_polling_enabled?
end
end
# == Schema Information

View File

@ -6,7 +6,7 @@ class Discourse::ForceHttpsMiddleware
end
def call(env)
env['rack.url_scheme'] = 'https' if SiteSetting.use_https
env['rack.url_scheme'] = 'https' if SiteSetting.force_https
@app.call(env)
end

View File

@ -765,7 +765,7 @@ de:
notification_email: "Die E-Mail-Adresse die als \"From:\" Absender aller wichtiger System-E-Mails benutzt wird. Die benutzte Domain sollte über korrekte SPF, DKIM und PTR Einträge verfügen, damit E-Mails sicher zugestellt werden können."
email_custom_headers: "Eine durch senkrechte Striche getrennte Liste von eigenen E-Mail Headerzeilen"
email_subject: "Format der Betreffzeile in Standard-E-Mails. Siehe https://meta.discourse.org/t/customize-subject-format-for-standard-emails/20801"
use_https: "Erzwinge HTTPS für deine Seite. ACHTUNG: aktiviere dies nicht, bevor HTTPS nicht vollständig eingerichtet ist und auf jeden Fall überall funktioniert! Hast du alle CDN-Netzwerke, alle Logins über Soziale Netzwerke, alle externe Logos / Abhängigkeiten geprüft, um sicherzustellen, dass sie auch alle HTTPS-kompatibel sind?"
force_https: "Erzwinge HTTPS für deine Seite. ACHTUNG: aktiviere dies nicht, bevor HTTPS nicht vollständig eingerichtet ist und auf jeden Fall überall funktioniert! Hast du alle CDN-Netzwerke, alle Logins über Soziale Netzwerke, alle externe Logos / Abhängigkeiten geprüft, um sicherzustellen, dass sie auch alle HTTPS-kompatibel sind?"
summary_score_threshold: "Mindestpunktzahl, die ein Beitrag benötigt, um in der \"Thema zusammenfassen\"-Ansicht zu erscheinen."
summary_posts_required: "Mindestanzahl an Beiträgen in einem Thema, bevor die \"Thema zusammenfassen\"-Funktion aktiviert wird."
summary_likes_required: "Mindestanzahl an \"Gefällt mir\" Wertungen in einem Thema, bevor die \"Thema zusammenfassen\" Funktion aktiviert wird."

View File

@ -865,7 +865,7 @@ en:
notification_email: "The from: email address used when sending all essential system emails. The domain specified here must have SPF, DKIM and reverse PTR records set correctly for email to arrive."
email_custom_headers: "A pipe-delimited list of custom email headers"
email_subject: "Customizable subject format for standard emails. See https://meta.discourse.org/t/customize-subject-format-for-standard-emails/20801"
use_https: "Force your site to use HTTPS only. WARNING: do NOT enable this until you verify HTTPS is fully set up and working absolutely everywhere! Did you check your CDN, all social logins, and any external logos / dependencies to make sure they are all HTTPS compatible, too?"
force_https: "Force your site to use HTTPS only. WARNING: do NOT enable this until you verify HTTPS is fully set up and working absolutely everywhere! Did you check your CDN, all social logins, and any external logos / dependencies to make sure they are all HTTPS compatible, too?"
summary_score_threshold: "The minimum score required for a post to be included in 'Summarize This Topic'"
summary_posts_required: "Minimum posts in a topic before 'Summarize This Topic' is enabled"
summary_likes_required: "Minimum likes in a topic before 'Summarize This Topic' is enabled"

View File

@ -776,7 +776,7 @@ es:
notification_email: "La dirección de correo electrónico \"remitente\", utilizada al enviar todos los emails esenciales de sistema. El dominio especificado debe tener correctamente configurados los registros SPF, DKIM y PTR inversos para que los emails se reciban correctamente."
email_custom_headers: "Lista de emails separados por una barra"
email_subject: "Formato de asunto personalizable para emails estándar. Mira https://meta.discourse.org/t/customize-subject-format-for-standard-emails/20801"
use_https: "Forzar al sitio a utilizar sólo HTTPS. AVISO: ¡NO actives esta opción a menos que verifiques completamente la configuración y funcione correctamente en todas partes! ¿Has verificado también que el CDN, los inicios de sesión social y cualquier logo externo / dependencia son compatibles con HTTPS?"
force_https: "Forzar al sitio a utilizar sólo HTTPS. AVISO: ¡NO actives esta opción a menos que verifiques completamente la configuración y funcione correctamente en todas partes! ¿Has verificado también que el CDN, los inicios de sesión social y cualquier logo externo / dependencia son compatibles con HTTPS?"
summary_score_threshold: "La puntuación mínima requerida para que un post sea incluido en el 'Resumen de este tema\""
summary_posts_required: "El mínimo número de posts en un tema para habilitar el 'Resumen de este tema'"
summary_likes_required: "Mínimo de \"me gusta\" en un tema para habilitar 'Resumen de este tema'"

View File

@ -786,7 +786,7 @@ pt:
notification_email: "Para: endereço de email usado ao enviar emails essenciais do sistema. O domínio especificado aqui deverá ter SPF, DKIM e registos PTR inversos configurados corretamente para a chegada do email."
email_custom_headers: "A lista delimitada por barras verticais de cabeçalhos de e-mail personalizados"
email_subject: "Formato de assunto personalizável para emails padrão. Veja https://meta.discourse.org/t/customize-subject-format-for-standard-emails/20801"
use_https: "Forçar o site a usar apenas HTTPS. ALERTA: NÃO active esta opção enquanto não verificar que o HTTPS está completamente configurado e funcional. Verificou a sua CDN, todos os logins por rede social, e quaisquer logos ou outras dependências externas para garantir que também são compatíveis com HTTPS?"
force_https: "Forçar o site a usar apenas HTTPS. ALERTA: NÃO active esta opção enquanto não verificar que o HTTPS está completamente configurado e funcional. Verificou a sua CDN, todos os logins por rede social, e quaisquer logos ou outras dependências externas para garantir que também são compatíveis com HTTPS?"
summary_score_threshold: "Pontuação mínima necessária para que uma mensagem seja incluída em 'Resumir Este Tópico'"
summary_posts_required: "Número mínimo de mensagens num tópico antes que 'Resumir Este Tópico' seja ativo."
summary_likes_required: "Número mínimo de gostos num tópico antes que 'Resumir Este Tópico' seja ativo."

View File

@ -760,7 +760,7 @@ trust:
client: true
security:
use_https: false
force_https: false
enable_escaped_fragments: true
allow_index_in_robots_txt: true
enable_noscript_support: true

View File

@ -0,0 +1,5 @@
class UseHttpsNameChangeInSiteSettings < ActiveRecord::Migration
def up
execute "UPDATE site_settings SET name = 'force_https' WHERE name = 'use_https'"
end
end

View File

@ -198,7 +198,7 @@ module Discourse
default_port = 80
protocol = "http"
if SiteSetting.use_https?
if SiteSetting.force_https?
protocol = "https"
default_port = 443
end

View File

@ -45,7 +45,7 @@ module Onebox
case route[:controller]
when 'uploads'
url.gsub!("http:", "https:") if SiteSetting.use_https
url.gsub!("http:", "https:") if SiteSetting.force_https
if File.extname(uri.path) =~ /^.(mov|mp4|webm|ogv)$/
return "<video width='100%' height='100%' controls><source src='#{url}'><a href='#{url}'>#{url}</a></video>"
elsif File.extname(uri.path) =~ /^.(mp3|ogg|wav)$/

View File

@ -453,6 +453,28 @@ module SiteSettingExtension
@validator_mapping[type_name]
end
DEPRECATED_SETTINGS = [
['use_https', 'force_https', '1.7']
]
def setup_deprecated_methods
DEPRECATED_SETTINGS.each do |old_setting, new_setting, version|
define_singleton_method old_setting do
logger.warn("`SiteSetting##{name}` has been deprecated and will be removed in the #{version} Release. Please use `SiteSetting##{new_setting}` instead")
self.public_send new_setting
end
define_singleton_method "#{old_setting}?" do
logger.warn("`SiteSetting##{name}?` has been deprecated and will be removed in the #{version} Release. Please use `SiteSetting##{new_setting}?` instead")
self.public_send "#{new_setting}?"
end
define_singleton_method "#{old_setting}=" do |val|
logger.warn("`SiteSetting##{name}=` has been deprecated and will be removed in the #{version} Release. Please use `SiteSetting##{new_setting}=` instead")
self.public_send "#{new_setting}=", val
end
end
end
def setup_methods(name)
clean_name = name.to_s.sub("?", "").to_sym
@ -488,4 +510,10 @@ module SiteSettingExtension
url
end
private
def logger
Rails.logger
end
end

View File

@ -18,7 +18,7 @@ describe Discourse do
context 'base_url' do
context 'when https is off' do
before do
SiteSetting.expects(:use_https?).returns(false)
SiteSetting.expects(:force_https?).returns(false)
end
it 'has a non https base url' do
@ -28,7 +28,7 @@ describe Discourse do
context 'when https is on' do
before do
SiteSetting.expects(:use_https?).returns(true)
SiteSetting.expects(:force_https?).returns(true)
end
it 'has a non-ssl base url' do

View File

@ -105,7 +105,7 @@ describe Email::Styles do
context "without https" do
before do
SiteSetting.stubs(:use_https).returns(false)
SiteSetting.stubs(:force_https).returns(false)
end
it "rewrites the href to have http" do
@ -126,7 +126,7 @@ describe Email::Styles do
context "with https" do
before do
SiteSetting.stubs(:use_https).returns(true)
SiteSetting.stubs(:force_https).returns(true)
end
it "rewrites the forum URL to have https" do

View File

@ -70,17 +70,41 @@ describe SiteSetting do
end
describe "scheme" do
before do
SiteSetting.force_https = true
end
it "returns http when ssl is disabled" do
SiteSetting.use_https = false
SiteSetting.force_https = false
expect(SiteSetting.scheme).to eq("http")
end
it "returns https when using ssl" do
SiteSetting.expects(:use_https).returns(true)
expect(SiteSetting.scheme).to eq("https")
end
end
context 'deprecated site settings' do
before do
SiteSetting.force_https = true
end
after do
SiteSetting.force_https = false
end
describe '#use_https' do
it 'should act as a proxy to the new methods' do
expect(SiteSetting.use_https).to eq(true)
expect(SiteSetting.use_https?).to eq(true)
SiteSetting.use_https = false
expect(SiteSetting.force_https).to eq(false)
expect(SiteSetting.force_https?).to eq(false)
end
end
end
end