1
0
Fork 0

Profile action fixes

Dieser Commit ist enthalten in:
Angus McLeod 2020-04-08 00:18:12 +10:00
Ursprung df8d40cf2b
Commit 5c33b4a621
4 geänderte Dateien mit 46 neuen und 16 gelöschten Zeilen

Datei anzeigen

@ -31,7 +31,7 @@ export default Component.extend({
}); });
selectionTypes.forEach(type => { selectionTypes.forEach(type => {
if (options[`${type}Selection`]) { if (options[`${type}Selection`] !== undefined) {
result[`${type}Selection`] = options[`${type}Selection`] result[`${type}Selection`] = options[`${type}Selection`]
} else { } else {
result[`${type}Selection`] = type === 'text' ? true : false; result[`${type}Selection`] = type === 'text' ? true : false;

Datei anzeigen

@ -36,6 +36,8 @@ const profileFields = [
'avatar', 'avatar',
'date_of_birth', 'date_of_birth',
'title', 'title',
'profile_background',
'card_background',
'locale', 'locale',
'location', 'location',
'website', 'website',

Datei anzeigen

@ -138,8 +138,9 @@
{{wizard-mapper {{wizard-mapper
inputs=action.profile_updates inputs=action.profile_updates
options=(hash options=(hash
single=true singular=true
inputTypes='association' inputTypes='association'
textSelection='value'
userFieldSelection='key' userFieldSelection='key'
wizardFieldSelection='value' wizardFieldSelection='value'
keyDefaultSelection='userField' keyDefaultSelection='userField'
@ -248,6 +249,7 @@
{{wizard-mapper {{wizard-mapper
inputs=action.custom_fields inputs=action.custom_fields
options=(hash options=(hash
singular=true
inputTypes='association' inputTypes='association'
wizardFieldSelection='value' wizardFieldSelection='value'
userFieldSelection='value' userFieldSelection='value'

Datei anzeigen

@ -63,15 +63,13 @@ class CustomWizard::Action
def update_profile def update_profile
return unless (profile_updates = action['profile_updates']).length return unless (profile_updates = action['profile_updates']).length
allowed_fields = CustomWizard::Mapper.user_fields + ['avatar']
params = {} params = {}
profile_updates.first[:pairs].each do |pair| profile_updates.first[:pairs].each do |pair|
if allowed_fields.include?(pair['key']) if allowed_profile_fields.include?(pair['key'])
key = pair['key'] key = cast_profile_key(pair['key']).to_sym
key = "#{key}_upload_url" if ['profile_background', 'card_background'].include?(key) value = mapper.map_field(pair['value'], pair['value_type'])
params[key.to_sym] = mapper.map_field(pair['value'], pair['value_type']) params[key] = cast_profile_value(value, pair['key'])
end end
end end
@ -85,14 +83,6 @@ class CustomWizard::Action
end end
end end
end end
def update_avatar(upload)
user.create_user_avatar unless user.user_avatar
user.user_avatar.custom_upload_id = upload['id']
user.uploaded_avatar_id = upload['id']
user.save!
user.user_avatar.save!
end
def send_to_api def send_to_api
api_body = nil api_body = nil
@ -261,4 +251,40 @@ class CustomWizard::Action
add_custom_fields(params) add_custom_fields(params)
end end
def profile_url_fields
['profile_background', 'card_background']
end
def cast_profile_key(key)
if profile_url_fields.include?(key)
"#{key}_upload_url"
else
key
end
end
def cast_profile_value(value, key)
if profile_url_fields.include?(key)
value['url']
elsif key === 'avatar'
value['id']
else
value
end
end
def allowed_profile_fields
CustomWizard::Mapper.user_fields +
profile_url_fields +
['avatar']
end
def update_avatar(upload_id)
user.create_user_avatar unless user.user_avatar
user.user_avatar.custom_upload_id = upload_id
user.uploaded_avatar_id = upload_id
user.save!
user.user_avatar.save!
end
end end