diff --git a/app/assets/javascripts/app/controllers/widget/online_notification.coffee b/app/assets/javascripts/app/controllers/widget/online_notification.coffee index fa1537d5c..d3cbd8b90 100644 --- a/app/assets/javascripts/app/controllers/widget/online_notification.coffee +++ b/app/assets/javascripts/app/controllers/widget/online_notification.coffee @@ -154,6 +154,7 @@ class App.OnlineNotificationWidget extends App.Controller title = item.objectNative.activityMessage(item) else title = "Need objectNative in item #{item.object}.find(#{item.o_id})" + title = title.replace(/<.+?>/g, '"') @notifyDesktop( url: item.link title: title diff --git a/app/models/observer/ticket/notification/background_job.rb b/app/models/observer/ticket/notification/background_job.rb index 78c0b9b41..433828b4a 100644 --- a/app/models/observer/ticket/notification/background_job.rb +++ b/app/models/observer/ticket/notification/background_job.rb @@ -130,7 +130,7 @@ class Observer::Ticket::Notification::BackgroundJob next if @p[:type] == 'update' && !article && ( !changes || changes.empty? ) # check if today already notified - if @p[:type] == 'reminder_reached' || @p[:type] == 'escalation' + if @p[:type] == 'reminder_reached' || @p[:type] == 'escalation' || @p[:type] == 'escalation_warning' identifier = user.email if !identifier || identifier == '' identifier = user.login @@ -154,11 +154,17 @@ class Observer::Ticket::Notification::BackgroundJob created_by_id = ticket.updated_by_id || 1 # delete old notifications - if @p[:type] == 'reminder_reached' || @p[:type] == 'escalation' + if @p[:type] == 'reminder_reached' seen = false created_by_id = 1 OnlineNotification.remove_by_type('Ticket', ticket.id, @p[:type], user) + elsif @p[:type] == 'escalation' || @p[:type] == 'escalation_warning' + seen = false + created_by_id = 1 + OnlineNotification.remove_by_type('Ticket', ticket.id, 'escalation', user) + OnlineNotification.remove_by_type('Ticket', ticket.id, 'escalation_warning', user) + # on updates without state changes create unseen messages elsif @p[:type] != 'create' && (!@p[:changes] || @p[:changes].empty? || !@p[:changes]['state_id']) seen = false @@ -197,6 +203,8 @@ class Observer::Ticket::Notification::BackgroundJob template = 'ticket_reminder_reached' elsif @p[:type] == 'escalation' template = 'ticket_escalation' + elsif @p[:type] == 'escalation_warning' + template = 'ticket_escalation_warning' else fail "unknown type for notification #{@p[:type]}" end diff --git a/app/models/ticket.rb b/app/models/ticket.rb index 3bae8b73d..8019fd071 100644 --- a/app/models/ticket.rb +++ b/app/models/ticket.rb @@ -126,7 +126,7 @@ returns processes tickets which have reached their pending time and sets next state_id - processed_tickets = Ticket.process_pending() + processed_tickets = Ticket.process_pending returns @@ -196,6 +196,54 @@ returns =begin +processes escalated tickets + + processed_tickets = Ticket.process_escalation + +returns + + processed_tickets = [, ...] + +=end + + def self.process_escalation + result = [] + + # get max warning diff + + tickets = where('escalation_time <= ?', Time.zone.now + 15.minutes) + + tickets.each {|ticket| + + # get sla + sla = ticket.escalation_calculation_get_sla + + # send escalation + if ticket.escalation_time < Time.zone.now + bg = Observer::Ticket::Notification::BackgroundJob.new( + ticket_id: ticket.id, + article_id: ticket.articles.last.id, + type: 'escalation', + ) + bg.perform + result.push ticket + next + end + + # check if warning need to be sent + bg = Observer::Ticket::Notification::BackgroundJob.new( + ticket_id: ticket.id, + article_id: ticket.articles.last.id, + type: 'escalation_warning', + ) + bg.perform + result.push ticket + } + result + end + +=begin + merge tickets ticket = Ticket.find(123) diff --git a/app/views/mailer/ticket_escalation/de.html.erb b/app/views/mailer/ticket_escalation/de.html.erb new file mode 100644 index 000000000..1b33dcddf --- /dev/null +++ b/app/views/mailer/ticket_escalation/de.html.erb @@ -0,0 +1,18 @@ +Ticket ist eskaliert (<%= d 'ticket.title' %>) + +

Hallo <%= d 'recipient.firstname' %>,

+
+

Ticket (<%= d 'ticket.title' %>) von "<%= d 'ticket.customer.longname' %>" ist seit "<%= d 'ticket.escalation_time' %>" eskaliert!

+
+<% if @objects[:article] %> +

+ <%= t 'Information' %>: +

+ <%= a 'article' %> +
+

+<% end %> +
+

+ <%= t 'View this in Zammad' %> +

diff --git a/app/views/mailer/ticket_escalation/en.html.erb b/app/views/mailer/ticket_escalation/en.html.erb new file mode 100644 index 000000000..ac382fdf7 --- /dev/null +++ b/app/views/mailer/ticket_escalation/en.html.erb @@ -0,0 +1,18 @@ +Ticket is escalated (<%= d 'ticket.title' %>) + +

Hi <%= d 'recipient.firstname' %>,

+
+

Ticket (<%= d 'ticket.title' %>) from "<%= d 'ticket.customer.longname' %>" is escalated since "<%= d 'ticket.escalation_time' %>"!

+
+<% if @objects[:article] %> +

+ <%= t 'Information' %>: +

+ <%= a 'article' %> +
+

+<% end %> +
+

+ <%= t 'View this in Zammad' %> +

diff --git a/app/views/mailer/ticket_escalation_warning/de.html.erb b/app/views/mailer/ticket_escalation_warning/de.html.erb new file mode 100644 index 000000000..4ee2e9671 --- /dev/null +++ b/app/views/mailer/ticket_escalation_warning/de.html.erb @@ -0,0 +1,18 @@ +Ticket wird eskalieren (<%= d 'ticket.title' %>) + +

Hallo <%= d 'recipient.firstname' %>,

+
+

Ticket (<%= d 'ticket.title' %>) von "<%= d 'ticket.customer.longname' %>" wird um "<%= d 'ticket.escalation_time' %>" eskalieren!

+
+<% if @objects[:article] %> +

+ <%= t 'Information' %>: +

+ <%= a 'article' %> +
+

+<% end %> +
+

+ <%= t 'View this in Zammad' %> +

diff --git a/app/views/mailer/ticket_escalation_warning/en.html.erb b/app/views/mailer/ticket_escalation_warning/en.html.erb new file mode 100644 index 000000000..7914b6fa1 --- /dev/null +++ b/app/views/mailer/ticket_escalation_warning/en.html.erb @@ -0,0 +1,18 @@ +Ticket will escalated (<%= d 'ticket.title' %>) + +

Hi <%= d 'recipient.firstname' %>,

+
+

Ticket (<%= d 'ticket.title' %>) from "<%= d 'ticket.customer.longname' %>" will escalated at "<%= d 'ticket.escalation_time' %>"!

+
+<% if @objects[:article] %> +

+ <%= t 'Information' %>: +

+ <%= a 'article' %> +
+

+<% end %> +
+

+ <%= t 'View this in Zammad' %> +

diff --git a/db/migrate/20160109000001_update_channel2.rb b/db/migrate/20160109000001_update_channel2.rb deleted file mode 100644 index b1fb18742..000000000 --- a/db/migrate/20160109000001_update_channel2.rb +++ /dev/null @@ -1,15 +0,0 @@ -class UpdateChannel2 < ActiveRecord::Migration - def up - - Scheduler.create_or_update( - name: 'Check streams for Channel ', - method: 'Channel.stream', - period: 60, - prio: 1, - active: true, - updated_by_id: 1, - created_by_id: 1, - ) - - end -end diff --git a/db/migrate/20160223000001_add_process_escalation_tickets.rb b/db/migrate/20160223000001_add_process_escalation_tickets.rb new file mode 100644 index 000000000..5163e3e12 --- /dev/null +++ b/db/migrate/20160223000001_add_process_escalation_tickets.rb @@ -0,0 +1,13 @@ +class AddProcessEscalationTickets < ActiveRecord::Migration + def up + Scheduler.create_if_not_exists( + name: 'Process escalation tickets', + method: 'Ticket.process_escalation', + period: 60 * 5, + prio: 1, + active: true, + updated_by_id: 1, + created_by_id: 1, + ) + end +end diff --git a/db/seeds.rb b/db/seeds.rb index 06d203081..d0cd392ce 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -3301,6 +3301,13 @@ Scheduler.create_if_not_exists( prio: 1, active: true, ) +Scheduler.create_if_not_exists( + name: 'Process escalation tickets', + method: 'Ticket.process_escalation', + period: 60 * 5, + prio: 1, + active: true, +) Scheduler.create_if_not_exists( name: 'Import OTRS diff load', method: 'Import::OTRS.diff_worker', @@ -3320,7 +3327,7 @@ Scheduler.create_if_not_exists( created_by_id: 1, ) Scheduler.create_if_not_exists( - name: 'Check streams for Channel ', + name: 'Check streams for Channel', method: 'Channel.stream', period: 60, prio: 1,