From 72c4de570e4383d172297b7d32cfd7b1db9da03f Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Fri, 31 Mar 2017 08:54:05 +0200 Subject: [PATCH] Fixed issue #883 - Placeholder in triggers with created_by & updated_by / > in article.body. --- lib/notification_factory/renderer.rb | 2 +- .../notification_factory_renderer_test.rb | 34 ++++++++++++++++++- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/lib/notification_factory/renderer.rb b/lib/notification_factory/renderer.rb index e8d4a8697..f15179d96 100644 --- a/lib/notification_factory/renderer.rb +++ b/lib/notification_factory/renderer.rb @@ -139,7 +139,7 @@ examples how to use end def data_key_valid?(key) - return false if key =~ /`|\.(|\s*)(save|destroy|delete|remove|drop|update|create|new|all|where|find)/i && key !~ /(update|create)d_at/i + return false if key =~ /`|\.(|\s*)(save|destroy|delete|remove|drop|update|create|new|all|where|find|raise|dump|rollback|freeze)/i && key !~ /(update|create)d_(at|by)/i true end diff --git a/test/unit/notification_factory_renderer_test.rb b/test/unit/notification_factory_renderer_test.rb index d091afeec..a09c73015 100644 --- a/test/unit/notification_factory_renderer_test.rb +++ b/test/unit/notification_factory_renderer_test.rb @@ -9,7 +9,7 @@ class NotificationFactoryRendererTest < ActiveSupport::TestCase end group = Group.new(name: 'Users') - owner = User.new(firstname: 'Notificationxxx', lastname: 'Agent1yyy') + owner = User.new(firstname: 'Ownerxxx', lastname: 'Agent1yyy') current_user = User.new(firstname: 'CurrentUserxxx', lastname: 'Agent2yyy') recipient = User.new(firstname: 'Recipientxxx', lastname: 'Customer1yyy') state = Ticket::State.new(name: 'new') @@ -19,6 +19,8 @@ class NotificationFactoryRendererTest < ActiveSupport::TestCase group: group, owner: owner, state: state, + created_by: current_user, + updated_by: current_user, created_at: Time.zone.parse('2016-11-12 12:00:00 UTC'), updated_at: Time.zone.parse('2016-11-12 14:00:00 UTC'), ) @@ -56,6 +58,16 @@ class NotificationFactoryRendererTest < ActiveSupport::TestCase ).render assert_equal(ticket.created_at.to_s, result) + template = "\#{ticket.created_by.firstname}" + result = described_class.new( + { + ticket: ticket, + }, + 'en-us', + template, + ).render + assert_equal('CurrentUser<b>xxx</b>', result) + template = "\#{ticket.updated_at}" result = described_class.new( { @@ -66,6 +78,26 @@ class NotificationFactoryRendererTest < ActiveSupport::TestCase ).render assert_equal(ticket.updated_at.to_s, result) + template = "\#{ticket.updated_by.firstname}" + result = described_class.new( + { + ticket: ticket, + }, + 'en-us', + template, + ).render + assert_equal('CurrentUser<b>xxx</b>', result) + + template = "\#{ticket.owner.firstname}" + result = described_class.new( + { + ticket: ticket, + }, + 'en-us', + template, + ).render + assert_equal('Owner<b>xxx</b>', result) + template = "\#{ticket. title}" result = described_class.new( {