From 89f99e52dde01c2a8746876743f1adcc3d0c48cd Mon Sep 17 00:00:00 2001 From: Ross Crawford-d'Heureuse Date: Thu, 29 Oct 2020 12:18:55 +0100 Subject: [PATCH] Fixes #2716 Closes #3225 - Triggered note with variables do not replace variable with content. --- app/models/ticket.rb | 54 +++++++++++++++++++++++--------- test/unit/ticket_trigger_test.rb | 8 ++--- 2 files changed, 44 insertions(+), 18 deletions(-) diff --git a/app/models/ticket.rb b/app/models/ticket.rb index 489bf715a..a1cf82fb7 100644 --- a/app/models/ticket.rb +++ b/app/models/ticket.rb @@ -1017,23 +1017,12 @@ perform changes on ticket save! end + objects = build_notification_template_objects(article) + perform_article.each do |key, value| raise 'Unable to create article, we only support article.note' if key != 'article.note' - Ticket::Article.create!( - ticket_id: id, - subject: value[:subject], - content_type: 'text/html', - body: value[:body], - internal: value[:internal], - sender: Ticket::Article::Sender.find_by(name: 'System'), - type: Ticket::Article::Type.find_by(name: 'note'), - preferences: { - perform_origin: perform_origin, - }, - updated_by_id: 1, - created_by_id: 1, - ) + add_trigger_note(id, value, objects, perform_origin) end perform_notification.each do |key, value| @@ -1053,6 +1042,43 @@ perform changes on ticket =begin +perform changes on ticket + + ticket.add_trigger_note(ticket_id, note, objects, perform_origin) + +=end + + def add_trigger_note(ticket_id, note, objects, perform_origin) + rendered_subject = NotificationFactory::Mailer.template( + templateInline: note[:subject], + objects: objects, + quote: true, + ) + + rendered_body = NotificationFactory::Mailer.template( + templateInline: note[:body], + objects: objects, + quote: true, + ) + + Ticket::Article.create!( + ticket_id: ticket_id, + subject: rendered_subject, + content_type: 'text/html', + body: rendered_body, + internal: note[:internal], + sender: Ticket::Article::Sender.find_by(name: 'System'), + type: Ticket::Article::Type.find_by(name: 'note'), + preferences: { + perform_origin: perform_origin, + }, + updated_by_id: 1, + created_by_id: 1, + ) + end + +=begin + perform active triggers on ticket Ticket.perform_triggers(ticket, article, item, options) diff --git a/test/unit/ticket_trigger_test.rb b/test/unit/ticket_trigger_test.rb index 937fe3216..434a314b9 100644 --- a/test/unit/ticket_trigger_test.rb +++ b/test/unit/ticket_trigger_test.rb @@ -4446,8 +4446,8 @@ class TicketTriggerTest < ActiveSupport::TestCase }, perform: { 'article.note' => { - 'body' => 'some note', - 'subject' => 'some subject!', + 'subject' => 'some subject! #{ticket.id}', + 'body' => 'I can integrate with 3rd party services at https://my.saas/foo/#{ticket.id}', 'internal' => 'true', }, 'notification.email' => { @@ -4508,8 +4508,8 @@ class TicketTriggerTest < ActiveSupport::TestCase article_note1 = ticket1.articles[1] assert_match('- ', article_note1.from) assert_nil(article_note1.to) - assert_match('some subject!', article_note1.subject) - assert_match('some note', article_note1.body) + assert_match("some subject! #{ticket1.id}", article_note1.subject) + assert_match("I can integrate with 3rd party services at https://my.saas/foo/#{ticket1.id}", article_note1.body) assert_equal('text/html', article_note1.content_type) assert_equal(true, article_note1.internal)