From 2b9f5c85c6efd70ca41dd0c05f4bb330b449ecca Mon Sep 17 00:00:00 2001 From: Rolf Schmidt Date: Tue, 3 Mar 2020 10:39:16 +0100 Subject: [PATCH] Fix. --- app/models/ticket.rb | 27 ++++++++++++++++----------- spec/models/trigger_spec.rb | 2 +- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/app/models/ticket.rb b/app/models/ticket.rb index 5beb9cc4d..05dae0886 100644 --- a/app/models/ticket.rb +++ b/app/models/ticket.rb @@ -591,6 +591,22 @@ condition example selector['value'] = selector['value'].split(/,/).collect(&:strip) end + if selector['operator'].include?('in working time') + next if attributes[1] != 'calendar_id' + raise 'Please enable execution_time feature to use it (currently only allowed for triggers and schedulers)' if !options[:execution_time] + + biz = Calendar.lookup(id: selector['value'])&.biz + next if biz.blank? + + if ( selector['operator'] == 'is in working time' && !biz.in_hours?(Time.zone.now) ) || ( selector['operator'] == 'is not in working time' && biz.in_hours?(Time.zone.now) ) + no_result = true + break + end + + # skip to next condition + next + end + if query != '' query += ' AND ' end @@ -828,17 +844,6 @@ condition example raise "Unknown selector attributes '#{selector.inspect}'" end bind_params.push time - elsif selector['operator'].include?('in working time') - next if attributes[1] != 'calendar_id' - raise 'Please enable execution_time feature to use it (currently only allowed for triggers and schedulers)' if !options[:execution_time] - - biz = Calendar.lookup(id: selector['value'])&.biz - next if biz.blank? - - if ( selector['operator'] == 'is in working time' && !biz.in_hours?(Time.zone.now) ) || ( selector['operator'] == 'is not in working time' && biz.in_hours?(Time.zone.now) ) - no_result = true - break - end else raise "Invalid operator '#{selector['operator']}' for '#{selector['value'].inspect}'" end diff --git a/spec/models/trigger_spec.rb b/spec/models/trigger_spec.rb index 1d08dbf7e..f3b075347 100644 --- a/spec/models/trigger_spec.rb +++ b/spec/models/trigger_spec.rb @@ -166,7 +166,7 @@ RSpec.describe Trigger, type: :model do context 'is in working time' do let(:condition) do - { 'execution_time.calendar_id' => { 'operator' => 'is in working time', 'value' => calendar.id } } + { 'ticket.state_id' => { 'operator' => 'is', 'value' => Ticket::State.all.pluck(:id) }, 'execution_time.calendar_id' => { 'operator' => 'is in working time', 'value' => calendar.id } } end it 'does trigger only in working time' do