Spiegel von
https://github.com/paviliondev/discourse-custom-wizard.git
synchronisiert 2024-11-10 04:12:53 +01:00
Profile action fixes
Dieser Commit ist enthalten in:
Ursprung
df8d40cf2b
Commit
5c33b4a621
4 geänderte Dateien mit 46 neuen und 16 gelöschten Zeilen
|
@ -31,7 +31,7 @@ export default Component.extend({
|
|||
});
|
||||
|
||||
selectionTypes.forEach(type => {
|
||||
if (options[`${type}Selection`]) {
|
||||
if (options[`${type}Selection`] !== undefined) {
|
||||
result[`${type}Selection`] = options[`${type}Selection`]
|
||||
} else {
|
||||
result[`${type}Selection`] = type === 'text' ? true : false;
|
||||
|
|
|
@ -36,6 +36,8 @@ const profileFields = [
|
|||
'avatar',
|
||||
'date_of_birth',
|
||||
'title',
|
||||
'profile_background',
|
||||
'card_background',
|
||||
'locale',
|
||||
'location',
|
||||
'website',
|
||||
|
|
|
@ -138,8 +138,9 @@
|
|||
{{wizard-mapper
|
||||
inputs=action.profile_updates
|
||||
options=(hash
|
||||
single=true
|
||||
singular=true
|
||||
inputTypes='association'
|
||||
textSelection='value'
|
||||
userFieldSelection='key'
|
||||
wizardFieldSelection='value'
|
||||
keyDefaultSelection='userField'
|
||||
|
@ -248,6 +249,7 @@
|
|||
{{wizard-mapper
|
||||
inputs=action.custom_fields
|
||||
options=(hash
|
||||
singular=true
|
||||
inputTypes='association'
|
||||
wizardFieldSelection='value'
|
||||
userFieldSelection='value'
|
||||
|
|
|
@ -63,15 +63,13 @@ class CustomWizard::Action
|
|||
|
||||
def update_profile
|
||||
return unless (profile_updates = action['profile_updates']).length
|
||||
|
||||
allowed_fields = CustomWizard::Mapper.user_fields + ['avatar']
|
||||
params = {}
|
||||
|
||||
profile_updates.first[:pairs].each do |pair|
|
||||
if allowed_fields.include?(pair['key'])
|
||||
key = pair['key']
|
||||
key = "#{key}_upload_url" if ['profile_background', 'card_background'].include?(key)
|
||||
params[key.to_sym] = mapper.map_field(pair['value'], pair['value_type'])
|
||||
if allowed_profile_fields.include?(pair['key'])
|
||||
key = cast_profile_key(pair['key']).to_sym
|
||||
value = mapper.map_field(pair['value'], pair['value_type'])
|
||||
params[key] = cast_profile_value(value, pair['key'])
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -85,14 +83,6 @@ class CustomWizard::Action
|
|||
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
|
||||
api_body = nil
|
||||
|
@ -261,4 +251,40 @@ class CustomWizard::Action
|
|||
|
||||
add_custom_fields(params)
|
||||
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
|
Laden …
In neuem Issue referenzieren