This commit is contained in:
Rolf Schmidt 2020-03-03 10:39:16 +01:00
parent eafb6dd236
commit 2b9f5c85c6
2 changed files with 17 additions and 12 deletions

View file

@ -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

View file

@ -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