Sha256: bd31fbe893e6d9cb5f43d2361bedabaf4d8862019f47652066e6b4d2850a1447

Contents?: true

Size: 1.2 KB

Versions: 4

Compression:

Stored size: 1.2 KB

Contents

require_dependency 'spam_protection'
require 'timeout'

class Comment < Feedback
  belongs_to :user
  content_fields :body
  validates :author, :body, presence: true

  after_save :send_notifications

  attr_accessor :referrer, :permalink

  scope :spam, -> { where(state: 'spam') }
  scope :not_spam, -> { where("state != 'spam'") }
  scope :presumed_spam, -> { where(state: 'presumed_spam') }
  scope :presumed_ham, -> { where(state: 'presumed_ham') }
  scope :ham, -> { where(state: 'ham') }
  scope :unconfirmed, -> { where(state: %w(presumed_spam presumed_ham)) }

  scope :last_published, -> { published.limit(5).order('created_at DESC') }

  def notify_user_via_email(user)
    EmailNotify.send_comment(self, user) if user.notify_via_email?
  end

  def interested_users
    User.where(notify_on_comments: true)
  end

  def default_text_filter
    TextFilter.find_or_default(blog.comment_text_filter)
  end

  def feed_title
    "Comment on #{article.title} by #{author}"
  end

  protected

  def article_allows_feedback?
    return true if article.allow_comments?
    errors.add(:article, 'Article is not open to comments')
    false
  end

  def originator
    author
  end

  def content_fields
    [:body]
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
publify_core-9.0.0.pre4 app/models/comment.rb
publify_core-9.0.0.pre3 app/models/comment.rb
publify_core-9.0.0.pre2 app/models/comment.rb
publify_core-9.0.0.pre1 app/models/comment.rb