app/models/foreman_tasks/task.rb in foreman-tasks-0.15.1 vs app/models/foreman_tasks/task.rb in foreman-tasks-0.15.2
- old
+ new
@@ -13,10 +13,11 @@
# TODO: missing validation of states
self.primary_key = :id
before_create :generate_id
+ before_save :update_state_updated_at
belongs_to :parent_task, :class_name => 'ForemanTasks::Task'
has_many :sub_tasks, :class_name => 'ForemanTasks::Task', :foreign_key => :parent_task_id, :dependent => :nullify
has_many :locks, :dependent => :destroy
@@ -37,10 +38,11 @@
scoped_search :on => :action, :complete_value => false
scoped_search :on => :label, :complete_value => true
scoped_search :on => :state, :complete_value => true
scoped_search :on => :result, :complete_value => true
scoped_search :on => :started_at, :complete_value => false
+ scoped_search :on => :state_updated_at, :complete_value => false
scoped_search :on => :start_at, :complete_value => false
scoped_search :on => :ended_at, :complete_value => false
scoped_search :on => :parent_task_id, :complete_value => true
scoped_search :relation => :locks, :on => :resource_id, :complete_value => false, :rename => 'location_id', :ext_method => :search_by_taxonomy, :only_explicit => true
scoped_search :relation => :locks, :on => :resource_id, :complete_value => false, :rename => 'organization_id', :ext_method => :search_by_taxonomy, :only_explicit => true
@@ -144,10 +146,27 @@
[self].tap do |ret|
ret.concat(parent_task.self_and_parents) if parent_task
end
end
+ # used by Foreman notifications framework
+ def notification_recipients_ids
+ owner_ids
+ end
+
+ def build_notifications
+ notifications = []
+ if paused?
+ owner = self.owner
+ if owner && !owner.hidden?
+ notifications << UINotifications::Tasks::TaskPausedOwner.new(self)
+ end
+ notifications << UINotifications::Tasks::TaskPausedAdmin.new(self)
+ end
+ notifications
+ end
+
def self.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])
@@ -266,8 +285,12 @@
protected
def generate_id
self.id ||= SecureRandom.uuid
+ end
+
+ def update_state_updated_at
+ self.state_updated_at = Time.now.utc if changes.key?(:state)
end
end
end