app/models/foreman_tasks/task.rb in foreman-tasks-0.7.6 vs app/models/foreman_tasks/task.rb in foreman-tasks-0.7.7
- old
+ new
@@ -11,10 +11,14 @@
belongs_to :parent_task, :class_name => 'ForemanTasks::Task'
has_many :sub_tasks, :class_name => 'ForemanTasks::Task', :foreign_key => :parent_task_id
has_many :locks
+ has_many :task_group_members
+ has_many :task_groups, :through => :task_group_members
+ has_many :recurring_logic_task_groups, :through => :task_group_members, :conditions => { :type => 'ForemanTasks::TaskGroups::RecurringLogicTaskGroup' }, :source => :task_group
+
# in fact, the task has only one owner but Rails don't let you to
# specify has_one relation though has_many relation
has_many :owners, :through => :locks, :source => :resource, :source_type => 'User',
:conditions => ["foreman_tasks_locks.name = ?", Lock::OWNER_LOCK_NAME]
@@ -28,10 +32,11 @@
scoped_search :in => :locks, :on => :resource_type, :complete_value => true, :rename => "resource_type", :ext_method => :search_by_generic_resource
scoped_search :in => :locks, :on => :resource_id, :complete_value => false, :rename => "resource_id", :ext_method => :search_by_generic_resource
scoped_search :in => :owners, :on => :id, :complete_value => true, :rename => "owner.id", :ext_method => :search_by_owner
scoped_search :in => :owners, :on => :login, :complete_value => true, :rename => "owner.login", :ext_method => :search_by_owner
scoped_search :in => :owners, :on => :firstname, :complete_value => true, :rename => "owner.firstname", :ext_method => :search_by_owner
+ scoped_search :in => :task_groups, :on => :id, :complete_value => true, :rename => "task_group.id"
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|
@@ -137,9 +142,14 @@
end
def self.authorized_resource_name
# We don't want STI subclasses to have separate permissions
'ForemanTasks::Task'
+ end
+
+ def add_missing_task_groups(groups)
+ groups = [groups] unless groups.is_a? Array
+ (groups - task_groups).each { |group| task_groups << group }
end
protected
def generate_id