mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 21:41:03 +08:00
FIX: preview theme not working consistently
Avoid flash, this makes debugging much simpler as well. Additionally URL now clearly shows you are previewing a theme.
This commit is contained in:
@ -5,10 +5,14 @@ class Admin::ThemesController < Admin::AdminController
|
|||||||
|
|
||||||
skip_before_action :check_xhr, only: [:show, :preview]
|
skip_before_action :check_xhr, only: [:show, :preview]
|
||||||
|
|
||||||
|
def self.whitelist_theme_key(user)
|
||||||
|
"whitelist_theme_key_#{user.id}"
|
||||||
|
end
|
||||||
|
|
||||||
def preview
|
def preview
|
||||||
@theme = Theme.find(params[:id])
|
@theme = Theme.find(params[:id])
|
||||||
|
$redis.setex(Admin::ThemesController.whitelist_theme_key(current_user), 60, @theme.key)
|
||||||
redirect_to path("/"), flash: { preview_theme_key: @theme.key }
|
redirect_to path("/?preview_theme_key=#{@theme.key}")
|
||||||
end
|
end
|
||||||
|
|
||||||
def upload_asset
|
def upload_asset
|
||||||
|
@ -307,7 +307,13 @@ class ApplicationController < ActionController::Base
|
|||||||
resolve_safe_mode
|
resolve_safe_mode
|
||||||
return if request.env[NO_CUSTOM]
|
return if request.env[NO_CUSTOM]
|
||||||
|
|
||||||
theme_key = flash[:preview_theme_key]
|
theme_key = nil
|
||||||
|
if (k = request[:preview_theme_key]) && current_user
|
||||||
|
# some extra security, only to use the magic param the key needs to be whitelisted
|
||||||
|
if k == $redis.get(::Admin::ThemesController.whitelist_theme_key(current_user))
|
||||||
|
theme_key = k
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
user_option = current_user&.user_option
|
user_option = current_user&.user_option
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user