app/models/foreman_tasks/task.rb in foreman-tasks-3.0.6 vs app/models/foreman_tasks/task.rb in foreman-tasks-4.0.0
- old
+ new
@@ -29,10 +29,11 @@
has_many :task_group_members, :dependent => :destroy
has_many :task_groups, :through => :task_group_members
has_many :recurring_logic_task_groups, -> { where :type => 'ForemanTasks::TaskGroups::RecurringLogicTaskGroup' },
:through => :task_group_members, :source => :task_group
belongs_to :user
+ has_many :links, :dependent => :destroy
scoped_search :on => :id, :complete_value => false
scoped_search :on => :action, :complete_value => false
scoped_search :on => :label, :complete_value => true
scoped_search :on => :state, :complete_value => true
@@ -44,14 +45,20 @@
scoped_search :on => :parent_task_id, :complete_value => true
scoped_search :on => :duration, :complete_value => false, :ext_method => :search_by_duration, :operators => %w[> >= = <= <], :only_explicit => true
# Note: the following searches may return duplicates, this is due to
# one task maybe having multiple locks (e.g. read/write) for the same resource_id
- 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
- scoped_search :relation => :locks, :on => :resource_type, :complete_value => true, :rename => 'resource_type', :ext_method => :search_by_generic_resource, :only_explicit => true
- scoped_search :relation => :locks, :on => :resource_id, :complete_value => false, :rename => 'resource_id', :ext_method => :search_by_generic_resource, :only_explicit => true
+ scoped_search :relation => :locks, :on => :resource_id, :complete_value => false, :rename => 'locked_location_id', :ext_method => :search_by_taxonomy, :only_explicit => true
+ scoped_search :relation => :locks, :on => :resource_id, :complete_value => false, :rename => 'locked_organization_id', :ext_method => :search_by_taxonomy, :only_explicit => true
+ scoped_search :relation => :locks, :on => :resource_type, :complete_value => true, :rename => 'locked_resource_type', :ext_method => :search_by_generic_resource, :only_explicit => true
+ scoped_search :relation => :locks, :on => :resource_id, :complete_value => false, :rename => 'locked_resource_id', :ext_method => :search_by_generic_resource, :only_explicit => true
+
+ scoped_search :relation => :links, :on => :resource_id, :complete_value => false, :rename => 'location_id', :ext_method => :search_by_taxonomy, :only_explicit => true
+ scoped_search :relation => :links, :on => :resource_id, :complete_value => false, :rename => 'organization_id', :ext_method => :search_by_taxonomy, :only_explicit => true
+ scoped_search :relation => :links, :on => :resource_type, :complete_value => true, :rename => 'resource_type', :ext_method => :search_by_generic_resource, :only_explicit => true
+ scoped_search :relation => :links, :on => :resource_id, :complete_value => false, :rename => 'resource_id', :ext_method => :search_by_generic_resource, :only_explicit => true
+
scoped_search :on => :user_id,
:complete_value => true,
:rename => 'user.id',
:validator => ->(value) { ScopedSearch::Validators::INTEGER.call(value) },
:value_translation => ->(value) { value == 'current_user' ? User.current.id : value },
@@ -63,12 +70,12 @@
scope :active, -> { where('foreman_tasks_tasks.state != ?', :stopped) }
scope :running, -> { where("foreman_tasks_tasks.state NOT IN ('stopped', 'paused')") }
scope :for_resource,
(lambda do |resource|
- joins(:locks).where(:"foreman_tasks_locks.resource_id" => resource.id,
- :"foreman_tasks_locks.resource_type" => resource.class.name)
+ joins(:links).where(:"foreman_tasks_links.resource_id" => resource.id,
+ :"foreman_tasks_links.resource_type" => resource.class.name)
end)
scope :for_action_types, (->(action_types) { where('foreman_tasks_tasks.label IN (?)', Array(action_types)) })
apipie :class, "A class representing #{model_name.human} object" do
name 'Task'
@@ -80,11 +87,11 @@
property :result, String, desc: 'Returns result of the task execution, e.g. "success"'
property :started_at, ActiveSupport::TimeWithZone, desc: 'Returns date with time the task started at'
property :ended_at, ActiveSupport::TimeWithZone, desc: 'Returns date with time the task ended at'
end
class Jail < Safemode::Jail
- allow :started_at, :ended_at, :result, :state, :label, :main_action
+ allow :started_at, :ended_at, :result, :state, :label, :main_action, :action_output
end
def input
{}
end
@@ -238,9 +245,15 @@
else
part.to_s
end
end.join('; ')
parts.join(' ').strip
+ end
+
+ def action_output
+ return unless main_action.is_a?(Actions::Helpers::WithContinuousOutput)
+ main_action.continuous_output.sort!
+ main_action.continuous_output.raw_outputs
end
protected
def generate_id