0
0
Fork 1
Spiegel von https://github.com/paviliondev/discourse-custom-wizard.git synchronisiert 2024-11-26 02:50:28 +01:00

Support custom user fields in profile update action

Dieser Commit ist enthalten in:
Angus McLeod 2020-04-19 19:48:58 +10:00
Ursprung 47722d13a3
Commit 1a5c66bf20

Datei anzeigen

@ -102,10 +102,16 @@ class CustomWizard::Action
params = {} params = {}
profile_updates.first[:pairs].each do |pair| profile_updates.first[:pairs].each do |pair|
if allowed_profile_fields.include?(pair['key']) if allowed_profile_field?(pair['key'])
key = cast_profile_key(pair['key']).to_sym key = cast_profile_key(pair['key'])
value = mapper.map_field(pair['value'], pair['value_type']) value = cast_profile_value(mapper.map_field(pair['value'], pair['value_type']), pair['key'])
params[key] = cast_profile_value(value, pair['key'])
if user_field?(pair['key'])
params[:custom_fields] ||= {}
params[:custom_fields][key] = value
else
params[key.to_sym] = value
end
end end
end end
@ -330,6 +336,15 @@ class CustomWizard::Action
['username', 'email', 'trust_level'].freeze ['username', 'email', 'trust_level'].freeze
end end
def allowed_profile_field?(field)
allowed_profile_fields.include?(field) || user_field?(field)
end
def user_field?(field)
field.to_s.include?(::User::USER_FIELD_PREFIX) &&
::UserField.exists?(field.split('_').last.to_i)
end
def allowed_profile_fields def allowed_profile_fields
CustomWizard::Mapper.user_fields.select { |f| profile_excluded_fields.exclude?(f) } + CustomWizard::Mapper.user_fields.select { |f| profile_excluded_fields.exclude?(f) } +
profile_url_fields + profile_url_fields +