aboutsummaryrefslogtreecommitdiff
blob: 1c56454f53b60496c9ee267b0f6b23d2ba732fcd (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
class Comment < ActiveRecord::Base

  hobo_model # Don't put anything above this

  fields do
    content :text
    timestamps
  end
  belongs_to    :answer

  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
    owner_is?(acting_user) || answer.owner_is?(acting_user) ||
      acting_user.try.role.try.is_recruiter?
  end

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