1
0
Fork 0

Ensure update avatar works

Dieser Commit ist enthalten in:
Angus McLeod 2020-04-07 23:33:11 +10:00
Ursprung 06e618ecbe
Commit df8d40cf2b
5 geänderte Dateien mit 41 neuen und 27 gelöschten Zeilen

Datei anzeigen

@ -15,7 +15,8 @@ export default Component.extend({
routeTo: equal('action.type', 'route_to'), routeTo: equal('action.type', 'route_to'),
disableId: not('action.isNew'), disableId: not('action.isNew'),
groupPropertyTypes: selectKitContent(['id', 'name']), groupPropertyTypes: selectKitContent(['id', 'name']),
hasAdvanced: or('basicTopicFields', 'routeTo'), hasAdvanced: or('hasCustomFields', 'routeTo'),
hasCustomFields: or('basicTopicFields', 'updateProfile'),
@on('didInsertElement') @on('didInsertElement')
@observes('action.type') @observes('action.type')

Datei anzeigen

@ -32,8 +32,8 @@ function camelCase(string) {
const profileFields = [ const profileFields = [
'name', 'name',
'username',
'email', 'email',
'avatar',
'date_of_birth', 'date_of_birth',
'title', 'title',
'locale', 'locale',
@ -181,7 +181,7 @@ const advancedProperties = {
function(map, type) { function(map, type) {
if (type === 'route_to') { if (type === 'route_to') {
map[type] = ['code']; map[type] = ['code'];
} else if (['create_topic', 'send_message', 'open_composer'].indexOf(type) > -1) { } else if (['create_topic', 'send_message', 'open_composer', 'update_profile'].indexOf(type) > -1) {
map[type] = ['custom_fields']; map[type] = ['custom_fields'];
} else if (['create_topic', 'send_message'].indexOf(type) > -1) { } else if (['create_topic', 'send_message'].indexOf(type) > -1) {
map[type].push('skip_redirect'); map[type].push('skip_redirect');

Datei anzeigen

@ -138,11 +138,11 @@
{{wizard-mapper {{wizard-mapper
inputs=action.profile_updates inputs=action.profile_updates
options=(hash options=(hash
pairConnector='set' single=true
inputTypes='association'
userFieldSelection='key' userFieldSelection='key'
wizardFieldSelection='value' wizardFieldSelection='value'
keyDefaultSelection='userField' keyDefaultSelection='userField'
keyPlaceholder='admin.wizard.action.update_profile.key'
context='action' context='action'
)}} )}}
</div> </div>
@ -238,7 +238,7 @@
{{#if action.showAdvanced}} {{#if action.showAdvanced}}
<div class="advanced-settings"> <div class="advanced-settings">
{{#if basicTopicFields}} {{#if hasCustomFields}}
<div class="setting full field-mapper-setting"> <div class="setting full field-mapper-setting">
<div class="setting-label"> <div class="setting-label">
<label>{{i18n 'admin.wizard.action.custom_fields.label'}}</label> <label>{{i18n 'admin.wizard.action.custom_fields.label'}}</label>

Datei anzeigen

@ -63,26 +63,36 @@ 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
attributes = { custom_fields: {} } allowed_fields = CustomWizard::Mapper.user_fields + ['avatar']
params = {}
profile_updates.each do |pu|
pair = field['pairs'].first profile_updates.first[:pairs].each do |pair|
field = mapper.map_field(pair['key'], pair['key_type']) if allowed_fields.include?(pair['key'])
value = mapper.map_field(pair['value'], pair['value_type']) key = pair['key']
key = "#{key}_upload_url" if ['profile_background', 'card_background'].include?(key)
if field.include?("custom_field") params[key.to_sym] = mapper.map_field(pair['value'], pair['value_type'])
attributes[:custom_fields][field] = value
else
attributes[field.to_sym] = value
end end
end end
if attributes.present? params = add_custom_fields(params)
user_updater = UserUpdater.new(user, user)
user_updater.update(attributes) if params.present?
UserUpdater.new(Discourse.system_user, user).update(params)
if params[:avatar].present?
update_avatar(params[:avatar])
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
@ -220,11 +230,11 @@ class CustomWizard::Action
keyArr = field[:key].split('.') keyArr = field[:key].split('.')
value = field[:value] value = field[:value]
if keyArr.length != 2 || keyArr.first === 'topic' if keyArr.first === 'topic'
params[:topic_opts] ||= {} params[:topic_opts] ||= {}
params[:topic_opts][:custom_fields] ||= {} params[:topic_opts][:custom_fields] ||= {}
params[:topic_opts][:custom_fields][keyArr.last] = value params[:topic_opts][:custom_fields][keyArr.last] = value
elsif keyArr.first === 'post' else
params[:custom_fields] ||= {} params[:custom_fields] ||= {}
params[:custom_fields][keyArr.last.to_sym] = value params[:custom_fields][keyArr.last.to_sym] = value
end end
@ -249,8 +259,6 @@ class CustomWizard::Action
mapper.interpolate(action['post_template']) : mapper.interpolate(action['post_template']) :
data[action['post']] data[action['post']]
params = add_custom_fields(params) add_custom_fields(params)
params
end end
end end

Datei anzeigen

@ -1,8 +1,13 @@
class CustomWizard::Mapper class CustomWizard::Mapper
attr_accessor :inputs, :data, :user attr_accessor :inputs, :data, :user
USER_FIELDS = ['name', 'username', 'email', 'date_of_birth', 'title', 'locale', 'trust_level'] USER_FIELDS = ['name', 'email', 'date_of_birth', 'title', 'locale', 'trust_level']
PROFILE_FIELDS = ['location', 'website', 'bio_raw'] PROFILE_FIELDS = ['location', 'website', 'bio_raw']
def self.user_fields
USER_FIELDS + PROFILE_FIELDS
end
OPERATORS = { OPERATORS = {
equal: '==', equal: '==',
greater: '>', greater: '>',