|
@@
-1,92
+1,113
|
|
1
|
# redMine - project management software
|
|
1
|
# redMine - project management software
|
|
2
|
# Copyright (C) 2006 Jean-Philippe Lang
|
|
2
|
# Copyright (C) 2006 Jean-Philippe Lang
|
|
3
|
#
|
|
3
|
#
|
|
4
|
# This program is free software; you can redistribute it and/or
|
|
4
|
# This program is free software; you can redistribute it and/or
|
|
5
|
# modify it under the terms of the GNU General Public License
|
|
5
|
# modify it under the terms of the GNU General Public License
|
|
6
|
# as published by the Free Software Foundation; either version 2
|
|
6
|
# as published by the Free Software Foundation; either version 2
|
|
7
|
# of the License, or (at your option) any later version.
|
|
7
|
# of the License, or (at your option) any later version.
|
|
8
|
#
|
|
8
|
#
|
|
9
|
# This program is distributed in the hope that it will be useful,
|
|
9
|
# This program is distributed in the hope that it will be useful,
|
|
10
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
10
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
11
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12
|
# GNU General Public License for more details.
|
|
12
|
# GNU General Public License for more details.
|
|
13
|
#
|
|
13
|
#
|
|
14
|
# You should have received a copy of the GNU General Public License
|
|
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
|
|
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.
|
|
16
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
17
|
|
|
17
|
|
|
18
|
class UsersController < ApplicationController
|
|
18
|
class UsersController < ApplicationController
|
|
19
|
layout 'base'
|
|
19
|
layout 'base'
|
|
20
|
before_filter :require_admin
|
|
20
|
before_filter :require_admin
|
|
21
|
|
|
21
|
|
|
22
|
helper :sort
|
|
22
|
helper :sort
|
|
23
|
include SortHelper
|
|
23
|
include SortHelper
|
|
24
|
helper :custom_fields
|
|
24
|
helper :custom_fields
|
|
25
|
include CustomFieldsHelper
|
|
25
|
include CustomFieldsHelper
|
|
26
|
|
|
26
|
|
|
27
|
def index
|
|
27
|
def index
|
|
28
|
list
|
|
28
|
list
|
|
29
|
render :action => 'list' unless request.xhr?
|
|
29
|
render :action => 'list' unless request.xhr?
|
|
30
|
end
|
|
30
|
end
|
|
31
|
|
|
31
|
|
|
32
|
def list
|
|
32
|
def list
|
|
33
|
sort_init 'login', 'asc'
|
|
33
|
sort_init 'login', 'asc'
|
|
34
|
sort_update
|
|
34
|
sort_update
|
|
35
|
@user_count = User.count
|
|
35
|
@user_count = User.count
|
|
36
|
@user_pages = Paginator.new self, @user_count,
|
|
36
|
@user_pages = Paginator.new self, @user_count,
|
|
37
|
15,
|
|
37
|
15,
|
|
38
|
@params['page']
|
|
38
|
@params['page']
|
|
39
|
@users = User.find :all,:order => sort_clause,
|
|
39
|
@users = User.find :all,:order => sort_clause,
|
|
40
|
:limit => @user_pages.items_per_page,
|
|
40
|
:limit => @user_pages.items_per_page,
|
|
41
|
:offset => @user_pages.current.offset
|
|
41
|
:offset => @user_pages.current.offset
|
|
42
|
|
|
42
|
|
|
43
|
render :action => "list", :layout => false if request.xhr?
|
|
43
|
render :action => "list", :layout => false if request.xhr?
|
|
44
|
end
|
|
44
|
end
|
|
45
|
|
|
45
|
|
|
46
|
def add
|
|
46
|
def add
|
|
47
|
if request.get?
|
|
47
|
if request.get?
|
|
48
|
@user = User.new(:language => $RDM_DEFAULT_LANG)
|
|
48
|
@user = User.new(:language => $RDM_DEFAULT_LANG)
|
|
49
|
@custom_values = UserCustomField.find(:all).collect { |x| CustomValue.new(:custom_field => x, :customized => @user) }
|
|
49
|
@custom_values = UserCustomField.find(:all).collect { |x| CustomValue.new(:custom_field => x, :customized => @user) }
|
|
50
|
else
|
|
50
|
else
|
|
51
|
@user = User.new(params[:user])
|
|
51
|
@user = User.new(params[:user])
|
|
52
|
@user.admin = params[:user][:admin] || false
|
|
52
|
@user.admin = params[:user][:admin] || false
|
|
53
|
@user.login = params[:user][:login]
|
|
53
|
@user.login = params[:user][:login]
|
|
54
|
@user.password, @user.password_confirmation = params[:password], params[:password_confirmation] unless @user.auth_source_id
|
|
54
|
@user.password, @user.password_confirmation = params[:password], params[:password_confirmation] unless @user.auth_source_id
|
|
55
|
@custom_values = UserCustomField.find(:all).collect { |x| CustomValue.new(:custom_field => x, :customized => @user, :value => params["custom_fields"][x.id.to_s]) }
|
|
55
|
@custom_values = UserCustomField.find(:all).collect { |x| CustomValue.new(:custom_field => x, :customized => @user, :value => params["custom_fields"][x.id.to_s]) }
|
|
56
|
@user.custom_values = @custom_values
|
|
56
|
@user.custom_values = @custom_values
|
|
57
|
if @user.save
|
|
57
|
if @user.save
|
|
58
|
flash[:notice] = l(:notice_successful_create)
|
|
58
|
flash[:notice] = l(:notice_successful_create)
|
|
59
|
redirect_to :action => 'list'
|
|
59
|
redirect_to :action => 'list'
|
|
60
|
end
|
|
60
|
end
|
|
61
|
end
|
|
61
|
end
|
|
62
|
@auth_sources = AuthSource.find(:all)
|
|
62
|
@auth_sources = AuthSource.find(:all)
|
|
63
|
end
|
|
63
|
end
|
|
64
|
|
|
64
|
|
|
65
|
def edit
|
|
65
|
def edit
|
|
66
|
@user = User.find(params[:id])
|
|
66
|
@user = User.find(params[:id])
|
|
67
|
if request.get?
|
|
67
|
if request.get?
|
|
68
|
@custom_values = UserCustomField.find(:all).collect { |x| @user.custom_values.find_by_custom_field_id(x.id) || CustomValue.new(:custom_field => x) }
|
|
68
|
@custom_values = UserCustomField.find(:all).collect { |x| @user.custom_values.find_by_custom_field_id(x.id) || CustomValue.new(:custom_field => x) }
|
|
69
|
else
|
|
69
|
else
|
|
70
|
@user.admin = params[:user][:admin] if params[:user][:admin]
|
|
70
|
@user.admin = params[:user][:admin] if params[:user][:admin]
|
|
71
|
@user.login = params[:user][:login] if params[:user][:login]
|
|
71
|
@user.login = params[:user][:login] if params[:user][:login]
|
|
72
|
@user.password, @user.password_confirmation = params[:password], params[:password_confirmation] unless params[:password].nil? or params[:password].empty? or @user.auth_source_id
|
|
72
|
@user.password, @user.password_confirmation = params[:password], params[:password_confirmation] unless params[:password].nil? or params[:password].empty? or @user.auth_source_id
|
|
73
|
if params[:custom_fields]
|
|
73
|
if params[:custom_fields]
|
|
74
|
@custom_values = UserCustomField.find(:all).collect { |x| CustomValue.new(:custom_field => x, :customized => @user, :value => params["custom_fields"][x.id.to_s]) }
|
|
74
|
@custom_values = UserCustomField.find(:all).collect { |x| CustomValue.new(:custom_field => x, :customized => @user, :value => params["custom_fields"][x.id.to_s]) }
|
|
75
|
@user.custom_values = @custom_values
|
|
75
|
@user.custom_values = @custom_values
|
|
76
|
end
|
|
76
|
end
|
|
77
|
if @user.update_attributes(params[:user])
|
|
77
|
if @user.update_attributes(params[:user])
|
|
78
|
flash[:notice] = l(:notice_successful_update)
|
|
78
|
flash[:notice] = l(:notice_successful_update)
|
|
79
|
redirect_to :action => 'list'
|
|
79
|
redirect_to :action => 'list'
|
|
80
|
end
|
|
80
|
end
|
|
81
|
end
|
|
81
|
end
|
|
82
|
@auth_sources = AuthSource.find(:all)
|
|
82
|
@auth_sources = AuthSource.find(:all)
|
|
|
|
|
83
|
@roles = Role.find :all
|
|
|
|
|
84
|
@projects = Project.find(:all) - @user.projects
|
|
|
|
|
85
|
@membership ||= Member.new
|
|
|
|
|
86
|
end
|
|
|
|
|
87
|
|
|
|
|
|
88
|
def edit_membership
|
|
|
|
|
89
|
@user = User.find(params[:id])
|
|
|
|
|
90
|
@membership = params[:membership_id] ? Member.find(params[:membership_id]) : Member.new(:user => @user)
|
|
|
|
|
91
|
@membership.attributes = params[:membership]
|
|
|
|
|
92
|
if request.post? and @membership.save
|
|
|
|
|
93
|
flash[:notice] = l(:notice_successful_update)
|
|
|
|
|
94
|
end
|
|
|
|
|
95
|
redirect_to :action => 'edit', :id => @user and return
|
|
|
|
|
96
|
end
|
|
|
|
|
97
|
|
|
|
|
|
98
|
def destroy_membership
|
|
|
|
|
99
|
@user = User.find(params[:id])
|
|
|
|
|
100
|
if request.post? and Member.find(params[:membership_id]).destroy
|
|
|
|
|
101
|
flash[:notice] = l(:notice_successful_update)
|
|
|
|
|
102
|
end
|
|
|
|
|
103
|
redirect_to :action => 'edit', :id => @user and return
|
|
83
|
end
|
|
104
|
end
|
|
84
|
|
|
105
|
|
|
85
|
def destroy
|
|
106
|
def destroy
|
|
86
|
User.find(params[:id]).destroy
|
|
107
|
User.find(params[:id]).destroy
|
|
87
|
redirect_to :action => 'list'
|
|
108
|
redirect_to :action => 'list'
|
|
88
|
rescue
|
|
109
|
rescue
|
|
89
|
flash[:notice] = "Unable to delete user"
|
|
110
|
flash[:notice] = "Unable to delete user"
|
|
90
|
redirect_to :action => 'list'
|
|
111
|
redirect_to :action => 'list'
|
|
91
|
end
|
|
112
|
end
|
|
92
|
end
|
|
113
|
end
|