<commit_before>#
# Copyright (C) 2011-2013 Instructure, Inc.
#
# This file is part of Canvas.
#
# Canvas is free software: you can redistribute it and/or modify it under
# the terms of the GNU Affero General Public License as published by the Free
# Software Foundation, version 3 of the License.
#
# Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
# details.
#
# You should have received a copy of the GNU Affero General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.
#

class InboxItem < ActiveRecord::Base
  # Included modules
  include Workflow

  # Associations
  belongs_to :asset,  :polymorphic => true
  belongs_to :author, :class_name => 'User', :foreign_key => :sender_id
  belongs_to :user

  # Callbacks
  before_save       :flag_changed
  before_save       :infer_context_code
  before_validation :trim_subject
  after_destroy     :update_user_inbox_items_count
  after_save        :update_user_inbox_items_count

  # Validations
  validates_length_of :subject, :maximum => 255

  # Access control
  attr_accessible :user_id, :asset, :subject, :body_teaser, :sender_id

  # Named scopes
  named_scope :active, :conditions => ['workflow_state NOT IN ?',
    %w{deleted retired retired_unread}]
  named_scope :unread, lambda {
    { :conditions => ['workflow_state = ?', 'unread'] } }

  # State machine
  workflow do
    state :unread
    state :read
    state :deleted
    state :retired
    state :retired_unread
  end
<commit_msg>fix bad sql in refactored named scope<commit_after>#
# Copyright (C) 2011-2013 Instructure, Inc.
#
# This file is part of Canvas.
#
# Canvas is free software: you can redistribute it and/or modify it under
# the terms of the GNU Affero General Public License as published by the Free
# Software Foundation, version 3 of the License.
#
# Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
# details.
#
# You should have received a copy of the GNU Affero General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.
#

class InboxItem < ActiveRecord::Base
  # Included modules
  include Workflow

  # Associations
  belongs_to :asset,  :polymorphic => true
  belongs_to :author, :class_name => 'User', :foreign_key => :sender_id
  belongs_to :user

  # Callbacks
  before_save       :flag_changed
  before_save       :infer_context_code
  before_validation :trim_subject
  after_destroy     :update_user_inbox_items_count
  after_save        :update_user_inbox_items_count

  # Validations
  validates_length_of :subject, :maximum => 255

  # Access control
  attr_accessible :user_id, :asset, :subject, :body_teaser, :sender_id

  # Named scopes
  named_scope :active, :conditions => "workflow_state NOT IN ('deleted', 'retired', 'retired_unread')"
  named_scope :unread, :conditions => {:workflow_state => 'unread'}

  # State machine
  workflow do
    state :unread
    state :read
    state :deleted
    state :retired
    state :retired_unread
  end

{'fraction_non_alphanumeric': 0.07720036046860919, 'fraction_numerical': 0.00720937218383899, 'mean_word_length': 4.030211480362538, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 18, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '2725081', 'n_tokens_mistral': 1026, 'n_tokens_neox': 988, 'n_words': 365}