1
0
Fork 0
Dieser Commit ist enthalten in:
jumagura 2023-09-21 22:39:29 -04:00
Ursprung adfffb4d08
Commit eeb99d1507

Datei anzeigen

@ -36,7 +36,7 @@ class CustomWizard::Action
end end
if creates_post? && @result.success? if creates_post? && @result.success?
@result.handler.enqueue_jobs @result.handler.enqueue_jobs
end end
if @result.success? && @result.output.present? if @result.success? && @result.output.present?
@ -92,10 +92,10 @@ class CustomWizard::Action
def send_message def send_message
if action['required'].present? if action['required'].present?
required = CustomWizard::Mapper.new( required = CustomWizard::Mapper.new(
inputs: action['required'], inputs: action['required'],
data: mapper_data, data: mapper_data,
user: user user: user
).perform ).perform
if required.blank? if required.blank?
log_error("required input not present") log_error("required input not present")
@ -107,11 +107,11 @@ class CustomWizard::Action
params.delete(:tags) unless user_can_tag params.delete(:tags) unless user_can_tag
targets = CustomWizard::Mapper.new( targets = CustomWizard::Mapper.new(
inputs: action['recipient'], inputs: action['recipient'],
data: mapper_data, data: mapper_data,
user: user, user: user,
multiple: true multiple: true
).perform ).perform
if targets.blank? if targets.blank?
log_error("no recipients", "send_message has no recipients") log_error("no recipients", "send_message has no recipients")
@ -132,8 +132,8 @@ class CustomWizard::Action
if params[:title].present? && if params[:title].present? &&
params[:raw].present? && params[:raw].present? &&
(params[:target_usernames].present? || (params[:target_usernames].present? ||
params[:target_group_names].present?) params[:target_group_names].present?)
params[:archetype] = Archetype.private_message params[:archetype] = Archetype.private_message
@ -169,12 +169,12 @@ class CustomWizard::Action
if allowed_profile_field?(pair['key']) if allowed_profile_field?(pair['key'])
key = cast_profile_key(pair['key']) key = cast_profile_key(pair['key'])
value = cast_profile_value( value = cast_profile_value(
mapper.map_field( mapper.map_field(
pair['value'], pair['value'],
pair['value_type'] pair['value_type']
), ),
pair['key'] pair['key']
) )
if user_field?(pair['key']) if user_field?(pair['key'])
params[:custom_fields] ||= {} params[:custom_fields] ||= {}
@ -207,10 +207,10 @@ class CustomWizard::Action
def watch_tags def watch_tags
tags = CustomWizard::Mapper.new( tags = CustomWizard::Mapper.new(
inputs: action['tags'], inputs: action['tags'],
data: mapper_data, data: mapper_data,
user: user user: user
).perform ).perform
tags = [*tags] tags = [*tags]
level = action['notification_level'].to_sym level = action['notification_level'].to_sym
@ -224,14 +224,14 @@ class CustomWizard::Action
if action['usernames'] if action['usernames']
mapped_users = CustomWizard::Mapper.new( mapped_users = CustomWizard::Mapper.new(
inputs: action['usernames'], inputs: action['usernames'],
data: mapper_data, data: mapper_data,
user: user user: user
).perform ).perform
if mapped_users.present? if mapped_users.present?
mapped_users = mapped_users.split(',') mapped_users = mapped_users.split(',')
.map { |username| User.find_by(username: username) } .map { |username| User.find_by(username: username) }
users.push(*mapped_users) users.push(*mapped_users)
end end
end end
@ -253,10 +253,10 @@ class CustomWizard::Action
def watch_categories def watch_categories
watched_categories = CustomWizard::Mapper.new( watched_categories = CustomWizard::Mapper.new(
inputs: action['categories'], inputs: action['categories'],
data: mapper_data, data: mapper_data,
user: user user: user
).perform ).perform
watched_categories = [*watched_categories].map(&:to_i) watched_categories = [*watched_categories].map(&:to_i)
@ -268,23 +268,23 @@ class CustomWizard::Action
end end
mute_remainder = CustomWizard::Mapper.new( mute_remainder = CustomWizard::Mapper.new(
inputs: action['mute_remainder'], inputs: action['mute_remainder'],
data: mapper_data, data: mapper_data,
user: user user: user
).perform ).perform
users = [] users = []
if action['usernames'] if action['usernames']
mapped_users = CustomWizard::Mapper.new( mapped_users = CustomWizard::Mapper.new(
inputs: action['usernames'], inputs: action['usernames'],
data: mapper_data, data: mapper_data,
user: user user: user
).perform ).perform
if mapped_users.present? if mapped_users.present?
mapped_users = mapped_users.split(',') mapped_users = mapped_users.split(',')
.map { |username| User.find_by(username: username) } .map { |username| User.find_by(username: username) }
users.push(*mapped_users) users.push(*mapped_users)
end end
end end
@ -370,13 +370,13 @@ class CustomWizard::Action
def add_to_group def add_to_group
group_map = CustomWizard::Mapper.new( group_map = CustomWizard::Mapper.new(
inputs: action['group'], inputs: action['group'],
data: mapper_data, data: mapper_data,
user: user, user: user,
opts: { opts: {
multiple: true multiple: true
} }
).perform ).perform
group_map = group_map.flatten.compact group_map = group_map.flatten.compact
@ -386,16 +386,16 @@ class CustomWizard::Action
end end
groups = group_map.reduce([]) do |result, g| groups = group_map.reduce([]) do |result, g|
begin begin
result.push(Integer(g)) result.push(Integer(g))
rescue ArgumentError rescue ArgumentError
group = Group.find_by(name: g) group = Group.find_by(name: g)
result.push(group.id) if group result.push(group.id) if group
end
result
end end
result
end
result = nil result = nil
if groups.present? if groups.present?
@ -420,10 +420,10 @@ class CustomWizard::Action
url = mapper.interpolate(url_input) url = mapper.interpolate(url_input)
else else
url = CustomWizard::Mapper.new( url = CustomWizard::Mapper.new(
inputs: url_input, inputs: url_input,
data: mapper_data, data: mapper_data,
user: user user: user
).perform ).perform
end end
if action['code'] if action['code']
@ -504,10 +504,10 @@ class CustomWizard::Action
def action_category def action_category
output = CustomWizard::Mapper.new( output = CustomWizard::Mapper.new(
inputs: action['category'], inputs: action['category'],
data: mapper_data, data: mapper_data,
user: user user: user
).perform ).perform
return false unless output.present? return false unless output.present?
@ -522,10 +522,10 @@ class CustomWizard::Action
def action_tags def action_tags
output = CustomWizard::Mapper.new( output = CustomWizard::Mapper.new(
inputs: action['tags'], inputs: action['tags'],
data: mapper_data, data: mapper_data,
user: user, user: user,
).perform ).perform
return false unless output.present? return false unless output.present?
@ -539,10 +539,10 @@ class CustomWizard::Action
def add_custom_fields(params = {}) def add_custom_fields(params = {})
if (custom_fields = action['custom_fields']).present? if (custom_fields = action['custom_fields']).present?
field_map = CustomWizard::Mapper.new( field_map = CustomWizard::Mapper.new(
inputs: custom_fields, inputs: custom_fields,
data: mapper_data, data: mapper_data,
user: user user: user
).perform ).perform
registered_fields = CustomWizard::CustomField.full_list registered_fields = CustomWizard::CustomField.full_list
field_map.each do |field| field_map.each do |field|
@ -606,10 +606,10 @@ class CustomWizard::Action
} }
params[:title] = CustomWizard::Mapper.new( params[:title] = CustomWizard::Mapper.new(
inputs: action['title'], inputs: action['title'],
data: mapper_data, data: mapper_data,
user: user user: user
).perform ).perform
if tags = action_tags if tags = action_tags
params[:tags] = tags params[:tags] = tags
@ -641,10 +641,10 @@ class CustomWizard::Action
public_topic_fields.each do |field| public_topic_fields.each do |field|
unless action[field].nil? || action[field] == "" unless action[field].nil? || action[field] == ""
params[field.to_sym] = CustomWizard::Mapper.new( params[field.to_sym] = CustomWizard::Mapper.new(
inputs: action[field], inputs: action[field],
data: mapper_data, data: mapper_data,
user: user user: user
).perform ).perform
end end
end end
end end
@ -675,7 +675,7 @@ class CustomWizard::Action
end end
if attr === "full_name" && input.blank? if attr === "full_name" && input.blank?
input = action["name"] input = action["name"]
end end
if input.present? if input.present?
@ -710,10 +710,10 @@ input = action["name"]
).each do |attr| ).each do |attr|
if action[attr].present? if action[attr].present?
value = CustomWizard::Mapper.new( value = CustomWizard::Mapper.new(
inputs: action[attr], inputs: action[attr],
data: mapper_data, data: mapper_data,
user: user user: user
).perform ).perform
if value if value
if attr === "parent_category_id" && value.is_a?(Array) if attr === "parent_category_id" && value.is_a?(Array)
@ -768,7 +768,7 @@ input = action["name"]
"#{key}_upload_url" "#{key}_upload_url"
else else
key key
end end
end end
def cast_profile_value(value, key) def cast_profile_value(value, key)
@ -793,7 +793,7 @@ end
def user_field?(field) def user_field?(field)
field.to_s.include?(::User::USER_FIELD_PREFIX) && field.to_s.include?(::User::USER_FIELD_PREFIX) &&
::UserField.exists?(field.split('_').last.to_i) ::UserField.exists?(field.split('_').last.to_i)
end end
def allowed_profile_fields def allowed_profile_fields