From 77fedbe10848c00e17ec230c43e7344b731ce038 Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Sat, 20 Feb 2016 13:36:59 +0100 Subject: [PATCH] Only set online notifications to seen for non ticket owners. --- app/models/ticket.rb | 12 ++++++++---- test/unit/online_notifiaction_test.rb | 24 +++++++++++++++++++++++- 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/app/models/ticket.rb b/app/models/ticket.rb index 6c7ebb49b..fa01119f3 100644 --- a/app/models/ticket.rb +++ b/app/models/ticket.rb @@ -278,13 +278,17 @@ returns =end def online_notification_seen_state(user_id_check = nil) - state = Ticket::State.lookup( id: state_id ) - state_type = Ticket::StateType.lookup( id: state.state_type_id ) + + # 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) # 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 ) - state_type = Ticket::StateType.lookup( id: state.state_type_id ) + state = Ticket::State.lookup(id: state.next_state_id) + state_type = Ticket::StateType.lookup(id: state.state_type_id) end # set all to seen if new state is pending reminder state diff --git a/test/unit/online_notifiaction_test.rb b/test/unit/online_notifiaction_test.rb index aca0fea7f..11d4fd439 100644 --- a/test/unit/online_notifiaction_test.rb +++ b/test/unit/online_notifiaction_test.rb @@ -391,7 +391,7 @@ class OnlineNotificationTest < ActiveSupport::TestCase ) 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_user1.id), false) assert_equal(ticket1.online_notification_seen_state(agent_user2.id), true) # to open, all to seen @@ -405,6 +405,28 @@ class OnlineNotificationTest < ActiveSupport::TestCase assert_equal(ticket1.online_notification_seen_state(agent_user1.id), false) assert_equal(ticket1.online_notification_seen_state(agent_user2.id), false) + # to closed, all only others to seen + ticket1.update_attributes( + owner_id: agent_user1.id, + state: Ticket::State.lookup(name: 'closed'), + updated_by_id: agent_user2.id, + ) + + assert_equal(ticket1.online_notification_seen_state, true) + assert_equal(ticket1.online_notification_seen_state(agent_user1.id), false) + 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: 'closed'), + updated_by_id: agent_user1.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)