From 642e3cca985bc004ba4dbd0692d16d5795e1298f Mon Sep 17 00:00:00 2001 From: Angus McLeod Date: Mon, 11 Nov 2019 09:48:26 +1100 Subject: [PATCH] FIX: reduce scope of ExtraLocalesController override --- plugin.rb | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/plugin.rb b/plugin.rb index 4ce2932e..659720b5 100644 --- a/plugin.rb +++ b/plugin.rb @@ -191,20 +191,25 @@ after_initialize do end end - ## TODO: We shouldn't be overriding the entire method here. Make this more lightweight. - add_to_class(:extra_locales_controller, :show) do - bundle = params[:bundle] - - unless URI(request.referer).path.include? '/w/' - raise Discourse::InvalidAccess.new if bundle !~ /^(admin|wizard)$/ || !current_user&.staff? - end + module CustomWizardExtraLocalesController + def show + if request.referer && URI(request.referer).path.include?('/w/') + bundle = params[:bundle] + + if params[:v]&.size == 32 + hash = ExtraLocalesController.bundle_js_hash(bundle) + immutable_for(1.year) if hash == params[:v] + end - if params[:v]&.size == 32 - hash = ExtraLocalesController.bundle_js_hash(bundle) - immutable_for(24.hours) if hash == params[:v] + render plain: ExtraLocalesController.bundle_js(bundle), content_type: "application/javascript" + else + super + end end - - render plain: ExtraLocalesController.bundle_js(bundle), content_type: "application/javascript" + end + + class ::ExtraLocalesController + prepend CustomWizardExtraLocalesController end DiscourseEvent.trigger(:custom_wizard_ready)