user_observer.rb 626 Bytes
Newer Older
1
2
class UserObserver < ActiveRecord::Observer
  def after_create(user)
randx's avatar
randx committed
3
4
    log_info("User \"#{user.name}\" (#{user.email}) was created")

5
    Notify.delay.new_user_email(user.id, user.password)
6
  end
randx's avatar
randx committed
7
8
9
10
11

  def after_destroy user
    log_info("User \"#{user.name}\" (#{user.email})  was removed")
  end

12
  def after_save user
13
14
15
16
    if user.username_changed?
      if user.namespace
        user.namespace.update_attributes(path: user.username)
      else
17
        user.create_namespace!(path: user.username, name: user.username)
18
      end
19
20
21
    end
  end

randx's avatar
randx committed
22
23
24
25
26
  protected

  def log_info message
    Gitlab::AppLogger.info message
  end
27
end