From 5d8dce986d64db377ea944f07ba7e0f2b3f3e70d Mon Sep 17 00:00:00 2001 From: Angus McLeod Date: Mon, 6 Nov 2017 19:50:19 +0800 Subject: [PATCH] Add existing profile values to fields associated with profile update actions --- lib/builder.rb | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/lib/builder.rb b/lib/builder.rb index ef6ffd65..9617ade9 100644 --- a/lib/builder.rb +++ b/lib/builder.rb @@ -61,6 +61,22 @@ class CustomWizard::Builder params[:value] = submission[f['id']] if submission[f['id']] end + if s['actions'].any? + profile_actions = s['actions'].select { |a| a['type'] === 'update_profile' } + if profile_actions.any? + profile_actions.each do |action| + if update = action['profile_updates'].select { |u| u['key'] === f['id'] }.first + attribute = update['value'] + if UserProfile.column_names.include? attribute + params[:value] = UserProfile.find_by(user_id: @wizard.user.id).send(attribute) + elsif User.column_names.include? attribute + params[:value] = User.find(@wizard.user.id).send(attribute) + end + end + end + end + end + field = step.add_field(params) if f['type'] === 'dropdown'