From 0903aa44bb3c6060979be3ea0ceef5710f5a90e4 Mon Sep 17 00:00:00 2001 From: David Taylor Date: Fri, 28 Feb 2020 10:53:11 +0000 Subject: [PATCH] FEATURE: Always disable customizations on the `/safe-mode` route (#9052) This makes it easier to enter safe mode when a customization has made the UI unusable --- app/controllers/safe_mode_controller.rb | 6 ++++++ spec/requests/safe_mode_controller_spec.rb | 12 ++++++++++++ 2 files changed, 18 insertions(+) diff --git a/app/controllers/safe_mode_controller.rb b/app/controllers/safe_mode_controller.rb index 76a93ebf59b..d0742eba102 100644 --- a/app/controllers/safe_mode_controller.rb +++ b/app/controllers/safe_mode_controller.rb @@ -3,6 +3,7 @@ class SafeModeController < ApplicationController layout 'no_ember' before_action :ensure_safe_mode_enabled + before_action :force_safe_mode_for_route skip_before_action :preload_json, :check_xhr @@ -29,4 +30,9 @@ class SafeModeController < ApplicationController raise Discourse::NotFound unless guardian.can_enable_safe_mode? end + def force_safe_mode_for_route + request.env[ApplicationController::NO_CUSTOM] = true + request.env[ApplicationController::NO_PLUGINS] = true + end + end diff --git a/spec/requests/safe_mode_controller_spec.rb b/spec/requests/safe_mode_controller_spec.rb index 542e3ed7d81..6bba0dad935 100644 --- a/spec/requests/safe_mode_controller_spec.rb +++ b/spec/requests/safe_mode_controller_spec.rb @@ -3,6 +3,18 @@ require 'rails_helper' RSpec.describe SafeModeController do + describe 'index' do + it 'never includes customizations' do + theme = Fabricate(:theme) + theme.set_field(target: :common, name: "header", value: "My Custom Header") + theme.save! + theme.set_default! + + get '/safe-mode' + expect(response.body).not_to include("My Custom Header") + end + end + describe 'enter' do context 'when no params are given' do it 'should redirect back to safe mode page' do