Spiegel von
https://github.com/paviliondev/discourse-custom-wizard.git
synchronisiert 2024-11-09 20:02:54 +01:00
Ensure update avatar works
Dieser Commit ist enthalten in:
Ursprung
06e618ecbe
Commit
df8d40cf2b
5 geänderte Dateien mit 41 neuen und 27 gelöschten Zeilen
|
@ -15,7 +15,8 @@ export default Component.extend({
|
|||
routeTo: equal('action.type', 'route_to'),
|
||||
disableId: not('action.isNew'),
|
||||
groupPropertyTypes: selectKitContent(['id', 'name']),
|
||||
hasAdvanced: or('basicTopicFields', 'routeTo'),
|
||||
hasAdvanced: or('hasCustomFields', 'routeTo'),
|
||||
hasCustomFields: or('basicTopicFields', 'updateProfile'),
|
||||
|
||||
@on('didInsertElement')
|
||||
@observes('action.type')
|
||||
|
|
|
@ -32,8 +32,8 @@ function camelCase(string) {
|
|||
|
||||
const profileFields = [
|
||||
'name',
|
||||
'username',
|
||||
'email',
|
||||
'avatar',
|
||||
'date_of_birth',
|
||||
'title',
|
||||
'locale',
|
||||
|
@ -181,7 +181,7 @@ const advancedProperties = {
|
|||
function(map, type) {
|
||||
if (type === 'route_to') {
|
||||
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'];
|
||||
} else if (['create_topic', 'send_message'].indexOf(type) > -1) {
|
||||
map[type].push('skip_redirect');
|
||||
|
|
|
@ -138,11 +138,11 @@
|
|||
{{wizard-mapper
|
||||
inputs=action.profile_updates
|
||||
options=(hash
|
||||
pairConnector='set'
|
||||
single=true
|
||||
inputTypes='association'
|
||||
userFieldSelection='key'
|
||||
wizardFieldSelection='value'
|
||||
keyDefaultSelection='userField'
|
||||
keyPlaceholder='admin.wizard.action.update_profile.key'
|
||||
context='action'
|
||||
)}}
|
||||
</div>
|
||||
|
@ -238,7 +238,7 @@
|
|||
{{#if action.showAdvanced}}
|
||||
<div class="advanced-settings">
|
||||
|
||||
{{#if basicTopicFields}}
|
||||
{{#if hasCustomFields}}
|
||||
<div class="setting full field-mapper-setting">
|
||||
<div class="setting-label">
|
||||
<label>{{i18n 'admin.wizard.action.custom_fields.label'}}</label>
|
||||
|
|
|
@ -63,26 +63,36 @@ class CustomWizard::Action
|
|||
|
||||
def update_profile
|
||||
return unless (profile_updates = action['profile_updates']).length
|
||||
|
||||
attributes = { custom_fields: {} }
|
||||
|
||||
profile_updates.each do |pu|
|
||||
pair = field['pairs'].first
|
||||
field = mapper.map_field(pair['key'], pair['key_type'])
|
||||
value = mapper.map_field(pair['value'], pair['value_type'])
|
||||
|
||||
if field.include?("custom_field")
|
||||
attributes[:custom_fields][field] = value
|
||||
else
|
||||
attributes[field.to_sym] = value
|
||||
|
||||
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'])
|
||||
end
|
||||
end
|
||||
|
||||
if attributes.present?
|
||||
user_updater = UserUpdater.new(user, user)
|
||||
user_updater.update(attributes)
|
||||
params = add_custom_fields(params)
|
||||
|
||||
if params.present?
|
||||
UserUpdater.new(Discourse.system_user, user).update(params)
|
||||
|
||||
if params[:avatar].present?
|
||||
update_avatar(params[:avatar])
|
||||
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
|
||||
|
@ -220,11 +230,11 @@ class CustomWizard::Action
|
|||
keyArr = field[:key].split('.')
|
||||
value = field[:value]
|
||||
|
||||
if keyArr.length != 2 || keyArr.first === 'topic'
|
||||
if keyArr.first === 'topic'
|
||||
params[:topic_opts] ||= {}
|
||||
params[:topic_opts][:custom_fields] ||= {}
|
||||
params[:topic_opts][:custom_fields][keyArr.last] = value
|
||||
elsif keyArr.first === 'post'
|
||||
else
|
||||
params[:custom_fields] ||= {}
|
||||
params[:custom_fields][keyArr.last.to_sym] = value
|
||||
end
|
||||
|
@ -249,8 +259,6 @@ class CustomWizard::Action
|
|||
mapper.interpolate(action['post_template']) :
|
||||
data[action['post']]
|
||||
|
||||
params = add_custom_fields(params)
|
||||
|
||||
params
|
||||
add_custom_fields(params)
|
||||
end
|
||||
end
|
|
@ -1,8 +1,13 @@
|
|||
class CustomWizard::Mapper
|
||||
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']
|
||||
|
||||
def self.user_fields
|
||||
USER_FIELDS + PROFILE_FIELDS
|
||||
end
|
||||
|
||||
OPERATORS = {
|
||||
equal: '==',
|
||||
greater: '>',
|
||||
|
|
Laden …
In neuem Issue referenzieren