app/models/foreman_tasks/task/search.rb in foreman-tasks-1.0.1 vs app/models/foreman_tasks/task/search.rb in foreman-tasks-1.1.0

- old
+ new

@@ -2,11 +2,12 @@ class Task module Search def search_by_generic_resource(key, operator, value) key = 'resource_type' if key.blank? key_name = connection.quote_column_name(key.sub(/^.*\./, '')) - condition = sanitize_sql_for_conditions(["foreman_tasks_locks.#{key_name} #{operator} ?", value]) + value = value.split(',') if operator.index(/IN/i) + condition = sanitize_sql_for_conditions(["foreman_tasks_locks.#{key_name} #{operator} (?)", value]) { :conditions => condition, :joins => :locks } end def search_by_taxonomy(key, operator, value) @@ -19,9 +20,18 @@ foreman_tasks_locks_taxonomy#{uniq_suffix}.resource_type = '#{resource_type}') SQL # Select only those tasks which either have the correct taxonomy or are not related to any sql = "foreman_tasks_locks_taxonomy#{uniq_suffix}.resource_id #{operator} ? OR foreman_tasks_locks_taxonomy#{uniq_suffix}.resource_id IS NULL" { :conditions => sanitize_sql_for_conditions([sql, value]), :joins => joins } + end + + # Expects the time in the format "\d+ (seconds|minutes|hours|days|months|years)" + SUPPORTED_DURATION_FORMAT = /\A\s*(\d+(\s+\b(seconds?|minutes?|hours?|days?|months?|years?)\b)?)\b\s*\z/i.freeze + def search_by_duration(_key, operator, value) + raise "Unsupported duration '#{value}' specified for searching" unless value =~ SUPPORTED_DURATION_FORMAT + value = value.strip + { :conditions => "coalesce(ended_at, current_timestamp) - coalesce(coalesce(started_at, ended_at), current_timestamp) #{operator} ?::interval", + :parameter => [value] } end end end end