DEV: Relax auth provider registration restrictions for plugins (#24095)

In the past we would build the stack of Omniauth providers at boot, which meant that plugins had to register any authenticators in the root of their plugin.rb (i.e. not in an `after_initialize` block). This could be frustrating because many features are not available that early in boot (e.g. Zeitwerk autoloading).

Now that we build the omniauth strategy stack 'just in time', it is safe for plugins to register their auth methods in an `after_initialize` block. This commit relaxes the old restrictions so that plugin authors have the option to move things around.
This commit is contained in:
David Taylor
2023-10-26 10:54:30 +01:00
committed by GitHub
parent 8438aed727
commit c88303bb27
3 changed files with 5 additions and 20 deletions

View File

@ -218,14 +218,14 @@ RSpec.describe Plugin::Instance do
# No enabled_site_setting
authenticator = SimpleAuthenticator.new
plugin.auth_provider(authenticator: authenticator)
plugin.notify_before_auth
plugin.notify_after_initialize
expect(authenticator.enabled?).to eq(true)
# With enabled site setting
plugin = Plugin::Instance.new
authenticator = SimpleAuthenticator.new
plugin.auth_provider(enabled_setting: "enable_badges", authenticator: authenticator)
plugin.notify_before_auth
plugin.notify_after_initialize
expect(authenticator.enabled?).to eq(false)
# Defines own method
@ -241,7 +241,7 @@ RSpec.describe Plugin::Instance do
end
.new
plugin.auth_provider(enabled_setting: "enable_badges", authenticator: authenticator)
plugin.notify_before_auth
plugin.notify_after_initialize
expect(authenticator.enabled?).to eq(false)
end
@ -271,7 +271,7 @@ RSpec.describe Plugin::Instance do
plugin = plugin_from_fixtures("my_plugin")
plugin.activate!
expect(DiscoursePluginRegistry.auth_providers.count).to eq(0)
plugin.notify_before_auth
plugin.notify_after_initialize
expect(DiscoursePluginRegistry.auth_providers.count).to eq(1)
auth_provider = DiscoursePluginRegistry.auth_providers.to_a[0]
expect(auth_provider.authenticator.name).to eq("facebook")