2019-05-03 06:17:27 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-11-21 13:46:02 +08:00
|
|
|
class SafeModeController < ApplicationController
|
|
|
|
layout 'no_ember'
|
2018-04-24 02:50:52 +08:00
|
|
|
before_action :ensure_safe_mode_enabled
|
2020-02-28 18:53:11 +08:00
|
|
|
before_action :force_safe_mode_for_route
|
2018-04-24 02:50:52 +08:00
|
|
|
|
2017-08-31 12:06:56 +08:00
|
|
|
skip_before_action :preload_json, :check_xhr
|
2016-11-21 13:46:02 +08:00
|
|
|
|
|
|
|
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
|
2017-11-13 12:59:51 +08:00
|
|
|
flash[:must_select] = true
|
2016-12-19 18:12:15 +08:00
|
|
|
redirect_to safe_mode_path
|
2016-11-21 13:46:02 +08:00
|
|
|
end
|
|
|
|
end
|
2018-04-24 02:50:52 +08:00
|
|
|
|
|
|
|
protected
|
|
|
|
|
|
|
|
def ensure_safe_mode_enabled
|
2018-04-25 23:46:54 +08:00
|
|
|
raise Discourse::NotFound unless guardian.can_enable_safe_mode?
|
2018-04-24 02:50:52 +08:00
|
|
|
end
|
|
|
|
|
2020-02-28 18:53:11 +08:00
|
|
|
def force_safe_mode_for_route
|
|
|
|
request.env[ApplicationController::NO_CUSTOM] = true
|
|
|
|
request.env[ApplicationController::NO_PLUGINS] = true
|
|
|
|
end
|
|
|
|
|
2016-11-21 13:46:02 +08:00
|
|
|
end
|