FEATURE: Allow safe mode to be disabled

This commit is contained in:
Robin Ward 2018-04-23 14:50:52 -04:00
parent b449c47bdd
commit fd14ee4797
6 changed files with 25 additions and 2 deletions

View File

@ -299,6 +299,8 @@ class ApplicationController < ActionController::Base
SAFE_MODE = "safe_mode" SAFE_MODE = "safe_mode"
def resolve_safe_mode def resolve_safe_mode
return unless SiteSetting.enable_safe_mode?
safe_mode = params[SAFE_MODE] safe_mode = params[SAFE_MODE]
if safe_mode if safe_mode
request.env[NO_CUSTOM] = !!safe_mode.include?(NO_CUSTOM) request.env[NO_CUSTOM] = !!safe_mode.include?(NO_CUSTOM)

View File

@ -1,5 +1,7 @@
class SafeModeController < ApplicationController class SafeModeController < ApplicationController
layout 'no_ember' layout 'no_ember'
before_action :ensure_safe_mode_enabled
skip_before_action :preload_json, :check_xhr skip_before_action :preload_json, :check_xhr
def index def index
@ -18,4 +20,11 @@ class SafeModeController < ApplicationController
redirect_to safe_mode_path redirect_to safe_mode_path
end end
end end
protected
def ensure_safe_mode_enabled
raise Discourse::NotFound unless SiteSetting.enable_safe_mode?
end
end end

View File

@ -50,7 +50,7 @@
Discourse.start(); Discourse.start();
Discourse.set('assetVersion','<%= Discourse.assets_digest %>'); Discourse.set('assetVersion','<%= Discourse.assets_digest %>');
Discourse.Session.currentProp("disableCustomCSS", <%= loading_admin? %>); Discourse.Session.currentProp("disableCustomCSS", <%= loading_admin? %>);
<%- if params["safe_mode"] %> <%- if SiteSetting.enable_safe_mode? && params["safe_mode"] %>
Discourse.Session.currentProp("safe_mode", <%= normalized_safe_mode.inspect.html_safe %>); Discourse.Session.currentProp("safe_mode", <%= normalized_safe_mode.inspect.html_safe %>);
<%- end %> <%- end %>
Discourse.HighlightJSPath = <%= HighlightJs.path.inspect.html_safe %>; Discourse.HighlightJSPath = <%= HighlightJs.path.inspect.html_safe %>;

View File

@ -1259,6 +1259,7 @@ en:
top_topics_formula_least_likes_per_post_multiplier: "value of least likes per post multiplier (n) in top topics formula: `log(views_count) * 2 + op_likes_count * 0.5 + LEAST(likes_count / posts_count, (n)) + 10 + log(posts_count)`" top_topics_formula_least_likes_per_post_multiplier: "value of least likes per post multiplier (n) in top topics formula: `log(views_count) * 2 + op_likes_count * 0.5 + LEAST(likes_count / posts_count, (n)) + 10 + log(posts_count)`"
rebake_old_posts_count: "Number of old posts to be rebaked every 15 minutes." rebake_old_posts_count: "Number of old posts to be rebaked every 15 minutes."
enable_safe_mode: "Allow users to enter safe mode to debug plugins."
rate_limit_create_topic: "After creating a topic, users must wait (n) seconds before creating another topic." rate_limit_create_topic: "After creating a topic, users must wait (n) seconds before creating another topic."
rate_limit_create_post: "After posting, users must wait (n) seconds before creating another post." rate_limit_create_post: "After posting, users must wait (n) seconds before creating another post."

View File

@ -1201,6 +1201,9 @@ developer:
bootstrap_error_pages: bootstrap_error_pages:
hidden: true hidden: true
default: false default: false
enable_safe_mode:
default: true
client: true
embedding: embedding:
feed_polling_enabled: feed_polling_enabled:

View File

@ -5,9 +5,17 @@ RSpec.describe SafeModeController do
context 'when no params are given' do context 'when no params are given' do
it 'should redirect back to safe mode page' do it 'should redirect back to safe mode page' do
post '/safe-mode' post '/safe-mode'
expect(response.status).to redirect_to(safe_mode_path) expect(response.status).to redirect_to(safe_mode_path)
end end
end end
context 'when safe mode is not enabled' do
it 'should raise an error' do
SiteSetting.enable_safe_mode = false
post '/safe-mode'
expect(response.status).to eq(404)
end
end
end end
end end