1 # redMine - project management software
2 # Copyright (C) 2006-2007 Jean-Philippe Lang
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 class UsersController < ApplicationController
19 before_filter :require_admin
24 include CustomFieldsHelper
28 render :action => 'list' unless request.xhr?
32 sort_init 'login', 'asc'
35 @status = params[:status] ? params[:status].to_i : 1
36 c = ARCondition.new(@status == 0 ? "status <> 0" : ["status = ?", @status])
38 unless params[:name].blank?
39 name = "%#{params[:name].strip.downcase}%"
40 c << ["LOWER(login) LIKE ? OR LOWER(firstname) LIKE ? OR LOWER(lastname) LIKE ?", name, name, name]
43 @user_count = User.count(:conditions => c.conditions)
44 @user_pages = Paginator.new self, @user_count,
47 @users = User.find :all,:order => sort_clause,
48 :conditions => c.conditions,
49 :limit => @user_pages.items_per_page,
50 :offset => @user_pages.current.offset
52 render :action => "list", :layout => false if request.xhr?
57 @user = User.new(:language => Setting.default_language)
59 @user = User.new(params[:user])
60 @user.admin = params[:user][:admin] || false
61 @user.login = params[:user][:login]
62 @user.password, @user.password_confirmation = params[:password], params[:password_confirmation] unless @user.auth_source_id
64 Mailer.deliver_account_information(@user, params[:password]) if params[:send_information]
65 flash[:notice] = l(:notice_successful_create)
66 redirect_to :action => 'list'
69 @auth_sources = AuthSource.find(:all)
73 @user = User.find(params[:id])
75 @user.admin = params[:user][:admin] if params[:user][:admin]
76 @user.login = params[:user][:login] if params[:user][:login]
77 @user.password, @user.password_confirmation = params[:password], params[:password_confirmation] unless params[:password].nil? or params[:password].empty? or @user.auth_source_id
78 if @user.update_attributes(params[:user])
79 flash[:notice] = l(:notice_successful_update)
80 # Give a string to redirect_to otherwise it would use status param as the response code
81 redirect_to(url_for(:action => 'list', :status => params[:status], :page => params[:page]))
84 @auth_sources = AuthSource.find(:all)
85 @roles = Role.find_all_givable
86 @projects = Project.find(:all, :order => 'name', :conditions => "status=#{Project::STATUS_ACTIVE}") - @user.projects
87 @membership ||= Member.new
88 @memberships = @user.memberships
92 @user = User.find(params[:id])
93 @membership = params[:membership_id] ? Member.find(params[:membership_id]) : Member.new(:user => @user)
94 @membership.attributes = params[:membership]
95 @membership.save if request.post?
96 redirect_to :action => 'edit', :id => @user, :tab => 'memberships'
99 def destroy_membership
100 @user = User.find(params[:id])
101 Member.find(params[:membership_id]).destroy if request.post?
102 redirect_to :action => 'edit', :id => @user, :tab => 'memberships'