Browse Source

Fixes #4599 - Error 500 if overview with "out of office replacement" filter is set to "specific user".

Rolf Schmidt 1 year ago
parent
commit
2086e1a059
2 changed files with 29 additions and 1 deletions
  1. 1 1
      app/models/ticket/selector/sql.rb
  2. 28 0
      spec/models/ticket/selector/sql_spec.rb

+ 1 - 1
app/models/ticket/selector/sql.rb

@@ -317,7 +317,7 @@ class Ticket::Selector::Sql < Ticket::Selector::Base
         else
           if attribute_name == 'out_of_office_replacement_id'
             query << "#{attribute} IN (?)"
-            bind_params.push User.find(block_condition[:value]).out_of_office_agent_of.pluck(:id)
+            bind_params.push User.where(id: Array.wrap(block_condition[:value])).map(&:out_of_office_agent_of).flatten.map(&:id)
           else
             block_condition[:value] = Array.wrap(block_condition[:value])
 

+ 28 - 0
spec/models/ticket/selector/sql_spec.rb

@@ -692,4 +692,32 @@ RSpec.describe Ticket::Selector::Sql do
     end
 
   end
+
+  describe 'Error 500 if overview with "out of office replacement" filter is set to "specific user" #4599' do
+    let(:agent)                 { create(:agent) }
+    let(:agent_ooo)             { create(:agent, :ooo, ooo_agent: agent_ooo_replacement) }
+    let(:agent_ooo_replacement) { create(:agent) }
+    let(:condition) do
+      {
+        'ticket.out_of_office_replacement_id': {
+          operator:         'is',
+          pre_condition:    'specific',
+          value:            [
+            agent_ooo_replacement.id.to_s,
+          ],
+          value_completion: ''
+        }
+      }
+    end
+
+    before do
+      agent_ooo
+    end
+
+    it 'calculates the out of office user ids for the out of office replacement agent' do
+      _, bind_params = Ticket.selector2sql(condition)
+
+      expect(bind_params.flatten).to include(agent_ooo.id)
+    end
+  end
 end