From 08bd5186b7f7025670804764ce1a2024bb17c30c Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Sat, 20 Feb 2016 14:09:56 +0100 Subject: [PATCH] So not set pending reminder online notifications to seen. --- .../observer/ticket/notification/background_job.rb | 1 + app/models/ticket.rb | 11 +++++++---- test/unit/online_notifiaction_test.rb | 11 +++++++++++ 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/app/models/observer/ticket/notification/background_job.rb b/app/models/observer/ticket/notification/background_job.rb index ba095b58e..289af9656 100644 --- a/app/models/observer/ticket/notification/background_job.rb +++ b/app/models/observer/ticket/notification/background_job.rb @@ -145,6 +145,7 @@ class Observer::Ticket::Notification::BackgroundJob # delete old notifications if @p[:type] == 'reminder_reached' || @p[:type] == 'escalation' + seen = false OnlineNotification.remove_by_type('Ticket', ticket.id, @p[:type]) end OnlineNotification.add( diff --git a/app/models/ticket.rb b/app/models/ticket.rb index fa01119f3..3bae8b73d 100644 --- a/app/models/ticket.rb +++ b/app/models/ticket.rb @@ -278,13 +278,16 @@ returns =end def online_notification_seen_state(user_id_check = nil) - - # always to set unseen for ticket owner - return false if user_id_check && user_id_check == owner_id && user_id_check != updated_by_id - state = Ticket::State.lookup(id: state_id) state_type = Ticket::StateType.lookup(id: state.state_type_id) + # always to set unseen for ticket owner + if state_type.name != 'merged' + if user_id_check + return false if user_id_check == owner_id && user_id_check != updated_by_id + end + end + # set all to seen if pending action state is a closed or merged state if state_type.name == 'pending action' && state.next_state_id state = Ticket::State.lookup(id: state.next_state_id) diff --git a/test/unit/online_notifiaction_test.rb b/test/unit/online_notifiaction_test.rb index 11d4fd439..4abaed355 100644 --- a/test/unit/online_notifiaction_test.rb +++ b/test/unit/online_notifiaction_test.rb @@ -427,6 +427,17 @@ class OnlineNotificationTest < ActiveSupport::TestCase assert_equal(ticket1.online_notification_seen_state(agent_user1.id), true) assert_equal(ticket1.online_notification_seen_state(agent_user2.id), true) + # to closed by owner self, all to seen + ticket1.update_attributes( + owner_id: agent_user1.id, + state: Ticket::State.lookup(name: 'merged'), + updated_by_id: agent_user2.id, + ) + + assert_equal(ticket1.online_notification_seen_state, true) + assert_equal(ticket1.online_notification_seen_state(agent_user1.id), true) + assert_equal(ticket1.online_notification_seen_state(agent_user2.id), true) + end def notification_check(online_notifications, checks)