]> source.dussan.org Git - redmine.git/commitdiff
Replaces User.find_active with a named scope.
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Sun, 30 Nov 2008 16:57:56 +0000 (16:57 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Sun, 30 Nov 2008 16:57:56 +0000 (16:57 +0000)
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@2079 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/controllers/account_controller.rb
app/controllers/application.rb
app/controllers/projects_controller.rb
app/models/mail_handler.rb
app/models/mailer.rb
app/models/user.rb
app/views/projects/settings/_members.rhtml

index f327dd5b65b6003d8f7c6a7138cd8aa790bf023c..fe44740a46588922093640d73070658347fd469e 100644 (file)
@@ -24,7 +24,7 @@ class AccountController < ApplicationController
 
   # Show user's account
   def show
-    @user = User.find_active(params[:id])
+    @user = User.active.find(params[:id])
     @custom_values = @user.custom_values
     
     # show only public projects and private projects that the logged in user is also a member of
index e5719a05969bb2643d23927a7a8d78ed0ffa7026..36123ba4757e92cf7b185beb69b48f83e7056520 100644 (file)
@@ -46,7 +46,7 @@ class ApplicationController < ActionController::Base
   def find_current_user
     if session[:user_id]
       # existing session
-      (User.find_active(session[:user_id]) rescue nil)
+      (User.active.find(session[:user_id]) rescue nil)
     elsif cookies[:autologin] && Setting.autologin?
       # auto-login feature
       User.find_by_autologin_key(cookies[:autologin])
index 43e1ae035bfba097f949b4b31814f73f0037973a..9b33166821deb874d517a917b6c017fc2ce370b1 100644 (file)
@@ -227,7 +227,7 @@ class ProjectsController < ApplicationController
     @date_to ||= Date.today + 1
     @date_from = @date_to - @days
     @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, 
                                                              :with_subprojects => @with_subprojects,
index fcb469c6082f4a5bc8b2b31441bccc2e3831f25a..a716412fc5506bf725f8e2ec8eaee7bbdfd3afc7 100644 (file)
@@ -39,7 +39,7 @@ class MailHandler < ActionMailer::Base
   # Processes incoming emails
   def receive(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
       # Unknown user => the email is ignored
       # 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)
       addresses = [email.to, email.cc].flatten.compact.uniq.collect {|a| a.strip.downcase}
       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)}
       end
     end
index 397807d162815afd0ffd527f8f2beaeadfc8cd16..f17ebbdbbdf9376c90283447ec0248b0b5b81e08 100644 (file)
@@ -116,7 +116,7 @@ class Mailer < ActionMailer::Base
 
   def account_activation_request(user)
     # 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)
     body :user => user,
          :url => url_for(:controller => 'users', :action => 'index', :status => User::STATUS_REGISTERED, :sort_key => 'created_on', :sort_order => 'desc')
index 72c550b822745793c4875d42814bdc8b728b6759..3722081d260376575eb52cdb35dbd5b2300a5380 100644 (file)
@@ -42,6 +42,9 @@ class User < ActiveRecord::Base
   has_one :rss_token, :dependent => :destroy, :class_name => 'Token', :conditions => "action='feeds'"
   belongs_to :auth_source
   
+  # Active non-anonymous users scope
+  named_scope :active, :conditions => "#{User.table_name}.status = #{STATUS_ACTIVE}"
+  
   acts_as_customizable
   
   attr_accessor :password, :password_confirmation
@@ -76,18 +79,6 @@ class User < ActiveRecord::Base
     @name = nil
     super
   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
   def self.try_to_login(login, password)
index 67c3fb505724276b0e3f3fa9263f2215d8baf4cb..20806fe2d2839f5a1b32c09828c266de41af5aa6 100644 (file)
@@ -1,6 +1,6 @@
 <%= error_messages_for 'member' %>
 <% 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 = @project.members.find(:all, :include => [:role, :user]).sort %>