<commit_before>class Participant < ActiveRecord::Base
  has_paper_trail
  belongs_to :user
  belongs_to :topic, class_name: 'SignUpTopic'
  belongs_to :assignment, foreign_key: 'parent_id'
  has_many   :join_team_requests, dependent: :destroy
  has_many   :comments, dependent: :destroy
  has_many   :reviews, class_name: 'ResponseMap', foreign_key: 'reviewer_id', dependent: :destroy
  has_many   :team_reviews, class_name: 'ReviewResponseMap', foreign_key: 'reviewer_id', dependent: :destroy
  has_many :response_maps, class_name: 'ResponseMap', foreign_key: 'reviewee_id', dependent: :destroy
  has_one :review_grade

  PARTICIPANT_TYPES = %w(Course Assignment).freeze

  def team
    TeamsUser.where(user: user).first.try :team
  end

  def responses
    response_maps.map(&:response)
  end

  validates_numericality_of :grade, allow_nil: true

  delegate :course, to: :assignment

  has_paper_trail

  def get_current_stage
    assignment.try :get_current_stage, topic_id
  end

  def stage_deadline
    assignment.stage_deadline topic_id
  end

  def name
    User.find(self.user_id).name
  end

  def fullname
    User.find(self.user_id).fullname
  end

  def delete(force = nil)
    # TODO: How do we test this code?  #need a controller test_oss808
    maps = ResponseMap.where(['reviewee_id = ? or reviewer_id = ?', self.id, self.id])

    if force or ((maps.nil? or maps.empty?) and
                 self.team.nil?)
      force_delete(maps)
    else
      raise "Associations exist for this participant."
    end
    end

  def force_delete(maps)
    maps.each {|map| map.delete(true) } if maps

    if self.team
      if self.team.teams_users.length == 1
        self.team.delete
      else
        self.team.teams_users.each do |tuser|
          tuser.delete if tuser.user_id == self.id
        end
      end
    end
    self.destroy
  end

  def topic_name
    return "<center>&#8212;</center>" if topic.nil? or topic.topic_name.empty?
    topic.topic_name
  end<commit_msg>Added type check for security update<commit_after>class Participant < ActiveRecord::Base
  has_paper_trail
  belongs_to :user
  belongs_to :topic, class_name: 'SignUpTopic'
  belongs_to :assignment, foreign_key: 'parent_id'
  has_many   :join_team_requests, dependent: :destroy
  has_many   :comments, dependent: :destroy
  has_many   :reviews, class_name: 'ResponseMap', foreign_key: 'reviewer_id', dependent: :destroy
  has_many   :team_reviews, class_name: 'ReviewResponseMap', foreign_key: 'reviewer_id', dependent: :destroy
  has_many :response_maps, class_name: 'ResponseMap', foreign_key: 'reviewee_id', dependent: :destroy
  has_one :review_grade

  PARTICIPANT_TYPES = %w(Course Assignment).freeze

  def team
    TeamsUser.where(user: user).first.try :team
  end

  def responses
    response_maps.map(&:response)
  end

  validates_numericality_of :grade, allow_nil: true

  delegate :course, to: :assignment

  has_paper_trail

  def get_current_stage
    assignment.try :get_current_stage, topic_id
  end

  def stage_deadline
    assignment.stage_deadline topic_id
  end

  def name
    User.find(self.user_id).name
  end

  def fullname
    User.find(self.user_id).fullname
  end

  def delete(force = nil)
    # TODO: How do we test this code?  #need a controller test_oss808
    if !id.is_a? Integer
      flash[:error] = "Illegal parameter."
    else
      maps = ResponseMap.where(['reviewee_id = ? or reviewer_id = ?', self.id, self.id])
    end

    if force or ((maps.nil? or maps.empty?) and
                 self.team.nil?)
      force_delete(maps)
    else
      raise "Associations exist for this participant."
    end
    end

  def force_delete(maps)
    maps.each {|map| map.delete(true) } if maps

    if self.team
      if self.team.teams_users.length == 1
        self.team.delete
      else
        self.team.teams_users.each do |tuser|
          tuser.delete if tuser.user_id == self.id
        end
      end
    end
    self.destroy
  end

  def topic_name
    return "<center>&#8212;</center>" if topic.nil? or topic.topic_name.empty?
    topic.topic_name
  end
{'fraction_non_alphanumeric': 0.09255631733594515, 'fraction_numerical': 0.0039177277179236044, 'mean_word_length': 3.322751322751323, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 7, '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': '7215844', 'n_tokens_mistral': 1393, 'n_tokens_neox': 1362, 'n_words': 338}