Code cleanup.
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@10881 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
96e01c6d4a
commit
457f0bb337
@ -114,11 +114,11 @@ class User < Principal
|
|||||||
|
|
||||||
scope :in_group, lambda {|group|
|
scope :in_group, lambda {|group|
|
||||||
group_id = group.is_a?(Group) ? group.id : group.to_i
|
group_id = group.is_a?(Group) ? group.id : group.to_i
|
||||||
{ :conditions => ["#{User.table_name}.id IN (SELECT gu.user_id FROM #{table_name_prefix}groups_users#{table_name_suffix} gu WHERE gu.group_id = ?)", group_id] }
|
where("#{User.table_name}.id IN (SELECT gu.user_id FROM #{table_name_prefix}groups_users#{table_name_suffix} gu WHERE gu.group_id = ?)", group_id)
|
||||||
}
|
}
|
||||||
scope :not_in_group, lambda {|group|
|
scope :not_in_group, lambda {|group|
|
||||||
group_id = group.is_a?(Group) ? group.id : group.to_i
|
group_id = group.is_a?(Group) ? group.id : group.to_i
|
||||||
{ :conditions => ["#{User.table_name}.id NOT IN (SELECT gu.user_id FROM #{table_name_prefix}groups_users#{table_name_suffix} gu WHERE gu.group_id = ?)", group_id] }
|
where("#{User.table_name}.id NOT IN (SELECT gu.user_id FROM #{table_name_prefix}groups_users#{table_name_suffix} gu WHERE gu.group_id = ?)", group_id)
|
||||||
}
|
}
|
||||||
|
|
||||||
def set_mail_notification
|
def set_mail_notification
|
||||||
@ -360,10 +360,10 @@ class User < Principal
|
|||||||
# version. Exact matches will be given priority.
|
# version. Exact matches will be given priority.
|
||||||
def self.find_by_login(login)
|
def self.find_by_login(login)
|
||||||
# First look for an exact match
|
# First look for an exact match
|
||||||
user = all(:conditions => {:login => login}).detect {|u| u.login == login}
|
user = where(:login => login).all.detect {|u| u.login == login}
|
||||||
unless user
|
unless user
|
||||||
# Fail over to case-insensitive if none was found
|
# Fail over to case-insensitive if none was found
|
||||||
user = first(:conditions => ["LOWER(login) = ?", login.to_s.downcase])
|
user = where("LOWER(login) = ?", login.to_s.downcase).first
|
||||||
end
|
end
|
||||||
user
|
user
|
||||||
end
|
end
|
||||||
@ -380,7 +380,7 @@ class User < Principal
|
|||||||
|
|
||||||
# Makes find_by_mail case-insensitive
|
# Makes find_by_mail case-insensitive
|
||||||
def self.find_by_mail(mail)
|
def self.find_by_mail(mail)
|
||||||
find(:first, :conditions => ["LOWER(mail) = ?", mail.to_s.downcase])
|
where("LOWER(mail) = ?", mail.to_s.downcase).first
|
||||||
end
|
end
|
||||||
|
|
||||||
# Returns true if the default admin account can no longer be used
|
# Returns true if the default admin account can no longer be used
|
||||||
@ -540,7 +540,7 @@ class User < Principal
|
|||||||
# Returns true if the user is allowed to delete his own account
|
# Returns true if the user is allowed to delete his own account
|
||||||
def own_account_deletable?
|
def own_account_deletable?
|
||||||
Setting.unsubscribe? &&
|
Setting.unsubscribe? &&
|
||||||
(!admin? || User.active.first(:conditions => ["admin = ? AND id <> ?", true, id]).present?)
|
(!admin? || User.active.where("admin = ? AND id <> ?", true, id).exists?)
|
||||||
end
|
end
|
||||||
|
|
||||||
safe_attributes 'login',
|
safe_attributes 'login',
|
||||||
@ -611,7 +611,7 @@ class User < Principal
|
|||||||
# Returns the anonymous user. If the anonymous user does not exist, it is created. There can be only
|
# Returns the anonymous user. If the anonymous user does not exist, it is created. There can be only
|
||||||
# one anonymous user per database.
|
# one anonymous user per database.
|
||||||
def self.anonymous
|
def self.anonymous
|
||||||
anonymous_user = AnonymousUser.find(:first)
|
anonymous_user = AnonymousUser.first
|
||||||
if anonymous_user.nil?
|
if anonymous_user.nil?
|
||||||
anonymous_user = AnonymousUser.create(:lastname => 'Anonymous', :firstname => '', :mail => '', :login => '', :status => 0)
|
anonymous_user = AnonymousUser.create(:lastname => 'Anonymous', :firstname => '', :mail => '', :login => '', :status => 0)
|
||||||
raise 'Unable to create the anonymous user.' if anonymous_user.new_record?
|
raise 'Unable to create the anonymous user.' if anonymous_user.new_record?
|
||||||
@ -624,7 +624,7 @@ class User < Principal
|
|||||||
# This method is used in the SaltPasswords migration and is to be kept as is
|
# This method is used in the SaltPasswords migration and is to be kept as is
|
||||||
def self.salt_unsalted_passwords!
|
def self.salt_unsalted_passwords!
|
||||||
transaction do
|
transaction do
|
||||||
User.find_each(:conditions => "salt IS NULL OR salt = ''") do |user|
|
User.where("salt IS NULL OR salt = ''").find_each do |user|
|
||||||
next if user.hashed_password.blank?
|
next if user.hashed_password.blank?
|
||||||
salt = User.generate_salt
|
salt = User.generate_salt
|
||||||
hashed_password = User.hash_password("#{salt}#{user.hashed_password}")
|
hashed_password = User.hash_password("#{salt}#{user.hashed_password}")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user