summaryrefslogtreecommitdiff
path: root/app/models/user.rb
diff options
context:
space:
mode:
authorValeriy Sizov <vsv2711@gmail.com>2012-10-09 01:17:38 -0700
committerValeriy Sizov <vsv2711@gmail.com>2012-10-09 01:17:38 -0700
commitdc33f71b181d154c8d9937f777fa16e9cf1d968d (patch)
tree1424eedeeeb4a9016d0f6dc5a5986c17e74e9122 /app/models/user.rb
parentc348284fedb487474626b3dae9be73311f8382df (diff)
parenta4cd738686659314f0bb9fd13a80845dc2b036ab (diff)
downloadgitlab-ce-dc33f71b181d154c8d9937f777fa16e9cf1d968d.tar.gz
Merge pull request #1656 from zzet/refactoring
Refactoring
Diffstat (limited to 'app/models/user.rb')
-rw-r--r--app/models/user.rb69
1 files changed, 36 insertions, 33 deletions
diff --git a/app/models/user.rb b/app/models/user.rb
index cf12fd60708..da0e9a0a202 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -27,53 +27,56 @@ class User < ActiveRecord::Base
validates :extern_uid, :allow_blank => true, :uniqueness => {:scope => :provider}
validates :projects_limit, presence: true, numericality: {greater_than_or_equal_to: 0}
- scope :not_in_project, lambda { |project| where("id not in (:ids)", ids: project.users.map(&:id) ) }
- scope :admins, where(admin: true)
- scope :blocked, where(blocked: true)
- scope :active, where(blocked: false)
-
before_validation :generate_password, on: :create
before_save :ensure_authentication_token
alias_attribute :private_token, :authentication_token
- def generate_password
- if self.force_random_password
- self.password = self.password_confirmation = Devise.friendly_token.first(8)
+ # Scopes
+ scope :not_in_project, ->(project) { where("id not in (:ids)", ids: project.users.map(&:id) ) }
+ scope :admins, where(admin: true)
+ scope :blocked, where(blocked: true)
+ scope :active, where(blocked: false)
+
+ class << self
+ def filter filter_name
+ case filter_name
+ when "admins"; self.admins
+ when "blocked"; self.blocked
+ when "wop"; self.without_projects
+ else
+ self.active
+ end
end
- end
- def self.filter filter_name
- case filter_name
- when "admins"; self.admins
- when "blocked"; self.blocked
- when "wop"; self.without_projects
- else
- self.active
+ def without_projects
+ where('id NOT IN (SELECT DISTINCT(user_id) FROM users_projects)')
end
- end
- def self.without_projects
- where('id NOT IN (SELECT DISTINCT(user_id) FROM users_projects)')
- end
+ def create_from_omniauth(auth, ldap = false)
+ gitlab_auth.create_from_omniauth(auth, ldap)
+ end
- def self.create_from_omniauth(auth, ldap = false)
- gitlab_auth.create_from_omniauth(auth, ldap)
- end
+ def find_or_new_for_omniauth(auth)
+ gitlab_auth.find_or_new_for_omniauth(auth)
+ end
- def self.find_or_new_for_omniauth(auth)
- gitlab_auth.find_or_new_for_omniauth(auth)
- end
+ def find_for_ldap_auth(auth, signed_in_resource = nil)
+ gitlab_auth.find_for_ldap_auth(auth, signed_in_resource)
+ end
- def self.find_for_ldap_auth(auth, signed_in_resource = nil)
- gitlab_auth.find_for_ldap_auth(auth, signed_in_resource)
- end
+ def gitlab_auth
+ Gitlab::Auth.new
+ end
- def self.gitlab_auth
- Gitlab::Auth.new
+ def search query
+ where("name LIKE :query or email LIKE :query", query: "%#{query}%")
+ end
end
- def self.search query
- where("name LIKE :query OR email LIKE :query", query: "%#{query}%")
+ def generate_password
+ if self.force_random_password
+ self.password = self.password_confirmation = Devise.friendly_token.first(8)
+ end
end
end