1
0
Fork 0

FIX: Ensure user_email and user_option attributes are handled properly (#119)

Dieser Commit ist enthalten in:
Angus McLeod 2021-06-15 16:18:17 +10:00 committet von GitHub
Ursprung af3e61fe75
Commit 58b3bc13c9
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 4AEE18F83AFDEB23
3 geänderte Dateien mit 67 neuen und 36 gelöschten Zeilen

Datei anzeigen

@ -5,20 +5,27 @@ class CustomWizard::Mapper
USER_FIELDS = [
'name',
'username',
'email',
'date_of_birth',
'title',
'locale',
'trust_level',
'email'
]
USER_OPTION_FIELDS = [
'email_level',
'email_messages_level',
'email_digests'
]
PROFILE_FIELDS = ['location', 'website', 'bio_raw']
PROFILE_FIELDS = [
'location',
'website',
'bio_raw'
]
def self.user_fields
USER_FIELDS + PROFILE_FIELDS
USER_FIELDS + USER_OPTION_FIELDS + PROFILE_FIELDS
end
OPERATORS = {
@ -197,11 +204,15 @@ class CustomWizard::Mapper
def map_user_field(value)
if value.include?(User::USER_FIELD_PREFIX)
UserCustomField.where(user_id: user.id, name: value).pluck(:value).first
user.custom_fields[value]
elsif PROFILE_FIELDS.include?(value)
UserProfile.find_by(user_id: user.id).send(value)
user.user_profile.send(value)
elsif USER_FIELDS.include?(value)
User.find(user.id).send(value)
user.send(value)
elsif USER_OPTION_FIELDS.include?(value)
user.user_option.send(value)
else
nil
end
end
@ -217,19 +228,11 @@ class CustomWizard::Mapper
return string if string.blank?
if opts[:user]
string.gsub!(/u\{(.*?)\}/) do |match|
result = ''
result = user.send($1) if USER_FIELDS.include?($1)
result = user.user_profile.send($1) if PROFILE_FIELDS.include?($1)
result
end
string.gsub!(/u\{(.*?)\}/) { |match| map_user_field($1) || '' }
end
if opts[:wizard]
string.gsub!(/w\{(.*?)\}/) do |match|
value = recurse(data, [*$1.split('.')])
value.present? ? value : ''
end
string.gsub!(/w\{(.*?)\}/) { |match| recurse(data, [*$1.split('.')]) || '' }
end
if opts[:value]

Datei anzeigen

@ -229,7 +229,8 @@ describe CustomWizard::Mapper do
).perform).to eq("value 2")
end
it "interpolates user fields" do
context "interpolates" do
it "user fields" do
expect(CustomWizard::Mapper.new(
inputs: inputs['interpolate_user_field'],
data: data,
@ -237,21 +238,32 @@ describe CustomWizard::Mapper do
).perform).to eq("Name: Angus")
end
it "interpolates wizard fields" do
it "user emails" do
expect(CustomWizard::Mapper.new(
inputs: inputs['interpolate_wizard_field'],
inputs: inputs['interpolate_user_email'],
data: data,
user: user1
).perform).to eq("Input 1: value 1")
).perform).to eq("Email: angus@email.com")
end
it "interpolates date" do
it "user options" do
user1.user_option.update_columns(email_level: UserOption.email_level_types[:never])
expect(CustomWizard::Mapper.new(
inputs: inputs['interpolate_user_option'],
data: data,
user: user1
).perform).to eq("Email Level: #{UserOption.email_level_types[:never]}")
end
it "date" do
expect(CustomWizard::Mapper.new(
inputs: inputs['interpolate_timestamp'],
data: data,
user: user1
).perform).to eq("Time: #{Time.now.strftime("%B %-d, %Y")}")
end
end
it "handles greater than pairs" do
expect(CustomWizard::Mapper.new(

Datei anzeigen

@ -57,6 +57,22 @@
"output": "Name: u{name}"
}
],
"interpolate_user_email": [
{
"type": "assignment",
"output_type": "text",
"output_connector": "set",
"output": "Email: u{email}"
}
],
"interpolate_user_option": [
{
"type": "assignment",
"output_type": "text",
"output_connector": "set",
"output": "Email Level: u{email_level}"
}
],
"interpolate_wizard_field": [
{
"type": "assignment",