1 # redMine - project management software
\r
2 # Copyright (C) 2006-2007 Jean-Philippe Lang
\r
4 # This program is free software; you can redistribute it and/or
\r
5 # modify it under the terms of the GNU General Public License
\r
6 # as published by the Free Software Foundation; either version 2
\r
7 # of the License, or (at your option) any later version.
\r
9 # This program is distributed in the hope that it will be useful,
\r
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
12 # GNU General Public License for more details.
\r
14 # You should have received a copy of the GNU General Public License
\r
15 # along with this program; if not, write to the Free Software
\r
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
\r
18 class UsersController < ApplicationController
\r
20 before_filter :require_admin
\r
24 helper :custom_fields
\r
25 include CustomFieldsHelper
\r
29 render :action => 'list' unless request.xhr?
33 sort_init 'login', 'asc'
\r
35 @user_count = User.count
\r
36 @user_pages = Paginator.new self, @user_count,
\r
39 @users = User.find :all,:order => sort_clause,
\r
40 :limit => @user_pages.items_per_page,
\r
41 :offset => @user_pages.current.offset
\r
43 render :action => "list", :layout => false if request.xhr?
48 @user = User.new(:language => Setting.default_language)
\r
49 @custom_values = UserCustomField.find(:all).collect { |x| CustomValue.new(:custom_field => x, :customized => @user) }
\r
51 @user = User.new(params[:user])
\r
52 @user.admin = params[:user][:admin] || false
\r
53 @user.login = params[:user][:login]
\r
54 @user.password, @user.password_confirmation = params[:password], params[:password_confirmation] unless @user.auth_source_id
\r
55 @custom_values = UserCustomField.find(:all).collect { |x| CustomValue.new(:custom_field => x, :customized => @user, :value => params["custom_fields"][x.id.to_s]) }
\r
56 @user.custom_values = @custom_values
\r
58 flash[:notice] = l(:notice_successful_create)
59 redirect_to :action => 'list'
62 @auth_sources = AuthSource.find(:all)
66 @user = User.find(params[:id])
68 @custom_values = UserCustomField.find(:all).collect { |x| @user.custom_values.find_by_custom_field_id(x.id) || CustomValue.new(:custom_field => x) }
\r
70 @user.admin = params[:user][:admin] if params[:user][:admin]
\r
71 @user.login = params[:user][:login] if params[:user][:login]
\r
72 @user.password, @user.password_confirmation = params[:password], params[:password_confirmation] unless params[:password].nil? or params[:password].empty? or @user.auth_source_id
\r
73 if params[:custom_fields]
\r
74 @custom_values = UserCustomField.find(:all).collect { |x| CustomValue.new(:custom_field => x, :customized => @user, :value => params["custom_fields"][x.id.to_s]) }
\r
75 @user.custom_values = @custom_values
\r
77 if @user.update_attributes(params[:user])
78 flash[:notice] = l(:notice_successful_update)
79 redirect_to :action => 'list'
82 @auth_sources = AuthSource.find(:all)
\r
83 @roles = Role.find(:all, :order => 'position')
\r
84 @projects = Project.find(:all) - @user.projects
\r
85 @membership ||= Member.new
\r
89 @user = User.find(params[:id])
\r
90 @membership = params[:membership_id] ? Member.find(params[:membership_id]) : Member.new(:user => @user)
\r
91 @membership.attributes = params[:membership]
\r
92 if request.post? and @membership.save
\r
93 flash[:notice] = l(:notice_successful_update)
\r
95 redirect_to :action => 'edit', :id => @user and return
\r
98 def destroy_membership
\r
99 @user = User.find(params[:id])
\r
100 if request.post? and Member.find(params[:membership_id]).destroy
\r
101 flash[:notice] = l(:notice_successful_update)
\r
103 redirect_to :action => 'edit', :id => @user and return
\r
107 User.find(params[:id]).destroy
108 redirect_to :action => 'list'
\r
110 flash[:notice] = "Unable to delete user"
\r
111 redirect_to :action => 'list'