<commit_before>class Task < ActiveRecord::Base
  include EventStreamNotifier
  include Commentable

  cattr_accessor :metadata_types

  default_scope { order("completed ASC") }

  after_initialize :initialize_defaults

  scope :completed,   -> { where(completed: true) }
  scope :metadata,    -> { where(type: metadata_types) }
  scope :incomplete,  -> { where(completed: false) }
  scope :unassigned,  -> { where(assignee: nil) }

  has_one :paper, through: :phase
  has_one :journal, through: :paper
  has_many :questions, inverse_of: :task
  has_many :participations, inverse_of: :task, dependent: :destroy
  has_many :participants, through: :participations

  validates :title, :role, presence: true
  validates :title, length: { maximum: 255 }

  belongs_to :assignee, class_name: 'User'
  belongs_to :phase, inverse_of: :tasks

  delegate :assignees, to: :paper

  def self.assigned_to(*users)
    #TODO: this is a stopgap until user <-> task relationship table can be established
    assigned_tasks   = Task.where.not(type: "MessageTask").where(assignee: users).pluck(:id)
    message_tasks    = MessageTask.joins(phase: :paper).where("papers.id" => Paper.where(user: users)).pluck(:id)

    where(id: (assigned_tasks + message_tasks))
  end

  def self.for_admins
    where(role: 'admin')
  end

  def self.without(task)
    where.not(id: task.id)
  end

  def is_metadata?
    Task.metadata_types.include?(self.class.name)
  end

  def array_attributes
    [:body, :participant_ids]
  end

  def permitted_attributes
    [:assignee_id, :completed, :title, :phase_id, body: [:type, :value, :answer], participant_ids: []]
  end

  class << self
    attr_reader :_default_title, :_default_role

    %w(title role).each do |attr|
      define_method attr do |default_attr|
        instance_variable_set :"@_default_#{attr}", default_attr
      end
    end
  end

  def update_responder<commit_msg>Allow body to be persisted<commit_after>class Task < ActiveRecord::Base
  include EventStreamNotifier
  include Commentable

  cattr_accessor :metadata_types

  default_scope { order("completed ASC") }

  after_initialize :initialize_defaults

  scope :completed,   -> { where(completed: true) }
  scope :metadata,    -> { where(type: metadata_types) }
  scope :incomplete,  -> { where(completed: false) }
  scope :unassigned,  -> { where(assignee: nil) }

  has_one :paper, through: :phase
  has_one :journal, through: :paper
  has_many :questions, inverse_of: :task
  has_many :participations, inverse_of: :task, dependent: :destroy
  has_many :participants, through: :participations

  validates :title, :role, presence: true
  validates :title, length: { maximum: 255 }

  belongs_to :assignee, class_name: 'User'
  belongs_to :phase, inverse_of: :tasks

  delegate :assignees, to: :paper

  def self.assigned_to(*users)
    #TODO: this is a stopgap until user <-> task relationship table can be established
    assigned_tasks   = Task.where.not(type: "MessageTask").where(assignee: users).pluck(:id)
    message_tasks    = MessageTask.joins(phase: :paper).where("papers.id" => Paper.where(user: users)).pluck(:id)

    where(id: (assigned_tasks + message_tasks))
  end

  def self.for_admins
    where(role: 'admin')
  end

  def self.without(task)
    where.not(id: task.id)
  end

  def is_metadata?
    Task.metadata_types.include?(self.class.name)
  end

  def array_attributes
    [:body, :participant_ids]
  end

  def permitted_attributes
    [:assignee_id, :completed, :title, :phase_id, :body, participant_ids: []]
  end

  class << self
    attr_reader :_default_title, :_default_role

    %w(title role).each do |attr|
      define_method attr do |default_attr|
        instance_variable_set :"@_default_#{attr}", default_attr
      end
    end
  end

  def update_responder
{'fraction_non_alphanumeric': 0.11418776371308016, 'fraction_numerical': 0.0015822784810126582, 'mean_word_length': 4.153532608695652, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '871919', 'n_tokens_mistral': 1297, 'n_tokens_neox': 1221, 'n_words': 308}