users_project_observer.rb 552 Bytes
Newer Older
1
class UsersProjectObserver < ActiveRecord::Observer
2
  def after_commit(users_project)
3
    return if users_project.destroyed?
4
    Notify.delay.project_access_granted_email(users_project.id)
5
  end
Alex Denisov's avatar
Alex Denisov committed
6

Alex Denisov's avatar
Alex Denisov committed
7
  def after_create(users_project)
Alex Denisov's avatar
Alex Denisov committed
8
9
10
11
12
    Event.create(
      project_id: users_project.project.id,
      action: Event::Joined,
      author_id: users_project.user.id
    )
13
  end
14

Alex Denisov's avatar
Alex Denisov committed
15
16
  def after_destroy(users_project)
    Event.create(
randx's avatar
randx committed
17
18
      project_id: users_project.project.id,
      action: Event::Left,
Alex Denisov's avatar
Alex Denisov committed
19
20
21
      author_id: users_project.user.id
    )
  end
22
end