From c8eab7ca5626cf4c4c8b97b5a24b4a4e1f6f0daf Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Thu, 10 Nov 2016 16:30:36 +0100 Subject: [PATCH] Fixed issue#383 - TicketSelector in Overview or SLA not working with filter for ticket customer or owner. --- app/models/ticket.rb | 6 ++++-- test/unit/ticket_selector_test.rb | 23 +++++++++++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/app/models/ticket.rb b/app/models/ticket.rb index 8d7a9cce5..e76413c5f 100644 --- a/app/models/ticket.rb +++ b/app/models/ticket.rb @@ -501,9 +501,11 @@ condition example selector = selector_raw.stringify_keys raise "Invalid selector, operator missing #{selector.inspect}" if !selector['operator'] - # validate value / allow empty but only if pre_condition exists + # validate value / allow empty but only if pre_condition exists and is not specific if !selector.key?('value') || ((selector['value'].class == String || selector['value'].class == Array) && (selector['value'].respond_to?(:empty?) && selector['value'].empty?)) - return nil if selector['pre_condition'].nil? || (selector['pre_condition'].respond_to?(:empty?) && selector['pre_condition'].empty?) + return nil if selector['pre_condition'].nil? + return nil if selector['pre_condition'].respond_to?(:empty?) && selector['pre_condition'].empty? + return nil if selector['pre_condition'] == 'specific' end # validate pre_condition values diff --git a/test/unit/ticket_selector_test.rb b/test/unit/ticket_selector_test.rb index 2d7039d12..218dbbeac 100644 --- a/test/unit/ticket_selector_test.rb +++ b/test/unit/ticket_selector_test.rb @@ -773,6 +773,29 @@ class TicketSelectorTest < ActiveSupport::TestCase ticket_count, tickets = Ticket.selectors(condition, 10, customer2) assert_equal(ticket_count, 0) + condition = { + 'ticket.group_id' => { + operator: 'is', + value: group.id, + }, + 'ticket.owner_id' => { + operator: 'is', + pre_condition: 'specific', + #value: agent1.id, # value is not set, no result should be shown + }, + } + ticket_count, tickets = Ticket.selectors(condition, 10, agent1) + assert_equal(ticket_count, nil) + + ticket_count, tickets = Ticket.selectors(condition, 10, agent2) + assert_equal(ticket_count, nil) + + ticket_count, tickets = Ticket.selectors(condition, 10, customer1) + assert_equal(ticket_count, nil) + + ticket_count, tickets = Ticket.selectors(condition, 10, customer2) + assert_equal(ticket_count, nil) + condition = { 'ticket.group_id' => { operator: 'is',