diff --git a/app/models/ticket.rb b/app/models/ticket.rb
index 5cba7da75..2f390f26d 100644
--- a/app/models/ticket.rb
+++ b/app/models/ticket.rb
@@ -24,6 +24,7 @@ class Ticket < ApplicationModel
latest_change_support
activity_stream_support ignore_attributes: {
+ organization_id: true, # organization_id will channge automatically on user update
create_article_type_id: true,
create_article_sender_id: true,
article_count: true,
diff --git a/app/models/transaction/notification.rb b/app/models/transaction/notification.rb
index c52b04a88..bd2c6bb70 100644
--- a/app/models/transaction/notification.rb
+++ b/app/models/transaction/notification.rb
@@ -179,7 +179,7 @@ class Transaction::Notification
raise "unknown type for notification #{@item[:type]}"
end
- current_user = User.lookup(id: @item[:user_id] || 1)
+ current_user = User.lookup(id: @item[:user_id])
if !current_user
current_user = User.lookup(id: 1)
end
diff --git a/app/models/transaction/slack.rb b/app/models/transaction/slack.rb
index f27995e77..6c12f4900 100644
--- a/app/models/transaction/slack.rb
+++ b/app/models/transaction/slack.rb
@@ -71,12 +71,19 @@ backend.perform
end
user = User.find(1)
+
+ current_user = User.lookup(id: @item[:user_id])
+ if !current_user
+ current_user = User.lookup(id: 1)
+ end
+
result = NotificationFactory::Slack.template(
template: template,
locale: user[:preferences][:locale],
objects: {
ticket: ticket,
article: article,
+ current_user: current_user,
changes: changes,
},
)
diff --git a/test/unit/notification_factory_mailer_template_test.rb b/test/unit/notification_factory_mailer_template_test.rb
new file mode 100644
index 000000000..7889b6057
--- /dev/null
+++ b/test/unit/notification_factory_mailer_template_test.rb
@@ -0,0 +1,206 @@
+# encoding: utf-8
+require 'test_helper'
+
+class NotificationFactoryMailerTemplateTest < ActiveSupport::TestCase
+
+ test 'notifications template' do
+
+ Translation.load('de-de')
+
+ groups = Group.where(name: 'Users')
+ roles = Role.where(name: 'Agent')
+ agent1 = User.create_or_update(
+ login: 'notification-template-agent1@example.com',
+ firstname: 'Notificationxxx',
+ lastname: 'Agent1yyy',
+ email: 'notification-template-agent1@example.com',
+ password: 'agentpw',
+ active: true,
+ roles: roles,
+ groups: groups,
+ preferences: {
+ locale: 'de-de',
+ },
+ updated_by_id: 1,
+ created_by_id: 1,
+ )
+
+ agent_current_user = User.create_or_update(
+ login: 'notification-template-current_user@example.com',
+ firstname: 'Notification Current',
+ lastname: 'User',
+ email: 'notification-template-current_user@example.com',
+ password: 'agentpw',
+ active: true,
+ roles: roles,
+ groups: groups,
+ preferences: {
+ locale: 'de-de',
+ },
+ updated_by_id: 1,
+ created_by_id: 1,
+ )
+
+ result = NotificationFactory::Mailer.template(
+ template: 'password_reset',
+ locale: 'de-de',
+ objects: {
+ user: agent1,
+ },
+ )
+ assert_match('Zurücksetzen Deines', result[:subject])
+ assert_match('wir haben eine Anfrage zum Zurücksetzen', result[:body])
+ assert_match('Dein', result[:body])
+ assert_match('Dein', result[:body])
+ assert_match('Notification<b>xxx</b>', result[:body])
+ assert_no_match('Your', result[:body])
+
+ result = NotificationFactory::Mailer.template(
+ template: 'password_reset',
+ locale: 'de',
+ objects: {
+ user: agent1,
+ },
+ )
+ assert_match('Zurücksetzen Deines', result[:subject])
+ assert_match('wir haben eine Anfrage zum Zurücksetzen', result[:body])
+ assert_match('Dein', result[:body])
+ assert_match('Notification<b>xxx</b>', result[:body])
+ assert_no_match('Your', result[:body])
+
+ result = NotificationFactory::Mailer.template(
+ template: 'password_reset',
+ locale: 'es-us',
+ objects: {
+ user: agent1,
+ },
+ )
+ assert_match('Reset your', result[:subject])
+ assert_match('We received a request to reset the password', result[:body])
+ assert_match('Your', result[:body])
+ assert_match('Notification<b>xxx</b>', result[:body])
+ assert_no_match('Dein', result[:body])
+
+ ticket = Ticket.create(
+ group_id: Group.lookup(name: 'Users').id,
+ customer_id: User.lookup(email: 'nicole.braun@zammad.org').id,
+ owner_id: User.lookup(login: '-').id,
+ title: 'Welcome to Zammad!',
+ state_id: Ticket::State.lookup(name: 'new').id,
+ priority_id: Ticket::Priority.lookup(name: '2 normal').id,
+ updated_by_id: 1,
+ created_by_id: 1,
+ )
+ article = Ticket::Article.create(
+ ticket_id: ticket.id,
+ type_id: Ticket::Article::Type.lookup(name: 'phone').id,
+ sender_id: Ticket::Article::Sender.lookup(name: 'Customer').id,
+ from: 'Zammad Feedback ',
+ content_type: 'text/plain',
+ body: 'Welcome!
+test123',
+ internal: false,
+ updated_by_id: 1,
+ created_by_id: 1,
+ )
+
+ changes = {}
+ result = NotificationFactory::Mailer.template(
+ template: 'ticket_create',
+ locale: 'es-us',
+ objects: {
+ ticket: ticket,
+ article: article,
+ recipient: agent1,
+ current_user: agent_current_user,
+ changes: changes,
+ },
+ )
+ assert_match('New Ticket', result[:subject])
+ assert_match('Notification<b>xxx</b>', result[:body])
+ assert_match('has been created by', result[:body])
+ assert_match('<b>test123</b>', result[:body])
+ assert_match('Manage your notifications settings', result[:body])
+ assert_no_match('Dein', result[:body])
+ assert_no_match('longname', result[:body])
+ assert_match('Current User', result[:body])
+
+ result = NotificationFactory::Mailer.template(
+ template: 'ticket_create',
+ locale: 'de-de',
+ objects: {
+ ticket: ticket,
+ article: article,
+ recipient: agent1,
+ current_user: agent_current_user,
+ changes: changes,
+ },
+ )
+ assert_match('Neues Ticket', result[:subject])
+ assert_match('Notification<b>xxx</b>', result[:body])
+ assert_match('es wurde ein neues Ticket', result[:body])
+ assert_match('<b>test123</b>', result[:body])
+ assert_match('Benachrichtigungseinstellungen Verwalten', result[:body])
+ assert_no_match('Your', result[:body])
+ assert_no_match('longname', result[:body])
+ assert_match('Current User', result[:body])
+
+ article = Ticket::Article.create(
+ ticket_id: ticket.id,
+ type_id: Ticket::Article::Type.lookup(name: 'phone').id,
+ sender_id: Ticket::Article::Sender.lookup(name: 'Customer').id,
+ from: 'Zammad Feedback ',
+ content_type: 'text/html',
+ body: 'Welcome!
+test123',
+ internal: false,
+ updated_by_id: 1,
+ created_by_id: 1,
+ )
+ changes = {
+ state: %w(aaa bbb),
+ group: %w(xxx yyy),
+ }
+ result = NotificationFactory::Mailer.template(
+ template: 'ticket_update',
+ locale: 'es-us',
+ objects: {
+ ticket: ticket,
+ article: article,
+ recipient: agent1,
+ current_user: agent_current_user,
+ changes: changes,
+ },
+ )
+ assert_match('Updated Ticket', result[:subject])
+ assert_match('Notification<b>xxx</b>', result[:body])
+ assert_match('has been updated by', result[:body])
+ assert_match('test123', result[:body])
+ assert_match('Manage your notifications settings', result[:body])
+ assert_no_match('Dein', result[:body])
+ assert_no_match('longname', result[:body])
+ assert_match('Current User', result[:body])
+
+ result = NotificationFactory::Mailer.template(
+ template: 'ticket_update',
+ locale: 'de-de',
+ objects: {
+ ticket: ticket,
+ article: article,
+ recipient: agent1,
+ current_user: agent_current_user,
+ changes: changes,
+ },
+ )
+ assert_match('Ticket aktualisiert', result[:subject])
+ assert_match('Notification<b>xxx</b>', result[:body])
+ assert_match('wurde von', result[:body])
+ assert_match('test123', result[:body])
+ assert_match('Benachrichtigungseinstellungen Verwalten', result[:body])
+ assert_no_match('Your', result[:body])
+ assert_no_match('longname', result[:body])
+ assert_match('Current User', result[:body])
+
+ end
+
+end
diff --git a/test/unit/notification_factory_mailer_test.rb b/test/unit/notification_factory_mailer_test.rb
index c66e15c44..8e2323a19 100644
--- a/test/unit/notification_factory_mailer_test.rb
+++ b/test/unit/notification_factory_mailer_test.rb
@@ -3,8 +3,6 @@ require 'test_helper'
class NotificationFactoryMailerTest < ActiveSupport::TestCase
- Translation.load('de-de')
-
test 'notifications send' do
result = NotificationFactory::Mailer.send(
recipient: User.find(2),
@@ -38,175 +36,6 @@ class NotificationFactoryMailerTest < ActiveSupport::TestCase
assert_match('text/html', result.to_s)
end
- test 'notifications template' do
- groups = Group.where(name: 'Users')
- roles = Role.where(name: 'Agent')
- agent1 = User.create_or_update(
- login: 'notification-template-agent1@example.com',
- firstname: 'Notificationxxx',
- lastname: 'Agent1yyy',
- email: 'notification-template-agent1@example.com',
- password: 'agentpw',
- active: true,
- roles: roles,
- groups: groups,
- preferences: {
- locale: 'de-de',
- },
- updated_by_id: 1,
- created_by_id: 1,
- )
-
- result = NotificationFactory::Mailer.template(
- template: 'password_reset',
- locale: 'de-de',
- objects: {
- user: agent1,
- },
- )
- assert_match('Zurücksetzen Deines', result[:subject])
- assert_match('wir haben eine Anfrage zum Zurücksetzen', result[:body])
- assert_match('Dein', result[:body])
- assert_match('Dein', result[:body])
- assert_match('Notification<b>xxx</b>', result[:body])
- assert_no_match('Your', result[:body])
-
- result = NotificationFactory::Mailer.template(
- template: 'password_reset',
- locale: 'de',
- objects: {
- user: agent1,
- },
- )
- assert_match('Zurücksetzen Deines', result[:subject])
- assert_match('wir haben eine Anfrage zum Zurücksetzen', result[:body])
- assert_match('Dein', result[:body])
- assert_match('Notification<b>xxx</b>', result[:body])
- assert_no_match('Your', result[:body])
-
- result = NotificationFactory::Mailer.template(
- template: 'password_reset',
- locale: 'es-us',
- objects: {
- user: agent1,
- },
- )
- assert_match('Reset your', result[:subject])
- assert_match('We received a request to reset the password', result[:body])
- assert_match('Your', result[:body])
- assert_match('Notification<b>xxx</b>', result[:body])
- assert_no_match('Dein', result[:body])
-
- ticket = Ticket.create(
- group_id: Group.lookup(name: 'Users').id,
- customer_id: User.lookup(email: 'nicole.braun@zammad.org').id,
- owner_id: User.lookup(login: '-').id,
- title: 'Welcome to Zammad!',
- state_id: Ticket::State.lookup(name: 'new').id,
- priority_id: Ticket::Priority.lookup(name: '2 normal').id,
- updated_by_id: 1,
- created_by_id: 1,
- )
- article = Ticket::Article.create(
- ticket_id: ticket.id,
- type_id: Ticket::Article::Type.lookup(name: 'phone').id,
- sender_id: Ticket::Article::Sender.lookup(name: 'Customer').id,
- from: 'Zammad Feedback ',
- content_type: 'text/plain',
- body: 'Welcome!
-test123',
- internal: false,
- updated_by_id: 1,
- created_by_id: 1,
- )
-
- changes = {}
- result = NotificationFactory::Mailer.template(
- template: 'ticket_create',
- locale: 'es-us',
- objects: {
- ticket: ticket,
- article: article,
- recipient: agent1,
- changes: changes,
- },
- )
- assert_match('New Ticket', result[:subject])
- assert_match('Notification<b>xxx</b>', result[:body])
- assert_match('has been created by', result[:body])
- assert_match('<b>test123</b>', result[:body])
- assert_match('Manage your notifications settings', result[:body])
- assert_no_match('Dein', result[:body])
-
- result = NotificationFactory::Mailer.template(
- template: 'ticket_create',
- locale: 'de-de',
- objects: {
- ticket: ticket,
- article: article,
- recipient: agent1,
- changes: changes,
- },
- )
- assert_match('Neues Ticket', result[:subject])
- assert_match('Notification<b>xxx</b>', result[:body])
- assert_match('es wurde ein neues Ticket', result[:body])
- assert_match('<b>test123</b>', result[:body])
- assert_match('Benachrichtigungseinstellungen Verwalten', result[:body])
- assert_no_match('Your', result[:body])
-
- article = Ticket::Article.create(
- ticket_id: ticket.id,
- type_id: Ticket::Article::Type.lookup(name: 'phone').id,
- sender_id: Ticket::Article::Sender.lookup(name: 'Customer').id,
- from: 'Zammad Feedback ',
- content_type: 'text/html',
- body: 'Welcome!
-test123',
- internal: false,
- updated_by_id: 1,
- created_by_id: 1,
- )
- changes = {
- state: %w(aaa bbb),
- group: %w(xxx yyy),
- }
- result = NotificationFactory::Mailer.template(
- template: 'ticket_update',
- locale: 'es-us',
- objects: {
- ticket: ticket,
- article: article,
- recipient: agent1,
- changes: changes,
- },
- )
- assert_match('Updated Ticket', result[:subject])
- assert_match('Notification<b>xxx</b>', result[:body])
- assert_match('has been updated by', result[:body])
- assert_match('test123', result[:body])
- assert_match('Manage your notifications settings', result[:body])
- assert_no_match('Dein', result[:body])
-
- result = NotificationFactory::Mailer.template(
- template: 'ticket_update',
- locale: 'de-de',
- objects: {
- ticket: ticket,
- article: article,
- recipient: agent1,
- changes: changes,
- },
- )
- assert_match('Ticket aktualisiert', result[:subject])
- assert_match('Notification<b>xxx</b>', result[:body])
- assert_match('wurde von', result[:body])
- assert_match('test123', result[:body])
- assert_match('Benachrichtigungseinstellungen Verwalten', result[:body])
- assert_no_match('Your', result[:body])
-
- end
-
test 'notifications settings' do
groups = Group.all
diff --git a/test/unit/notification_factory_slack_template_test.rb b/test/unit/notification_factory_slack_template_test.rb
new file mode 100644
index 000000000..d746c4b42
--- /dev/null
+++ b/test/unit/notification_factory_slack_template_test.rb
@@ -0,0 +1,125 @@
+# encoding: utf-8
+require 'test_helper'
+
+class NotificationFactorySlackTemplateTest < ActiveSupport::TestCase
+
+ test 'notifications template' do
+
+ Translation.load('de-de')
+
+ groups = Group.where(name: 'Users')
+ roles = Role.where(name: 'Agent')
+ agent1 = User.create_or_update(
+ login: 'notification-template-agent1@example.com',
+ firstname: 'Notificationxxx',
+ lastname: 'Agent1yyy',
+ email: 'notification-template-agent1@example.com',
+ password: 'agentpw',
+ active: true,
+ roles: roles,
+ groups: groups,
+ preferences: {
+ locale: 'de-de',
+ },
+ updated_by_id: 1,
+ created_by_id: 1,
+ )
+
+ agent_current_user = User.create_or_update(
+ login: 'notification-template-current_user@example.com',
+ firstname: 'Notification Current',
+ lastname: 'Userxxx',
+ email: 'notification-template-current_user@example.com',
+ password: 'agentpw',
+ active: true,
+ roles: roles,
+ groups: groups,
+ preferences: {
+ locale: 'de-de',
+ },
+ updated_by_id: 1,
+ created_by_id: 1,
+ )
+
+ ticket = Ticket.create(
+ group_id: Group.lookup(name: 'Users').id,
+ customer_id: User.lookup(email: 'nicole.braun@zammad.org').id,
+ owner_id: User.lookup(login: '-').id,
+ title: 'Welcome to Zammad!',
+ state_id: Ticket::State.lookup(name: 'new').id,
+ priority_id: Ticket::Priority.lookup(name: '2 normal').id,
+ updated_by_id: 1,
+ created_by_id: 1,
+ )
+ article = Ticket::Article.create(
+ ticket_id: ticket.id,
+ type_id: Ticket::Article::Type.lookup(name: 'phone').id,
+ sender_id: Ticket::Article::Sender.lookup(name: 'Customer').id,
+ from: 'Zammad Feedback ',
+ content_type: 'text/plain',
+ body: 'Welcome!
+test123',
+ internal: false,
+ updated_by_id: 1,
+ created_by_id: 1,
+ )
+
+ changes = {}
+ result = NotificationFactory::Slack.template(
+ template: 'ticket_create',
+ locale: 'es-us',
+ objects: {
+ ticket: ticket,
+ article: article,
+ recipient: agent1,
+ current_user: agent_current_user,
+ changes: changes,
+ },
+ )
+
+ assert_match('# Welcome to Zammad!', result[:subject])
+ assert_match('User<b>xxx</b>', result[:body])
+ assert_match('Created by', result[:body])
+ assert_match('test123', result[:body])
+ assert_no_match('Dein', result[:body])
+ assert_no_match('longname', result[:body])
+ assert_match('Current User', result[:body])
+
+ article = Ticket::Article.create(
+ ticket_id: ticket.id,
+ type_id: Ticket::Article::Type.lookup(name: 'phone').id,
+ sender_id: Ticket::Article::Sender.lookup(name: 'Customer').id,
+ from: 'Zammad Feedback ',
+ content_type: 'text/html',
+ body: 'Welcome!
+test123',
+ internal: false,
+ updated_by_id: 1,
+ created_by_id: 1,
+ )
+ changes = {
+ state: %w(aaa bbb),
+ group: %w(xxx yyy),
+ }
+ result = NotificationFactory::Slack.template(
+ template: 'ticket_update',
+ locale: 'es-us',
+ objects: {
+ ticket: ticket,
+ article: article,
+ recipient: agent1,
+ current_user: agent_current_user,
+ changes: changes,
+ },
+ )
+ assert_match('# Welcome to Zammad!', result[:subject])
+ assert_match('User<b>xxx</b>', result[:body])
+ assert_match('state: aaa -> bbb', result[:body])
+ assert_match('group: xxx -> yyy', result[:body])
+ assert_no_match('Dein', result[:body])
+ assert_no_match('longname', result[:body])
+ assert_match('Current User', result[:body])
+
+ end
+
+end