Follow up - af10e5d1d2 - Fixes #535: Send Trigger and Scheduler Notification Email/SMS to single user. Job/Trigger#perform notification.* recipient User Assets are not resolved.

This commit is contained in:
Thorsten Eckel 2020-03-18 18:25:24 +01:00
parent bf874d77c6
commit 33a20f2cf2
2 changed files with 40 additions and 18 deletions

View file

@ -73,28 +73,35 @@ get assets and record_ids of selector
logger.error "Unable to get asset for '#{attribute[0]}': #{e.inspect}"
next
end
reflection = attribute[1].sub(/_id$/, '')
#reflection = reflection.to_sym
next if !models[attribute_class]
next if !models[attribute_class][:reflections]
next if !models[attribute_class][:reflections][reflection]
next if !models[attribute_class][:reflections][reflection].klass
attribute_ref_class = models[attribute_class][:reflections][reflection].klass
if content['value'].instance_of?(Array)
content['value'].each do |item_id|
next if item_id.blank?
if attribute_class == ::Notification
next if content['recipient'].blank?
attribute_object = attribute_ref_class.lookup(id: item_id)
next if !attribute_object
attribute_ref_class = ::User
item_ids = []
Array(content['recipient']).each do |identifier|
next if identifier !~ /\Auserid_(\d+)\z/
assets = attribute_object.assets(assets)
end
elsif content['value'].present?
attribute_object = attribute_ref_class.find_by(id: content['value'])
if attribute_object
assets = attribute_object.assets(assets)
item_ids.push($1)
end
else
reflection = attribute[1].sub(/_id$/, '')
next if !models[attribute_class]
next if !models[attribute_class][:reflections]
next if !models[attribute_class][:reflections][reflection]
next if !models[attribute_class][:reflections][reflection].klass
attribute_ref_class = models[attribute_class][:reflections][reflection].klass
item_ids = Array(content['value'])
end
item_ids.each do |item_id|
next if item_id.blank?
attribute_object = attribute_ref_class.lookup(id: item_id)
next if !attribute_object
assets = attribute_object.assets(assets)
end
end
assets

View file

@ -157,6 +157,21 @@ RSpec.describe Trigger, type: :model do
it 'contains all recipients' do
expect(ticket.articles.last.to).to eq("#{recipient1.email}, #{recipient2.email}, #{recipient3.email}")
end
context 'assets' do
it 'resolves Users from recipient list' do
expect(trigger.assets({})[:User].keys).to include(recipient1.id, recipient2.id, recipient3.id)
end
context 'single entry' do
let(:recipient) { "userid_#{recipient1.id}" }
it 'resolves User from recipient list' do
expect(trigger.assets({})[:User].keys).to include(recipient1.id)
end
end
end
end
context 'recipient group keyword only' do