mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FEATURE: Add basic support for Safe Mode
In Safe Mode all JS extensions and site customizations are disabled. To access Safe Mode visit `sitename.org/safe-mode`
This commit is contained in:
parent
6397d935ce
commit
e2c87da42a
@ -9,6 +9,10 @@ export default Ember.Component.extend(bufferedRender({
|
|||||||
buildBuffer(buffer) {
|
buildBuffer(buffer) {
|
||||||
let notices = [];
|
let notices = [];
|
||||||
|
|
||||||
|
if (this.session.get('safe_mode')) {
|
||||||
|
notices.push([I18n.t("safe_mode.enabled"), 'safe-mode']);
|
||||||
|
}
|
||||||
|
|
||||||
if (this.site.get("isReadOnly")) {
|
if (this.site.get("isReadOnly")) {
|
||||||
notices.push([I18n.t("read_only_mode.enabled"), 'alert-read-only']);
|
notices.push([I18n.t("read_only_mode.enabled"), 'alert-read-only']);
|
||||||
}
|
}
|
||||||
|
20
app/controllers/safe_mode_controller.rb
Normal file
20
app/controllers/safe_mode_controller.rb
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
class SafeModeController < ApplicationController
|
||||||
|
layout 'no_ember'
|
||||||
|
skip_before_filter :preload_json, :check_xhr
|
||||||
|
|
||||||
|
def index
|
||||||
|
end
|
||||||
|
|
||||||
|
def enter
|
||||||
|
safe_mode = []
|
||||||
|
safe_mode << "no_custom" if params["no_customizations"] == "true"
|
||||||
|
safe_mode << "no_plugins" if params["no_plugins"] == "true"
|
||||||
|
safe_mode << "only_official" if params["only_official"] == "true"
|
||||||
|
|
||||||
|
if safe_mode.length > 0
|
||||||
|
redirect_to path("/?safe_mode=#{safe_mode.join("%2C")}")
|
||||||
|
else
|
||||||
|
redirect_to :index
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
@ -241,7 +241,18 @@ module ApplicationHelper
|
|||||||
end
|
end
|
||||||
|
|
||||||
def customization_disabled?
|
def customization_disabled?
|
||||||
session[:disable_customization]
|
safe_mode = params["safe_mode"]
|
||||||
|
session[:disable_customization] || (safe_mode && safe_mode.include?("no_custom"))
|
||||||
|
end
|
||||||
|
|
||||||
|
def allow_plugins?
|
||||||
|
safe_mode = params["safe_mode"]
|
||||||
|
!(safe_mode && safe_mode.include?("no_plugins"))
|
||||||
|
end
|
||||||
|
|
||||||
|
def allow_third_party_plugins?
|
||||||
|
safe_mode = params["safe_mode"]
|
||||||
|
!(safe_mode && (safe_mode.include?("no_plugins") || safe_mode.include?("only_official")))
|
||||||
end
|
end
|
||||||
|
|
||||||
def loading_admin?
|
def loading_admin?
|
||||||
|
@ -52,6 +52,9 @@
|
|||||||
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"] %>
|
||||||
|
Discourse.Session.currentProp("safe_mode", <%= params["safe_mode"].inspect.html_safe %>);
|
||||||
|
<%- end %>
|
||||||
Discourse.HighlightJSPath = <%= HighlightJs.path.inspect.html_safe %>;
|
Discourse.HighlightJSPath = <%= HighlightJs.path.inspect.html_safe %>;
|
||||||
<%- if SiteSetting.enable_s3_uploads %>
|
<%- if SiteSetting.enable_s3_uploads %>
|
||||||
<%- if SiteSetting.s3_cdn_url.present? %>
|
<%- if SiteSetting.s3_cdn_url.present? %>
|
||||||
|
@ -28,8 +28,12 @@
|
|||||||
<%= script "vendor" %>
|
<%= script "vendor" %>
|
||||||
<%= script "pretty-text-bundle" %>
|
<%= script "pretty-text-bundle" %>
|
||||||
<%= script "application" %>
|
<%= script "application" %>
|
||||||
|
<%- if allow_plugins? %>
|
||||||
<%= script "plugin" %>
|
<%= script "plugin" %>
|
||||||
|
<%- end %>
|
||||||
|
<%- if allow_third_party_plugins? %>
|
||||||
<%= script "plugin-third-party" %>
|
<%= script "plugin-third-party" %>
|
||||||
|
<%- end %>
|
||||||
|
|
||||||
<%- if staff? %>
|
<%- if staff? %>
|
||||||
<script src="<%= Discourse.base_uri %>/extra-locales/admin"></script>
|
<script src="<%= Discourse.base_uri %>/extra-locales/admin"></script>
|
||||||
|
29
app/views/safe_mode/index.html.erb
Normal file
29
app/views/safe_mode/index.html.erb
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
<div class='container safe-mode'>
|
||||||
|
<h2><%= t 'safe_mode.title'%></h2>
|
||||||
|
<%= form_tag(safe_mode_enter_path) do %>
|
||||||
|
<p>
|
||||||
|
<%= t 'safe_mode.description' %>
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
<label>
|
||||||
|
<%= check_box_tag 'no_customizations', true, true %>
|
||||||
|
<%= t 'safe_mode.no_customizations' %>
|
||||||
|
</label>
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
<label>
|
||||||
|
<%= check_box_tag 'only_official', true, true %>
|
||||||
|
<%= t 'safe_mode.only_official' %>
|
||||||
|
</label>
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
<label>
|
||||||
|
<%= check_box_tag 'no_plugins', true, true %>
|
||||||
|
<%= t 'safe_mode.no_plugins' %>
|
||||||
|
</label>
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
<%= submit_tag t('safe_mode.enter'), class: 'btn btn-danger' %>
|
||||||
|
</p>
|
||||||
|
<% end %>
|
||||||
|
</div>
|
@ -2308,6 +2308,10 @@ en:
|
|||||||
custom_message_template_forum: "Hey, you should join this forum!"
|
custom_message_template_forum: "Hey, you should join this forum!"
|
||||||
custom_message_template_topic: "Hey, I thought you might enjoy this topic!"
|
custom_message_template_topic: "Hey, I thought you might enjoy this topic!"
|
||||||
|
|
||||||
|
safe_mode:
|
||||||
|
enabled: "Safe mode is enabled, to exit safe mode close this browser window"
|
||||||
|
|
||||||
|
|
||||||
# This section is exported to the javascript for i18n in the admin section
|
# This section is exported to the javascript for i18n in the admin section
|
||||||
admin_js:
|
admin_js:
|
||||||
type_to_filter: "type to filter..."
|
type_to_filter: "type to filter..."
|
||||||
|
@ -3222,6 +3222,13 @@ en:
|
|||||||
title: "Resend Activation Email"
|
title: "Resend Activation Email"
|
||||||
message: "<p>We've re-sent the activation email to <b>%{email}</b>"
|
message: "<p>We've re-sent the activation email to <b>%{email}</b>"
|
||||||
|
|
||||||
|
safe_mode:
|
||||||
|
title: "Enter safe mode"
|
||||||
|
description: "Safe mode allows you to test your site without loading plugins or site customizations."
|
||||||
|
no_customizations: "Disable all site customizations"
|
||||||
|
only_official: "Disable unofficial plugins"
|
||||||
|
no_plugins: "Disable all plugins"
|
||||||
|
enter: "Enter Safe Mode"
|
||||||
wizard:
|
wizard:
|
||||||
title: "Discourse Setup"
|
title: "Discourse Setup"
|
||||||
step:
|
step:
|
||||||
|
@ -699,6 +699,9 @@ Discourse::Application.routes.draw do
|
|||||||
post "/user-api-key/revoke" => "user_api_keys#revoke"
|
post "/user-api-key/revoke" => "user_api_keys#revoke"
|
||||||
post "/user-api-key/undo-revoke" => "user_api_keys#undo_revoke"
|
post "/user-api-key/undo-revoke" => "user_api_keys#undo_revoke"
|
||||||
|
|
||||||
|
get "/safe-mode" => "safe_mode#index"
|
||||||
|
post "/safe-mode" => "safe_mode#enter", as: "safe_mode_enter"
|
||||||
|
|
||||||
get "*url", to: 'permalinks#show', constraints: PermalinkConstraint.new
|
get "*url", to: 'permalinks#show', constraints: PermalinkConstraint.new
|
||||||
|
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user