Replaces User.find_active with a named scope.
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@2079 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
9572699301
commit
e7b6a56a97
|
@ -24,7 +24,7 @@ class AccountController < ApplicationController
|
||||||
|
|
||||||
# Show user's account
|
# Show user's account
|
||||||
def show
|
def show
|
||||||
@user = User.find_active(params[:id])
|
@user = User.active.find(params[:id])
|
||||||
@custom_values = @user.custom_values
|
@custom_values = @user.custom_values
|
||||||
|
|
||||||
# show only public projects and private projects that the logged in user is also a member of
|
# show only public projects and private projects that the logged in user is also a member of
|
||||||
|
|
|
@ -46,7 +46,7 @@ class ApplicationController < ActionController::Base
|
||||||
def find_current_user
|
def find_current_user
|
||||||
if session[:user_id]
|
if session[:user_id]
|
||||||
# existing session
|
# existing session
|
||||||
(User.find_active(session[:user_id]) rescue nil)
|
(User.active.find(session[:user_id]) rescue nil)
|
||||||
elsif cookies[:autologin] && Setting.autologin?
|
elsif cookies[:autologin] && Setting.autologin?
|
||||||
# auto-login feature
|
# auto-login feature
|
||||||
User.find_by_autologin_key(cookies[:autologin])
|
User.find_by_autologin_key(cookies[:autologin])
|
||||||
|
|
|
@ -227,7 +227,7 @@ class ProjectsController < ApplicationController
|
||||||
@date_to ||= Date.today + 1
|
@date_to ||= Date.today + 1
|
||||||
@date_from = @date_to - @days
|
@date_from = @date_to - @days
|
||||||
@with_subprojects = params[:with_subprojects].nil? ? Setting.display_subprojects_issues? : (params[:with_subprojects] == '1')
|
@with_subprojects = params[:with_subprojects].nil? ? Setting.display_subprojects_issues? : (params[:with_subprojects] == '1')
|
||||||
@author = (params[:user_id] ? User.find_active(params[:user_id]) : nil)
|
@author = (params[:user_id] ? User.active.find(params[:user_id]) : nil)
|
||||||
|
|
||||||
@activity = Redmine::Activity::Fetcher.new(User.current, :project => @project,
|
@activity = Redmine::Activity::Fetcher.new(User.current, :project => @project,
|
||||||
:with_subprojects => @with_subprojects,
|
:with_subprojects => @with_subprojects,
|
||||||
|
|
|
@ -39,7 +39,7 @@ class MailHandler < ActionMailer::Base
|
||||||
# Processes incoming emails
|
# Processes incoming emails
|
||||||
def receive(email)
|
def receive(email)
|
||||||
@email = email
|
@email = email
|
||||||
@user = User.find_active(:first, :conditions => ["LOWER(mail) = ?", email.from.first.to_s.strip.downcase])
|
@user = User.active.find(:first, :conditions => ["LOWER(mail) = ?", email.from.first.to_s.strip.downcase])
|
||||||
unless @user
|
unless @user
|
||||||
# Unknown user => the email is ignored
|
# Unknown user => the email is ignored
|
||||||
# TODO: ability to create the user's account
|
# TODO: ability to create the user's account
|
||||||
|
@ -149,7 +149,7 @@ class MailHandler < ActionMailer::Base
|
||||||
if user.allowed_to?("add_#{obj.class.name.underscore}_watchers".to_sym, obj.project)
|
if user.allowed_to?("add_#{obj.class.name.underscore}_watchers".to_sym, obj.project)
|
||||||
addresses = [email.to, email.cc].flatten.compact.uniq.collect {|a| a.strip.downcase}
|
addresses = [email.to, email.cc].flatten.compact.uniq.collect {|a| a.strip.downcase}
|
||||||
unless addresses.empty?
|
unless addresses.empty?
|
||||||
watchers = User.find_active(:all, :conditions => ['LOWER(mail) IN (?)', addresses])
|
watchers = User.active.find(:all, :conditions => ['LOWER(mail) IN (?)', addresses])
|
||||||
watchers.each {|w| obj.add_watcher(w)}
|
watchers.each {|w| obj.add_watcher(w)}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -116,7 +116,7 @@ class Mailer < ActionMailer::Base
|
||||||
|
|
||||||
def account_activation_request(user)
|
def account_activation_request(user)
|
||||||
# Send the email to all active administrators
|
# Send the email to all active administrators
|
||||||
recipients User.find_active(:all, :conditions => {:admin => true}).collect { |u| u.mail }.compact
|
recipients User.active.find(:all, :conditions => {:admin => true}).collect { |u| u.mail }.compact
|
||||||
subject l(:mail_subject_account_activation_request, Setting.app_title)
|
subject l(:mail_subject_account_activation_request, Setting.app_title)
|
||||||
body :user => user,
|
body :user => user,
|
||||||
:url => url_for(:controller => 'users', :action => 'index', :status => User::STATUS_REGISTERED, :sort_key => 'created_on', :sort_order => 'desc')
|
:url => url_for(:controller => 'users', :action => 'index', :status => User::STATUS_REGISTERED, :sort_key => 'created_on', :sort_order => 'desc')
|
||||||
|
|
|
@ -42,6 +42,9 @@ class User < ActiveRecord::Base
|
||||||
has_one :rss_token, :dependent => :destroy, :class_name => 'Token', :conditions => "action='feeds'"
|
has_one :rss_token, :dependent => :destroy, :class_name => 'Token', :conditions => "action='feeds'"
|
||||||
belongs_to :auth_source
|
belongs_to :auth_source
|
||||||
|
|
||||||
|
# Active non-anonymous users scope
|
||||||
|
named_scope :active, :conditions => "#{User.table_name}.status = #{STATUS_ACTIVE}"
|
||||||
|
|
||||||
acts_as_customizable
|
acts_as_customizable
|
||||||
|
|
||||||
attr_accessor :password, :password_confirmation
|
attr_accessor :password, :password_confirmation
|
||||||
|
@ -76,18 +79,6 @@ class User < ActiveRecord::Base
|
||||||
@name = nil
|
@name = nil
|
||||||
super
|
super
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.active
|
|
||||||
with_scope :find => { :conditions => [ "status = ?", STATUS_ACTIVE ] } do
|
|
||||||
yield
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.find_active(*args)
|
|
||||||
active do
|
|
||||||
find(*args)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
# Returns the user that matches provided login and password, or nil
|
# Returns the user that matches provided login and password, or nil
|
||||||
def self.try_to_login(login, password)
|
def self.try_to_login(login, password)
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
<%= error_messages_for 'member' %>
|
<%= error_messages_for 'member' %>
|
||||||
<% roles = Role.find_all_givable %>
|
<% roles = Role.find_all_givable %>
|
||||||
<% users = User.find_active(:all).sort - @project.users %>
|
<% users = User.active.find(:all).sort - @project.users %>
|
||||||
<% # members sorted by role position
|
<% # members sorted by role position
|
||||||
members = @project.members.find(:all, :include => [:role, :user]).sort %>
|
members = @project.members.find(:all, :include => [:role, :user]).sort %>
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue