DEV: Add logic to append tag if user allowed
Dieser Commit ist enthalten in:
Ursprung
a518955423
Commit
c29c3b084e
1 geänderte Dateien mit 93 neuen und 87 gelöschten Zeilen
|
@ -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")
|
||||||
|
@ -104,13 +104,14 @@ class CustomWizard::Action
|
||||||
end
|
end
|
||||||
|
|
||||||
params = basic_topic_params
|
params = basic_topic_params
|
||||||
|
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")
|
||||||
|
@ -131,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
|
||||||
|
|
||||||
|
@ -168,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] ||= {}
|
||||||
|
@ -206,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
|
||||||
|
@ -223,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
|
||||||
|
@ -252,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)
|
||||||
|
|
||||||
|
@ -267,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
|
||||||
|
@ -369,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
|
||||||
|
|
||||||
|
@ -385,15 +386,15 @@ 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
|
end
|
||||||
|
|
||||||
result
|
result
|
||||||
end
|
end
|
||||||
|
|
||||||
result = nil
|
result = nil
|
||||||
|
|
||||||
|
@ -419,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']
|
||||||
|
@ -503,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?
|
||||||
|
|
||||||
|
@ -521,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?
|
||||||
|
|
||||||
|
@ -538,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|
|
||||||
|
@ -605,10 +606,14 @@ 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
|
||||||
|
params[:tags] = tags
|
||||||
|
end
|
||||||
|
|
||||||
params[:raw] = action['post_builder'] ?
|
params[:raw] = action['post_builder'] ?
|
||||||
mapper.interpolate(
|
mapper.interpolate(
|
||||||
|
@ -632,18 +637,14 @@ class CustomWizard::Action
|
||||||
params[:category] = category
|
params[:category] = category
|
||||||
end
|
end
|
||||||
|
|
||||||
if tags = action_tags
|
|
||||||
params[:tags] = tags
|
|
||||||
end
|
|
||||||
|
|
||||||
if public_topic_fields.any?
|
if public_topic_fields.any?
|
||||||
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
|
||||||
|
@ -674,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?
|
||||||
|
@ -709,10 +710,10 @@ class CustomWizard::Action
|
||||||
).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)
|
||||||
|
@ -767,7 +768,7 @@ class CustomWizard::Action
|
||||||
"#{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)
|
||||||
|
@ -792,7 +793,7 @@ class CustomWizard::Action
|
||||||
|
|
||||||
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
|
||||||
|
@ -837,4 +838,9 @@ class CustomWizard::Action
|
||||||
@log.join('; ')
|
@log.join('; ')
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
def user_can_tag
|
||||||
|
allowed_groups =
|
||||||
|
SiteSetting.pm_tags_allowed_for_groups.split('|').map(&:to_i)
|
||||||
|
user.groups.pluck(:id).any? { |group| allowed_groups.include?(group) }
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Laden …
In neuem Issue referenzieren