<commit_before># == Schema Information
# Schema version: 20101101011500
#
# Table name: user_school_assignments
#
#  id         :integer(4)      not null, primary key
#  school_id  :integer(4)
#  user_id    :integer(4)
#  admin      :boolean(1)
#  created_at :datetime
#  updated_at :datetime
#

class UserSchoolAssignment < ActiveRecord::Base
  belongs_to :school
  belongs_to :user

  # Need to be able to create these before assigning them to a parent...
  # validates_presence_of :school_id
  # validates_presence_of :user_id

  named_scope :admin, :conditions => {:admin => true}
  after_save :create_all_students
  after_destroy :remove_special_user_groups

  def all_students
    !!user.special_user_groups.find_by_school_id_and_grade_and_grouptype(school_id, nil, SpecialUserGroup::ALL_STUDENTS_IN_SCHOOL) if user
  end

  def all_students=(val)
    if val =="true"
      @all_students=true

    elsif val == "false"
      @all_students=false
    end

  end

private
  def remove_special_user_groups
    SpecialUserGroup.delete_all("user_id = #{user_id} and school_id = #{school_id}")
  end

  def create_all_students<commit_msg>add non_admin scope for user_school_assignments<commit_after># == Schema Information
# Schema version: 20101101011500
#
# Table name: user_school_assignments
#
#  id         :integer(4)      not null, primary key
#  school_id  :integer(4)
#  user_id    :integer(4)
#  admin      :boolean(1)
#  created_at :datetime
#  updated_at :datetime
#

class UserSchoolAssignment < ActiveRecord::Base
  belongs_to :school
  belongs_to :user

  # Need to be able to create these before assigning them to a parent...
  # validates_presence_of :school_id
  # validates_presence_of :user_id

  named_scope :admin, :conditions => {:admin => true}
  named_scope :non_admin, :conditions => {:admin => false}
  after_save :create_all_students
  after_destroy :remove_special_user_groups

  def all_students
    !!user.special_user_groups.find_by_school_id_and_grade_and_grouptype(school_id, nil, SpecialUserGroup::ALL_STUDENTS_IN_SCHOOL) if user
  end

  def all_students=(val)
    if val =="true"
      @all_students=true

    elsif val == "false"
      @all_students=false
    end

  end

private
  def remove_special_user_groups
    SpecialUserGroup.delete_all("user_id = #{user_id} and school_id = #{school_id}")
  end

  def create_all_students
{'fraction_non_alphanumeric': 0.08618504435994931, 'fraction_numerical': 0.015209125475285171, 'mean_word_length': 4.357466063348416, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, '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': '2631112', 'n_tokens_mistral': 845, 'n_tokens_neox': 807, 'n_words': 186}