2006-06-28 22:11:03 +04:00
|
|
|
# redMine - project management software
|
|
|
|
# Copyright (C) 2006 Jean-Philippe Lang
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or
|
|
|
|
# modify it under the terms of the GNU General Public License
|
|
|
|
# as published by the Free Software Foundation; either version 2
|
|
|
|
# of the License, or (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
|
|
|
class UsersController < ApplicationController
|
2006-07-09 20:30:01 +04:00
|
|
|
layout 'base'
|
|
|
|
before_filter :require_admin
|
|
|
|
|
|
|
|
helper :sort
|
|
|
|
include SortHelper
|
2006-07-29 13:32:58 +04:00
|
|
|
helper :custom_fields
|
|
|
|
include CustomFieldsHelper
|
2006-07-09 20:30:01 +04:00
|
|
|
|
|
|
|
def index
|
|
|
|
list
|
|
|
|
render :action => 'list'
|
|
|
|
end
|
2006-06-28 22:11:03 +04:00
|
|
|
|
2006-07-09 20:30:01 +04:00
|
|
|
def list
|
|
|
|
sort_init 'login', 'asc'
|
|
|
|
sort_update
|
|
|
|
@user_count = User.count
|
|
|
|
@user_pages = Paginator.new self, @user_count,
|
2006-06-28 22:11:03 +04:00
|
|
|
15,
|
|
|
|
@params['page']
|
2006-07-09 20:30:01 +04:00
|
|
|
@users = User.find :all,:order => sort_clause,
|
2006-06-28 22:11:03 +04:00
|
|
|
:limit => @user_pages.items_per_page,
|
|
|
|
:offset => @user_pages.current.offset
|
2006-07-09 20:30:01 +04:00
|
|
|
end
|
2006-06-28 22:11:03 +04:00
|
|
|
|
2006-07-09 20:30:01 +04:00
|
|
|
def add
|
|
|
|
if request.get?
|
2006-07-29 13:32:58 +04:00
|
|
|
@user = User.new(:language => $RDM_DEFAULT_LANG)
|
|
|
|
@custom_values = UserCustomField.find(:all).collect { |x| CustomValue.new(:custom_field => x, :customized => @user) }
|
2006-07-09 20:30:01 +04:00
|
|
|
else
|
|
|
|
@user = User.new(params[:user])
|
|
|
|
@user.admin = params[:user][:admin] || false
|
|
|
|
@user.login = params[:user][:login]
|
|
|
|
@user.password, @user.password_confirmation = params[:password], params[:password_confirmation]
|
2006-07-29 13:32:58 +04:00
|
|
|
@custom_values = UserCustomField.find(:all).collect { |x| CustomValue.new(:custom_field => x, :customized => @user, :value => params["custom_fields"][x.id.to_s]) }
|
|
|
|
@user.custom_values = @custom_values
|
2006-07-09 20:30:01 +04:00
|
|
|
if @user.save
|
|
|
|
flash[:notice] = 'User was successfully created.'
|
|
|
|
redirect_to :action => 'list'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2006-06-28 22:11:03 +04:00
|
|
|
|
2006-07-09 20:30:01 +04:00
|
|
|
def edit
|
|
|
|
@user = User.find(params[:id])
|
2006-07-29 13:32:58 +04:00
|
|
|
if request.get?
|
|
|
|
@custom_values = UserCustomField.find(:all).collect { |x| @user.custom_values.find_by_custom_field_id(x.id) || CustomValue.new(:custom_field => x) }
|
|
|
|
else
|
2006-07-09 20:30:01 +04:00
|
|
|
@user.admin = params[:user][:admin] if params[:user][:admin]
|
|
|
|
@user.login = params[:user][:login] if params[:user][:login]
|
|
|
|
@user.password, @user.password_confirmation = params[:password], params[:password_confirmation] unless params[:password].nil? or params[:password].empty?
|
2006-07-29 13:32:58 +04:00
|
|
|
if params[:custom_fields]
|
|
|
|
@custom_values = UserCustomField.find(:all).collect { |x| CustomValue.new(:custom_field => x, :customized => @user, :value => params["custom_fields"][x.id.to_s]) }
|
|
|
|
@user.custom_values = @custom_values
|
|
|
|
end
|
2006-07-09 20:30:01 +04:00
|
|
|
if @user.update_attributes(params[:user])
|
|
|
|
flash[:notice] = 'User was successfully updated.'
|
|
|
|
redirect_to :action => 'list'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2006-06-28 22:11:03 +04:00
|
|
|
|
2006-07-09 20:30:01 +04:00
|
|
|
def destroy
|
|
|
|
User.find(params[:id]).destroy
|
|
|
|
redirect_to :action => 'list'
|
2006-06-28 22:11:03 +04:00
|
|
|
rescue
|
|
|
|
flash[:notice] = "Unable to delete user"
|
|
|
|
redirect_to :action => 'list'
|
2006-07-09 20:30:01 +04:00
|
|
|
end
|
2006-06-28 22:11:03 +04:00
|
|
|
end
|