diff --git a/app/assets/javascripts/discourse/components/global-notice.js.es6 b/app/assets/javascripts/discourse/components/global-notice.js.es6 index 0b291384c6e..d3ae4235484 100644 --- a/app/assets/javascripts/discourse/components/global-notice.js.es6 +++ b/app/assets/javascripts/discourse/components/global-notice.js.es6 @@ -9,6 +9,10 @@ export default Ember.Component.extend(bufferedRender({ buildBuffer(buffer) { let notices = []; + if (this.session.get('safe_mode')) { + notices.push([I18n.t("safe_mode.enabled"), 'safe-mode']); + } + if (this.site.get("isReadOnly")) { notices.push([I18n.t("read_only_mode.enabled"), 'alert-read-only']); } diff --git a/app/controllers/safe_mode_controller.rb b/app/controllers/safe_mode_controller.rb new file mode 100644 index 00000000000..d414f141b7a --- /dev/null +++ b/app/controllers/safe_mode_controller.rb @@ -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 diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 8d313386cb9..07d7ce951c4 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -241,7 +241,18 @@ module ApplicationHelper end 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 def loading_admin? diff --git a/app/views/common/_discourse_javascript.html.erb b/app/views/common/_discourse_javascript.html.erb index c337c56a866..c214d5e1fda 100644 --- a/app/views/common/_discourse_javascript.html.erb +++ b/app/views/common/_discourse_javascript.html.erb @@ -52,6 +52,9 @@ Discourse.start(); Discourse.set('assetVersion','<%= Discourse.assets_digest %>'); 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 %>; <%- if SiteSetting.enable_s3_uploads %> <%- if SiteSetting.s3_cdn_url.present? %> diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 8cdb11cc514..178fd7cbd83 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -28,8 +28,12 @@ <%= script "vendor" %> <%= script "pretty-text-bundle" %> <%= script "application" %> + <%- if allow_plugins? %> <%= script "plugin" %> + <%- end %> + <%- if allow_third_party_plugins? %> <%= script "plugin-third-party" %> + <%- end %> <%- if staff? %> diff --git a/app/views/safe_mode/index.html.erb b/app/views/safe_mode/index.html.erb new file mode 100644 index 00000000000..4908bf23b3e --- /dev/null +++ b/app/views/safe_mode/index.html.erb @@ -0,0 +1,29 @@ +
+ <%= t 'safe_mode.description' %> +
++ +
++ +
++ +
++ <%= submit_tag t('safe_mode.enter'), class: 'btn btn-danger' %> +
+ <% end %> +We've re-sent the activation email to %{email}" + 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: title: "Discourse Setup" step: diff --git a/config/routes.rb b/config/routes.rb index 61f05947a3a..b511a21036b 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -699,6 +699,9 @@ Discourse::Application.routes.draw do post "/user-api-key/revoke" => "user_api_keys#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 end