From e066ee4b00443864d8052390661a15c53234cddc Mon Sep 17 00:00:00 2001 From: Angus McLeod Date: Mon, 23 Nov 2020 10:11:45 +1100 Subject: [PATCH] Revert "Remove unused ExtraLocaleController extension" This reverts commit 37c18ff3242a3e80673020de02d888c20a34c167. --- extensions/extra_locales_controller.rb | 16 ++++++++++++ plugin.rb | 2 ++ .../extra_locales_controller_spec.rb | 26 +++++++++++++++++++ 3 files changed, 44 insertions(+) create mode 100644 extensions/extra_locales_controller.rb create mode 100644 spec/extensions/extra_locales_controller_spec.rb diff --git a/extensions/extra_locales_controller.rb b/extensions/extra_locales_controller.rb new file mode 100644 index 00000000..31a9f488 --- /dev/null +++ b/extensions/extra_locales_controller.rb @@ -0,0 +1,16 @@ +module ExtraLocalesControllerCustomWizard + 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 + + render plain: ::ExtraLocalesController.bundle_js(bundle), content_type: "application/javascript" + else + super + end + end +end \ No newline at end of file diff --git a/plugin.rb b/plugin.rb index 5454c4d4..4eb89d7b 100644 --- a/plugin.rb +++ b/plugin.rb @@ -77,6 +77,7 @@ after_initialize do ../serializers/custom_wizard/wizard_step_serializer.rb ../serializers/custom_wizard/wizard_serializer.rb ../serializers/custom_wizard/log_serializer.rb + ../extensions/extra_locales_controller.rb ../extensions/invites_controller.rb ../extensions/users_controller.rb ../extensions/wizard_field.rb @@ -157,6 +158,7 @@ after_initialize do redirect_to_wizard_if_required if current_user end + ::ExtraLocalesController.prepend ExtraLocalesControllerCustomWizard ::InvitesController.prepend InvitesControllerCustomWizard ::UsersController.prepend CustomWizardUsersController ::Wizard::Field.prepend CustomWizardFieldExtension diff --git a/spec/extensions/extra_locales_controller_spec.rb b/spec/extensions/extra_locales_controller_spec.rb new file mode 100644 index 00000000..e12b5f04 --- /dev/null +++ b/spec/extensions/extra_locales_controller_spec.rb @@ -0,0 +1,26 @@ +require 'rails_helper' + +describe ExtraLocalesControllerCustomWizard, type: :request do + before do + CustomWizard::Template.save( + JSON.parse(File.open( + "#{Rails.root}/plugins/discourse-custom-wizard/spec/fixtures/wizard.json" + ).read), + skip_jobs: true) + end + + before do + @controller = ExtraLocalesController.new + end + + it "returns locales when requested by wizard" do + @controller.request = ActionController::TestRequest.create(@controller.class) + @controller.request.env['HTTP_REFERER'] = "/w/super-mega-fun-wizard" + + expect( + ExtraLocalesController.url("wizard") + ).to eq( + "#{Discourse.base_path}/extra-locales/wizard?v=#{ExtraLocalesController.bundle_js_hash("wizard")}" + ) + end +end \ No newline at end of file