<commit_before># == Schema Information
#
# Table name: projects
#
#  id             :integer          not null, primary key
#  title          :string
#  created_at     :datetime         not null
#  updated_at     :datetime         not null
#  description    :string           default("")
#  public         :boolean          default(TRUE)
#  status         :boolean          default(TRUE)
#  chair_id       :integer
#  project_leader :string           default("")
#

class Project < ActiveRecord::Base
  scope :title, -> title { where('LOWER(title) LIKE ?', "%#{title.downcase}%") }
  scope :chair, -> name { joins(:chair).where('LOWER(name) LIKE ?', "%#{name.downcase}%") }

  has_and_belongs_to_many :users
  has_many :project_applications, dependent: :destroy
  has_many :invitations
  belongs_to :chair

  accepts_nested_attributes_for :invitations, allow_destroy: true

  validates :title, presence: true

  def invite_user(user, sender)
    if user && !user.is_superadmin?
      inv = Invitation.create(user: user, project: self, sender: sender)
      ActiveSupport::Notifications.instrument('event', {trigger: inv.id, target: user.id, seclevel: :hiwi, type: 'EventProjectInvitation'})
      user.invitations << inv<commit_msg>Validate that a chair is always present for a project<commit_after># == Schema Information
#
# Table name: projects
#
#  id             :integer          not null, primary key
#  title          :string
#  created_at     :datetime         not null
#  updated_at     :datetime         not null
#  description    :string           default("")
#  public         :boolean          default(TRUE)
#  status         :boolean          default(TRUE)
#  chair_id       :integer
#  project_leader :string           default("")
#

class Project < ActiveRecord::Base
  scope :title, -> title { where('LOWER(title) LIKE ?', "%#{title.downcase}%") }
  scope :chair, -> name { joins(:chair).where('LOWER(name) LIKE ?', "%#{name.downcase}%") }

  has_and_belongs_to_many :users
  has_many :project_applications, dependent: :destroy
  has_many :invitations
  belongs_to :chair

  accepts_nested_attributes_for :invitations, allow_destroy: true

  validates :title, presence: true
  validates :chair, presence: true

  def invite_user(user, sender)
    if user && !user.is_superadmin?
      inv = Invitation.create(user: user, project: self, sender: sender)
      ActiveSupport::Notifications.instrument('event', {trigger: inv.id, target: user.id, seclevel: :hiwi, type: 'EventProjectInvitation'})
      user.invitations << inv
{'fraction_non_alphanumeric': 0.11776289877904687, 'fraction_numerical': 0.0, 'mean_word_length': 3.1233766233766236, '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': '4586282', 'n_tokens_mistral': 762, 'n_tokens_neox': 750, 'n_words': 198}