From 0c7c33b64caeefdd4c9d69c89759b5c82d6f689e Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Mon, 6 Aug 2018 19:36:27 +0200 Subject: [PATCH] Fixed issue #2171 - Overview not showing unassigned tickets "if not defined". --- app/models/ticket.rb | 4 +- test/unit/ticket_overview_test.rb | 98 +++++++++++++++++++++++++++++++ 2 files changed, 100 insertions(+), 2 deletions(-) diff --git a/app/models/ticket.rb b/app/models/ticket.rb index 88a2933ce..f7df061df 100644 --- a/app/models/ticket.rb +++ b/app/models/ticket.rb @@ -575,7 +575,7 @@ condition example if selector['operator'] == 'is' if selector['pre_condition'] == 'not_set' if attributes[1].match?(/^(created_by|updated_by|owner|customer|user)_id/) - query += "#{attribute} IN (?)" + query += "(#{attribute} IS NULL OR #{attribute} IN (?))" bind_params.push 1 else query += "#{attribute} IS NULL" @@ -610,7 +610,7 @@ condition example elsif selector['operator'] == 'is not' if selector['pre_condition'] == 'not_set' if attributes[1].match?(/^(created_by|updated_by|owner|customer|user)_id/) - query += "(#{attribute} IS NULL OR #{attribute} NOT IN (?))" + query += "(#{attribute} IS NOT NULL AND #{attribute} NOT IN (?))" bind_params.push 1 else query += "#{attribute} IS NOT NULL" diff --git a/test/unit/ticket_overview_test.rb b/test/unit/ticket_overview_test.rb index 1c98e6911..b212e5cc7 100644 --- a/test/unit/ticket_overview_test.rb +++ b/test/unit/ticket_overview_test.rb @@ -879,4 +879,102 @@ class TicketOverviewTest < ActiveSupport::TestCase end + test 'overview any owner / no owner is set' do + + Ticket.destroy_all + Overview.destroy_all + + UserInfo.current_user_id = 1 + overview_role = Role.find_by(name: 'Agent') + overview1 = Overview.create_or_update( + name: 'not owned', + prio: 1000, + role_ids: [overview_role.id], + condition: { + 'ticket.owner_id' => { + operator: 'is', + pre_condition: 'not_set', + }, + }, + order: { + by: 'created_at', + direction: 'ASC', + }, + view: { + d: %w[title customer group created_at], + s: %w[title customer group created_at], + m: %w[number title customer group created_at], + view_mode_default: 's', + }, + ) + + overview2 = Overview.create_or_update( + name: 'not owned by somebody', + prio: 2000, + role_ids: [overview_role.id], + condition: { + 'ticket.owner_id' => { + operator: 'is not', + pre_condition: 'not_set', + }, + }, + order: { + by: 'created_at', + direction: 'ASC', + }, + view: { + d: %w[title customer group created_at], + s: %w[title customer group created_at], + m: %w[number title customer group created_at], + view_mode_default: 's', + }, + ) + + ticket1 = Ticket.create!( + title: 'overview test 1', + group: Group.lookup(name: 'OverviewTest'), + customer_id: 2, + owner_id: 1, + state: Ticket::State.lookup(name: 'new'), + priority: Ticket::Priority.lookup(name: '2 normal'), + ) + + travel 2.seconds + ticket2 = Ticket.create!( + title: 'overview test 2', + group: Group.lookup(name: 'OverviewTest'), + customer_id: 2, + owner_id: nil, + state: Ticket::State.lookup(name: 'new'), + priority: Ticket::Priority.lookup(name: '2 normal'), + ) + + travel 2.seconds + ticket3 = Ticket.create!( + title: 'overview test 3', + group: Group.lookup(name: 'OverviewTest'), + customer_id: 2, + owner_id: @agent1.id, + state: Ticket::State.lookup(name: 'new'), + priority: Ticket::Priority.lookup(name: '2 normal'), + ) + + result = Ticket::Overviews.index(@agent1) + assert_equal(result[0][:overview][:id], overview1.id) + assert_equal(result[0][:overview][:name], 'not owned') + assert_equal(result[0][:overview][:view], 'not_owned') + assert_equal(result[0][:tickets].class, Array) + + assert_equal(result[0][:tickets][0][:id], ticket1.id) + assert_equal(result[0][:tickets][1][:id], ticket2.id) + assert_equal(result[0][:count], 2) + + assert_equal(result[1][:overview][:id], overview2.id) + assert_equal(result[1][:overview][:name], 'not owned by somebody') + assert_equal(result[1][:overview][:view], 'not_owned_by_somebody') + assert_equal(result[1][:tickets].class, Array) + assert_equal(result[1][:tickets][0][:id], ticket3.id) + assert_equal(result[1][:count], 1) + + end end