Skip to content

A platform for community discussion. Free, open, simple.

FIX: Include auth_providers for anonymous users when login_required

David Tayloraa9a9a5a7259
diff --git a/app/models/site.rb b/app/models/site.rb
index ec5cec19d4f..e6a0accb3d9 100644
--- a/app/models/site.rb
+++ b/app/models/site.rb
@@ -91,6 +91,9 @@ class Site
filters: Discourse.filters.map(&:to_s),
user_fields: UserField.all.map do |userfield|
UserFieldSerializer.new(userfield, root: false, scope: guardian)
+ end,
+ auth_providers: Discourse.enabled_auth_providers.map do |provider|
+ AuthProviderSerializer.new(provider, root: false, scope: guardian)
end
}.to_json
end
diff --git a/spec/models/site_spec.rb b/spec/models/site_spec.rb
index 7d6127d0add..ecb3d4f8f04 100644
--- a/spec/models/site_spec.rb
+++ b/spec/models/site_spec.rb
@@ -69,7 +69,16 @@ describe Site do
it "includes all enabled authentication providers" do
SiteSetting.enable_twitter_logins = true
SiteSetting.enable_facebook_logins = true
- expect(Site.new(Guardian.new).auth_providers.map(&:name)).to contain_exactly('facebook', 'twitter')
+ data = JSON.parse(Site.json_for(Guardian.new))
+ expect(data["auth_providers"].map { |a| a["name"] }).to contain_exactly('facebook', 'twitter')
+ end
+
+ it "includes all enabled authentication providers for anon when login_required" do
+ SiteSetting.login_required = true
+ SiteSetting.enable_twitter_logins = true
+ SiteSetting.enable_facebook_logins = true
+ data = JSON.parse(Site.json_for(Guardian.new))
+ expect(data["auth_providers"].map { |a| a["name"] }).to contain_exactly('facebook', 'twitter')
end
end