summaryrefslogtreecommitdiff
path: root/app/models/user.rb
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2014-06-17 22:32:35 +0300
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2014-06-17 22:32:35 +0300
commita90a201d0ee3c9e33cc04075ac8a2509c1d2acc9 (patch)
treef188438bd919e4ae20f4f48725cb7b77927970d9 /app/models/user.rb
parenta7d5052cd4e117768d9c32f582ed72d2cc98e5e6 (diff)
downloadgitlab-ce-a90a201d0ee3c9e33cc04075ac8a2509c1d2acc9.tar.gz
Remove user observer
Diffstat (limited to 'app/models/user.rb')
-rw-r--r--app/models/user.rb36
1 files changed, 36 insertions, 0 deletions
diff --git a/app/models/user.rb b/app/models/user.rb
index 2352f8c050b..5e371e2c60b 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -132,6 +132,10 @@ class User < ActiveRecord::Base
before_validation :sanitize_attrs
before_save :ensure_authentication_token
+ after_save :ensure_namespace_correct
+ after_create :post_create_hook
+ after_destroy :post_destroy_hook
+
alias_attribute :private_token, :authentication_token
@@ -490,4 +494,36 @@ class User < ActiveRecord::Base
GravatarService.new.execute(email, size)
end
end
+
+ def ensure_namespace_correct
+ # Ensure user has namespace
+ self.create_namespace!(path: self.username, name: self.username) unless self.namespace
+
+ if self.username_changed?
+ self.namespace.update_attributes(path: self.username, name: self.username)
+ end
+ end
+
+ def post_create_hook
+ log_info("User \"#{self.name}\" (#{self.email}) was created")
+ notification.new_user(self)
+ system_hook_service.execute_hooks_for(self, :create)
+ end
+
+ def post_destroy_hook
+ log_info("User \"#{self.name}\" (#{self.email}) was removed")
+ system_hook_service.execute_hooks_for(self, :destroy)
+ end
+
+ def notification
+ NotificationService.new
+ end
+
+ def log_info message
+ Gitlab::AppLogger.info message
+ end
+
+ def system_hook_service
+ SystemHooksService.new
+ end
end