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:
parent
7152345ee7
commit
0b6c89dc62
|
@ -58,6 +58,7 @@ class CurrentUserSerializer < BasicUserSerializer
|
||||||
:can_create_group,
|
:can_create_group,
|
||||||
:link_posting_access,
|
:link_posting_access,
|
||||||
:external_id,
|
:external_id,
|
||||||
|
:associated_account_ids,
|
||||||
:top_category_ids,
|
:top_category_ids,
|
||||||
:hide_profile_and_presence,
|
:hide_profile_and_presence,
|
||||||
:groups,
|
:groups,
|
||||||
|
@ -293,6 +294,20 @@ class CurrentUserSerializer < BasicUserSerializer
|
||||||
SiteSetting.enable_discourse_connect
|
SiteSetting.enable_discourse_connect
|
||||||
end
|
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
|
def second_factor_enabled
|
||||||
object.totp_enabled? || object.security_keys_enabled?
|
object.totp_enabled? || object.security_keys_enabled?
|
||||||
end
|
end
|
||||||
|
|
|
@ -2018,6 +2018,9 @@ developer:
|
||||||
default: ""
|
default: ""
|
||||||
allow_any: false
|
allow_any: false
|
||||||
refresh: true
|
refresh: true
|
||||||
|
include_associated_account_ids:
|
||||||
|
default: false
|
||||||
|
hidden: true
|
||||||
|
|
||||||
embedding:
|
embedding:
|
||||||
embed_by_username:
|
embed_by_username:
|
||||||
|
|
|
@ -372,4 +372,19 @@ RSpec.describe CurrentUserSerializer do
|
||||||
expect(serializer.as_json[:redesigned_user_page_nav_enabled]).to eq(true)
|
expect(serializer.as_json[:redesigned_user_page_nav_enabled]).to eq(true)
|
||||||
end
|
end
|
||||||
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
|
end
|
||||||
|
|
Loading…
Reference in New Issue