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 conditions = "status <> 0"
37 conditions = ["status=?", @status] unless @status == 0
39 @user_count = User.count(:conditions => conditions)
40 @user_pages = Paginator.new self, @user_count,
43 @users = User.find :all,:order => sort_clause,
44 :conditions => conditions,
45 :limit => @user_pages.items_per_page,
46 :offset => @user_pages.current.offset
48 render :action => "list", :layout => false if request.xhr?
53 @user = User.new(:language => Setting.default_language)
55 @user = User.new(params[:user])
56 @user.admin = params[:user][:admin] || false
57 @user.login = params[:user][:login]
58 @user.password, @user.password_confirmation = params[:password], params[:password_confirmation] unless @user.auth_source_id
60 Mailer.deliver_account_information(@user, params[:password]) if params[:send_information]
61 flash[:notice] = l(:notice_successful_create)
62 redirect_to :action => 'list'
65 @auth_sources = AuthSource.find(:all)
69 @user = User.find(params[:id])
71 @user.admin = params[:user][:admin] if params[:user][:admin]
72 @user.login = params[:user][:login] if params[:user][:login]
73 @user.password, @user.password_confirmation = params[:password], params[:password_confirmation] unless params[:password].nil? or params[:password].empty? or @user.auth_source_id
74 if @user.update_attributes(params[:user])
75 flash[:notice] = l(:notice_successful_update)
76 # Give a string to redirect_to otherwise it would use status param as the response code
77 redirect_to(url_for(:action => 'list', :status => params[:status], :page => params[:page]))
80 @auth_sources = AuthSource.find(:all)
81 @roles = Role.find_all_givable
82 @projects = Project.find(:all, :order => 'name', :conditions => "status=#{Project::STATUS_ACTIVE}") - @user.projects
83 @membership ||= Member.new
84 @memberships = @user.memberships
88 @user = User.find(params[:id])
89 @membership = params[:membership_id] ? Member.find(params[:membership_id]) : Member.new(:user => @user)
90 @membership.attributes = params[:membership]
91 @membership.save if request.post?
92 redirect_to :action => 'edit', :id => @user, :tab => 'memberships'
95 def destroy_membership
96 @user = User.find(params[:id])
97 Member.find(params[:membership_id]).destroy if request.post?
98 redirect_to :action => 'edit', :id => @user, :tab => 'memberships'