aboutsummaryrefslogtreecommitdiff
blob: a67e7dc64b6209c16850ed5f3007771141c08f21 (plain)
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
class Comment < ActiveRecord::Base

  hobo_model # Don't put anything above this

  fields do
    content HoboFields::MarkdownString, :null => false
    timestamps
  end

  belongs_to    :answer, :null => false

  validates_presence_of :content

  after_create :notify_new_comment

  owned_model "User"

  def create_permitted?
    answer.owner.mentor_is?(acting_user) && owned_soft?
  end

  def view_permitted?(field)
    # only recruiters, mentor who created comment
    # and recruit who owns answer can view
    return true if owner_is?(acting_user)
    return true if answer.owner_is?(acting_user)
    return true if acting_user.role.is_recruiter?

    false
  end

  protected
    def notify_new_comment
      UserMailer.deliver_new_comment(answer.owner, self)
    end
end