FEATURE: add site setting to include user associated account ids. (#18375)

By default, we won't include associated account ids in current user serializer. If the new hidden site setting `include_associated_account_ids` is enabled then we will add it in the serializer.
This commit is contained in:
Vinoth Kannan 2022-09-27 12:40:20 +05:30 committed by GitHub
parent 7152345ee7
commit 0b6c89dc62
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 33 additions and 0 deletions

View File

@ -58,6 +58,7 @@ class CurrentUserSerializer < BasicUserSerializer
:can_create_group,
:link_posting_access,
:external_id,
:associated_account_ids,
:top_category_ids,
:hide_profile_and_presence,
:groups,
@ -293,6 +294,20 @@ class CurrentUserSerializer < BasicUserSerializer
SiteSetting.enable_discourse_connect
end
def associated_account_ids
values = {}
object.user_associated_accounts.map do |user_associated_account|
values[user_associated_account.provider_name] = user_associated_account.provider_uid
end
values
end
def include_associated_account_ids?
SiteSetting.include_associated_account_ids
end
def second_factor_enabled
object.totp_enabled? || object.security_keys_enabled?
end

View File

@ -2018,6 +2018,9 @@ developer:
default: ""
allow_any: false
refresh: true
include_associated_account_ids:
default: false
hidden: true
embedding:
embed_by_username:

View File

@ -372,4 +372,19 @@ RSpec.describe CurrentUserSerializer do
expect(serializer.as_json[:redesigned_user_page_nav_enabled]).to eq(true)
end
end
describe '#associated_account_ids' do
before do
UserAssociatedAccount.create(user_id: user.id, provider_name: "twitter", provider_uid: "1", info: { nickname: "sam" })
end
it 'should not include associated account ids by default' do
expect(serializer.as_json[:associated_account_ids]).to be_nil
end
it 'should include associated account ids when site setting enabled' do
SiteSetting.include_associated_account_ids = true
expect(serializer.as_json[:associated_account_ids]).to eq({ "twitter" => "1" })
end
end
end