<commit_before>class TeamsUser < ActiveRecord::Base
  belongs_to :user
  belongs_to :team
  has_one :team_user_node, foreign_key: 'node_object_id', dependent: :destroy
  has_paper_trail
  attr_accessible :user_id, :team_id

  def name
    self.user.name
  end

  def delete
    TeamUserNode.find_by_node_object_id(self.id).destroy
    team = self.team
    self.destroy
    team.delete if team.teams_users.empty?
  end

  def get_team_members(team_id)
  end

  # Removes entry in the TeamUsers table for the given user and given team id
  def self.remove_team(user_id, team_id)
    team_user = TeamsUser.where(['user_id = ? and team_id = ?', user_id, team_id]).first
    team_user.destroy unless team_user.nil?
  end

  # Returns the first entry in the TeamUsers table for a given team id
  def self.first_by_team_id(team_id)
    TeamsUser.where("team_id = ?", team_id).first
  end

  # Determines whether a team is empty of not
  def self.is_team_empty(team_id)
    team_members = TeamsUser.where("team_id = ?", team_id)
    team_members.nil? || team_members.empty?
  end

  # Add member to the team they were invited to and accepted the invite for
  def self.add_member_to_invited_team(invitee_user_id, invited_user_id, assignment_id)
    users_teams = TeamsUser.where(['user_id = ?', invitee_user_id])
    for team in users_teams
      new_team = AssignmentTeam.where(['id = ? and parent_id = ?', team.team_id, assignment_id]).first
      unless new_team.nil?
        can_add_member = new_team.add_member(User.find(invited_user_id), assignment_id)
      end
    end
    can_add_member<commit_msg>Added type checks for security update<commit_after>class TeamsUser < ActiveRecord::Base
  belongs_to :user
  belongs_to :team
  has_one :team_user_node, foreign_key: 'node_object_id', dependent: :destroy
  has_paper_trail
  attr_accessible :user_id, :team_id

  def name
    self.user.name
  end

  def delete
    TeamUserNode.find_by_node_object_id(self.id).destroy
    team = self.team
    self.destroy
    team.delete if team.teams_users.empty?
  end

  def get_team_members(team_id)
  end

  # Removes entry in the TeamUsers table for the given user and given team id
  def self.remove_team(user_id, team_id)
    if !(user_id.is_a? Integer and team_id.is_a? Integer)
      flash[:error] = "Illegal parameter."
    else
      team_user = TeamsUser.where(['user_id = ? and team_id = ?', user_id, team_id]).first
      team_user.destroy unless team_user.nil?
    end
  end

  # Returns the first entry in the TeamUsers table for a given team id
  def self.first_by_team_id(team_id)
    TeamsUser.where("team_id = ?", team_id).first
  end

  # Determines whether a team is empty of not
  def self.is_team_empty(team_id)
    team_members = TeamsUser.where("team_id = ?", team_id)
    team_members.nil? || team_members.empty?
  end

  # Add member to the team they were invited to and accepted the invite for
  def self.add_member_to_invited_team(invitee_user_id, invited_user_id, assignment_id)
    users_teams = TeamsUser.where(['user_id = ?', invitee_user_id])
    for team in users_teams
      new_team = AssignmentTeam.where(['id = ? and parent_id = ?', team.team_id, assignment_id]).first
      unless new_team.nil?
        can_add_member = new_team.add_member(User.find(invited_user_id), assignment_id)
      end
    end
    can_add_member
{'fraction_non_alphanumeric': 0.08378216636744465, 'fraction_numerical': 0.0, 'mean_word_length': 3.86608442503639, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '4192754', 'n_tokens_mistral': 1158, 'n_tokens_neox': 1136, 'n_words': 283}