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