aboutsummaryrefslogtreecommitdiffstats
path: root/app/models/blog_comment.rb
blob: 37e11ac49723a2955ab75a55f2e4ce8edd35d107 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
class BlogComment < ActiveRecord::Base

  belongs_to :post, :class_name => 'BlogPost'

  acts_as_indexed :fields => [:name, :email, :body]

  named_scope :unmoderated, :conditions => {:state => nil}
  named_scope :approved, :conditions => {:state => 'approved'}
  named_scope :rejected, :conditions => {:state => 'rejected'}

  module Moderation
    class << self
      def enabled?
        RefinerySetting.find_or_set(:comment_moderation, true, {:scoping => :blog})
      end

      def toggle
        RefinerySetting[:comment_moderation] = {:value => !self.enabled?, :scoping => :blog}
      end
    end
  end

  module Notification
    class << self
      def recipients
        RefinerySetting.find_or_set(
          :comment_notification_recipients, (Role[:refinery].users.first.email rescue ''), {:scoping => :blog}
        )
      end

      def recipients=(emails)
        RefinerySetting[:comment_notification_recipients] = {:value => emails, :scoping => :blog}
      end
    end
  end

end