You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

users_controller.rb 3.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. # redMine - project management software
  2. # Copyright (C) 2006 Jean-Philippe Lang
  3. #
  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.
  8. #
  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.
  13. #
  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.
  17. class UsersController < ApplicationController
  18. layout 'base'
  19. before_filter :require_admin
  20. helper :sort
  21. include SortHelper
  22. helper :custom_fields
  23. include CustomFieldsHelper
  24. def index
  25. list
  26. render :action => 'list' unless request.xhr?
  27. end
  28. def list
  29. sort_init 'login', 'asc'
  30. sort_update
  31. @user_count = User.count
  32. @user_pages = Paginator.new self, @user_count,
  33. 15,
  34. @params['page']
  35. @users = User.find :all,:order => sort_clause,
  36. :limit => @user_pages.items_per_page,
  37. :offset => @user_pages.current.offset
  38. render :action => "list", :layout => false if request.xhr?
  39. end
  40. def add
  41. if request.get?
  42. @user = User.new(:language => $RDM_DEFAULT_LANG)
  43. @custom_values = UserCustomField.find(:all).collect { |x| CustomValue.new(:custom_field => x, :customized => @user) }
  44. else
  45. @user = User.new(params[:user])
  46. @user.admin = params[:user][:admin] || false
  47. @user.login = params[:user][:login]
  48. @user.password, @user.password_confirmation = params[:password], params[:password_confirmation] unless @user.auth_source_id
  49. @custom_values = UserCustomField.find(:all).collect { |x| CustomValue.new(:custom_field => x, :customized => @user, :value => params["custom_fields"][x.id.to_s]) }
  50. @user.custom_values = @custom_values
  51. if @user.save
  52. flash[:notice] = l(:notice_successful_create)
  53. redirect_to :action => 'list'
  54. end
  55. end
  56. @auth_sources = AuthSource.find(:all)
  57. end
  58. def edit
  59. @user = User.find(params[:id])
  60. if request.get?
  61. @custom_values = UserCustomField.find(:all).collect { |x| @user.custom_values.find_by_custom_field_id(x.id) || CustomValue.new(:custom_field => x) }
  62. else
  63. @user.admin = params[:user][:admin] if params[:user][:admin]
  64. @user.login = params[:user][:login] if params[:user][:login]
  65. @user.password, @user.password_confirmation = params[:password], params[:password_confirmation] unless params[:password].nil? or params[:password].empty? or @user.auth_source_id
  66. if params[:custom_fields]
  67. @custom_values = UserCustomField.find(:all).collect { |x| CustomValue.new(:custom_field => x, :customized => @user, :value => params["custom_fields"][x.id.to_s]) }
  68. @user.custom_values = @custom_values
  69. end
  70. if @user.update_attributes(params[:user])
  71. flash[:notice] = l(:notice_successful_update)
  72. redirect_to :action => 'list'
  73. end
  74. end
  75. @auth_sources = AuthSource.find(:all)
  76. end
  77. def destroy
  78. User.find(params[:id]).destroy
  79. redirect_to :action => 'list'
  80. rescue
  81. flash[:notice] = "Unable to delete user"
  82. redirect_to :action => 'list'
  83. end
  84. end