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:
parent
bf874d77c6
commit
33a20f2cf2
2 changed files with 40 additions and 18 deletions
|
@ -73,28 +73,35 @@ get assets and record_ids of selector
|
||||||
logger.error "Unable to get asset for '#{attribute[0]}': #{e.inspect}"
|
logger.error "Unable to get asset for '#{attribute[0]}': #{e.inspect}"
|
||||||
next
|
next
|
||||||
end
|
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 attribute_class == ::Notification
|
||||||
if content['value'].instance_of?(Array)
|
next if content['recipient'].blank?
|
||||||
content['value'].each do |item_id|
|
|
||||||
next if item_id.blank?
|
|
||||||
|
|
||||||
attribute_object = attribute_ref_class.lookup(id: item_id)
|
attribute_ref_class = ::User
|
||||||
next if !attribute_object
|
item_ids = []
|
||||||
|
Array(content['recipient']).each do |identifier|
|
||||||
|
next if identifier !~ /\Auserid_(\d+)\z/
|
||||||
|
|
||||||
assets = attribute_object.assets(assets)
|
item_ids.push($1)
|
||||||
end
|
|
||||||
elsif content['value'].present?
|
|
||||||
attribute_object = attribute_ref_class.find_by(id: content['value'])
|
|
||||||
if attribute_object
|
|
||||||
assets = attribute_object.assets(assets)
|
|
||||||
end
|
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
|
||||||
end
|
end
|
||||||
assets
|
assets
|
||||||
|
|
|
@ -157,6 +157,21 @@ RSpec.describe Trigger, type: :model do
|
||||||
it 'contains all recipients' do
|
it 'contains all recipients' do
|
||||||
expect(ticket.articles.last.to).to eq("#{recipient1.email}, #{recipient2.email}, #{recipient3.email}")
|
expect(ticket.articles.last.to).to eq("#{recipient1.email}, #{recipient2.email}, #{recipient3.email}")
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
context 'recipient group keyword only' do
|
context 'recipient group keyword only' do
|
||||||
|
|
Loading…
Reference in a new issue