From 4312bbe1e7ce627c997920f7731f6a276d6c8291 Mon Sep 17 00:00:00 2001 From: David Taylor Date: Fri, 1 Nov 2019 09:50:31 +0000 Subject: [PATCH] FIX: Do not load plugin CSS/JS assets when disabled (#8275) Follow-up to 839916aa4901ab62fb84bcaf7d91c4354091f506 and 5bd6b70d985e2736f56d2bec6cce56bee0227b1f --- lib/discourse.rb | 2 +- spec/components/discourse_spec.rb | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/lib/discourse.rb b/lib/discourse.rb index 561a4e979fa..759a01a935a 100644 --- a/lib/discourse.rb +++ b/lib/discourse.rb @@ -216,7 +216,7 @@ module Discourse plugins.select do |plugin| next if args[:include_official] == false && plugin.metadata.official? next if args[:include_unofficial] == false && !plugin.metadata.official? - next if args[:include_disabled] == false && !plugin.enabled? + next if !args[:include_disabled] && !plugin.enabled? true end diff --git a/spec/components/discourse_spec.rb b/spec/components/discourse_spec.rb index 70559a5038d..705195d53cb 100644 --- a/spec/components/discourse_spec.rb +++ b/spec/components/discourse_spec.rb @@ -65,6 +65,33 @@ describe Discourse do end end + context 'plugins' do + let(:plugin_class) do + Class.new(Plugin::Instance) do + attr_accessor :enabled + def enabled? + @enabled + end + end + end + + let(:plugin1) { plugin_class.new.tap { |p| p.enabled = true } } + let(:plugin2) { plugin_class.new.tap { |p| p.enabled = false } } + + before { Discourse.plugins.append(plugin1, plugin2) } + after { Discourse.plugins.clear } + + it 'can find plugins correctly' do + expect(Discourse.plugins).to contain_exactly(plugin1, plugin2) + + # Exclude disabled plugins by default + expect(Discourse.find_plugins({})).to contain_exactly(plugin1) + + # Include disabled plugins when requested + expect(Discourse.find_plugins(include_disabled: true)).to contain_exactly(plugin1, plugin2) + end + end + context 'authenticators' do it 'returns inbuilt authenticators' do expect(Discourse.authenticators).to match_array(Discourse::BUILTIN_AUTH.map(&:authenticator))