##// END OF EJS Templates
Unified UsersController#list and #index....
Jean-Philippe Lang -
r2877:92ec35e6570b
parent child
Show More
@@ -1,145 +1,140
1 1 # Redmine - project management software
2 2 # Copyright (C) 2006-2009 Jean-Philippe Lang
3 3 #
4 4 # This program is free software; you can redistribute it and/or
5 5 # modify it under the terms of the GNU General Public License
6 6 # as published by the Free Software Foundation; either version 2
7 7 # of the License, or (at your option) any later version.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU General Public License
15 15 # along with this program; if not, write to the Free Software
16 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 18 class UsersController < ApplicationController
19 19 before_filter :require_admin, :except => :show
20 20
21 21 helper :sort
22 22 include SortHelper
23 23 helper :custom_fields
24 24 include CustomFieldsHelper
25 25
26 26 def index
27 list
28 render :action => 'list' unless request.xhr?
29 end
30
31 def list
32 27 sort_init 'login', 'asc'
33 28 sort_update %w(login firstname lastname mail admin created_on last_login_on)
34 29
35 30 @status = params[:status] ? params[:status].to_i : 1
36 31 c = ARCondition.new(@status == 0 ? "status <> 0" : ["status = ?", @status])
37 32
38 33 unless params[:name].blank?
39 34 name = "%#{params[:name].strip.downcase}%"
40 35 c << ["LOWER(login) LIKE ? OR LOWER(firstname) LIKE ? OR LOWER(lastname) LIKE ? OR LOWER(mail) LIKE ?", name, name, name, name]
41 36 end
42 37
43 38 @user_count = User.count(:conditions => c.conditions)
44 39 @user_pages = Paginator.new self, @user_count,
45 40 per_page_option,
46 41 params['page']
47 42 @users = User.find :all,:order => sort_clause,
48 43 :conditions => c.conditions,
49 44 :limit => @user_pages.items_per_page,
50 45 :offset => @user_pages.current.offset
51 46
52 render :action => "list", :layout => false if request.xhr?
47 render :layout => !request.xhr?
53 48 end
54 49
55 50 def show
56 51 @user = User.active.find(params[:id])
57 52 @custom_values = @user.custom_values
58 53
59 54 # show only public projects and private projects that the logged in user is also a member of
60 55 @memberships = @user.memberships.select do |membership|
61 56 membership.project.is_public? || (User.current.member_of?(membership.project))
62 57 end
63 58
64 59 events = Redmine::Activity::Fetcher.new(User.current, :author => @user).events(nil, nil, :limit => 10)
65 60 @events_by_day = events.group_by(&:event_date)
66 61
67 62 if @user != User.current && !User.current.admin? && @memberships.empty? && events.empty?
68 63 render_404 and return
69 64 end
70 65
71 66 rescue ActiveRecord::RecordNotFound
72 67 render_404
73 68 end
74 69
75 70 def add
76 71 if request.get?
77 72 @user = User.new(:language => Setting.default_language)
78 73 else
79 74 @user = User.new(params[:user])
80 75 @user.admin = params[:user][:admin] || false
81 76 @user.login = params[:user][:login]
82 77 @user.password, @user.password_confirmation = params[:password], params[:password_confirmation] unless @user.auth_source_id
83 78 if @user.save
84 79 Mailer.deliver_account_information(@user, params[:password]) if params[:send_information]
85 80 flash[:notice] = l(:notice_successful_create)
86 81 redirect_to :controller => 'users', :action => 'edit', :id => @user
87 82 end
88 83 end
89 84 @auth_sources = AuthSource.find(:all)
90 85 end
91 86
92 87 def edit
93 88 @user = User.find(params[:id])
94 89 if request.post?
95 90 @user.admin = params[:user][:admin] if params[:user][:admin]
96 91 @user.login = params[:user][:login] if params[:user][:login]
97 92 @user.password, @user.password_confirmation = params[:password], params[:password_confirmation] unless params[:password].nil? or params[:password].empty? or @user.auth_source_id
98 93 @user.group_ids = params[:user][:group_ids] if params[:user][:group_ids]
99 94 @user.attributes = params[:user]
100 95 # Was the account actived ? (do it before User#save clears the change)
101 96 was_activated = (@user.status_change == [User::STATUS_REGISTERED, User::STATUS_ACTIVE])
102 97 if @user.save
103 98 if was_activated
104 99 Mailer.deliver_account_activated(@user)
105 100 elsif @user.active? && params[:send_information] && !params[:password].blank? && @user.auth_source_id.nil?
106 101 Mailer.deliver_account_information(@user, params[:password])
107 102 end
108 103 flash[:notice] = l(:notice_successful_update)
109 104 redirect_to :back
110 105 end
111 106 end
112 107 @auth_sources = AuthSource.find(:all)
113 108 @membership ||= Member.new
114 109 rescue ::ActionController::RedirectBackError
115 110 redirect_to :controller => 'users', :action => 'edit', :id => @user
116 111 end
117 112
118 113 def edit_membership
119 114 @user = User.find(params[:id])
120 115 @membership = params[:membership_id] ? Member.find(params[:membership_id]) : Member.new(:principal => @user)
121 116 @membership.attributes = params[:membership]
122 117 @membership.save if request.post?
123 118 respond_to do |format|
124 119 format.html { redirect_to :controller => 'users', :action => 'edit', :id => @user, :tab => 'memberships' }
125 120 format.js {
126 121 render(:update) {|page|
127 122 page.replace_html "tab-content-memberships", :partial => 'users/memberships'
128 123 page.visual_effect(:highlight, "member-#{@membership.id}")
129 124 }
130 125 }
131 126 end
132 127 end
133 128
134 129 def destroy_membership
135 130 @user = User.find(params[:id])
136 131 @membership = Member.find(params[:membership_id])
137 132 if request.post? && @membership.deletable?
138 133 @membership.destroy
139 134 end
140 135 respond_to do |format|
141 136 format.html { redirect_to :controller => 'users', :action => 'edit', :id => @user, :tab => 'memberships' }
142 137 format.js { render(:update) {|page| page.replace_html "tab-content-memberships", :partial => 'users/memberships'} }
143 138 end
144 139 end
145 140 end
1 NO CONTENT: file renamed from app/views/users/list.rhtml to app/views/users/index.rhtml
@@ -1,263 +1,262
1 1 ActionController::Routing::Routes.draw do |map|
2 2 # Add your own custom routes here.
3 3 # The priority is based upon order of creation: first created -> highest priority.
4 4
5 5 # Here's a sample route:
6 6 # map.connect 'products/:id', :controller => 'catalog', :action => 'view'
7 7 # Keep in mind you can assign values other than :controller and :action
8 8
9 9 map.home '', :controller => 'welcome'
10 10
11 11 map.signin 'login', :controller => 'account', :action => 'login'
12 12 map.signout 'logout', :controller => 'account', :action => 'logout'
13 13
14 14 map.connect 'roles/workflow/:id/:role_id/:tracker_id', :controller => 'roles', :action => 'workflow'
15 15 map.connect 'help/:ctrl/:page', :controller => 'help'
16 16
17 17 map.connect 'time_entries/:id/edit', :action => 'edit', :controller => 'timelog'
18 18 map.connect 'projects/:project_id/time_entries/new', :action => 'edit', :controller => 'timelog'
19 19 map.connect 'projects/:project_id/issues/:issue_id/time_entries/new', :action => 'edit', :controller => 'timelog'
20 20
21 21 map.with_options :controller => 'timelog' do |timelog|
22 22 timelog.connect 'projects/:project_id/time_entries', :action => 'details'
23 23
24 24 timelog.with_options :action => 'details', :conditions => {:method => :get} do |time_details|
25 25 time_details.connect 'time_entries'
26 26 time_details.connect 'time_entries.:format'
27 27 time_details.connect 'issues/:issue_id/time_entries'
28 28 time_details.connect 'issues/:issue_id/time_entries.:format'
29 29 time_details.connect 'projects/:project_id/time_entries.:format'
30 30 time_details.connect 'projects/:project_id/issues/:issue_id/time_entries'
31 31 time_details.connect 'projects/:project_id/issues/:issue_id/time_entries.:format'
32 32 end
33 33 timelog.connect 'projects/:project_id/time_entries/report', :action => 'report'
34 34 timelog.with_options :action => 'report',:conditions => {:method => :get} do |time_report|
35 35 time_report.connect 'time_entries/report'
36 36 time_report.connect 'time_entries/report.:format'
37 37 time_report.connect 'projects/:project_id/time_entries/report.:format'
38 38 end
39 39
40 40 timelog.with_options :action => 'edit', :conditions => {:method => :get} do |time_edit|
41 41 time_edit.connect 'issues/:issue_id/time_entries/new'
42 42 end
43 43
44 44 timelog.connect 'time_entries/:id/destroy', :action => 'destroy', :conditions => {:method => :post}
45 45 end
46 46
47 47 map.connect 'projects/:id/wiki', :controller => 'wikis', :action => 'edit', :conditions => {:method => :post}
48 48 map.connect 'projects/:id/wiki/destroy', :controller => 'wikis', :action => 'destroy', :conditions => {:method => :get}
49 49 map.connect 'projects/:id/wiki/destroy', :controller => 'wikis', :action => 'destroy', :conditions => {:method => :post}
50 50 map.with_options :controller => 'wiki' do |wiki_routes|
51 51 wiki_routes.with_options :conditions => {:method => :get} do |wiki_views|
52 52 wiki_views.connect 'projects/:id/wiki/:page', :action => 'special', :page => /page_index|date_index|export/i
53 53 wiki_views.connect 'projects/:id/wiki/:page', :action => 'index', :page => nil
54 54 wiki_views.connect 'projects/:id/wiki/:page/edit', :action => 'edit'
55 55 wiki_views.connect 'projects/:id/wiki/:page/rename', :action => 'rename'
56 56 wiki_views.connect 'projects/:id/wiki/:page/history', :action => 'history'
57 57 wiki_views.connect 'projects/:id/wiki/:page/diff/:version/vs/:version_from', :action => 'diff'
58 58 wiki_views.connect 'projects/:id/wiki/:page/annotate/:version', :action => 'annotate'
59 59 end
60 60
61 61 wiki_routes.connect 'projects/:id/wiki/:page/:action',
62 62 :action => /edit|rename|destroy|preview|protect/,
63 63 :conditions => {:method => :post}
64 64 end
65 65
66 66 map.with_options :controller => 'messages' do |messages_routes|
67 67 messages_routes.with_options :conditions => {:method => :get} do |messages_views|
68 68 messages_views.connect 'boards/:board_id/topics/new', :action => 'new'
69 69 messages_views.connect 'boards/:board_id/topics/:id', :action => 'show'
70 70 messages_views.connect 'boards/:board_id/topics/:id/edit', :action => 'edit'
71 71 end
72 72 messages_routes.with_options :conditions => {:method => :post} do |messages_actions|
73 73 messages_actions.connect 'boards/:board_id/topics/new', :action => 'new'
74 74 messages_actions.connect 'boards/:board_id/topics/:id/replies', :action => 'reply'
75 75 messages_actions.connect 'boards/:board_id/topics/:id/:action', :action => /edit|destroy/
76 76 end
77 77 end
78 78
79 79 map.with_options :controller => 'boards' do |board_routes|
80 80 board_routes.with_options :conditions => {:method => :get} do |board_views|
81 81 board_views.connect 'projects/:project_id/boards', :action => 'index'
82 82 board_views.connect 'projects/:project_id/boards/new', :action => 'new'
83 83 board_views.connect 'projects/:project_id/boards/:id', :action => 'show'
84 84 board_views.connect 'projects/:project_id/boards/:id.:format', :action => 'show'
85 85 board_views.connect 'projects/:project_id/boards/:id/edit', :action => 'edit'
86 86 end
87 87 board_routes.with_options :conditions => {:method => :post} do |board_actions|
88 88 board_actions.connect 'projects/:project_id/boards', :action => 'new'
89 89 board_actions.connect 'projects/:project_id/boards/:id/:action', :action => /edit|destroy/
90 90 end
91 91 end
92 92
93 93 map.with_options :controller => 'documents' do |document_routes|
94 94 document_routes.with_options :conditions => {:method => :get} do |document_views|
95 95 document_views.connect 'projects/:project_id/documents', :action => 'index'
96 96 document_views.connect 'projects/:project_id/documents/new', :action => 'new'
97 97 document_views.connect 'documents/:id', :action => 'show'
98 98 document_views.connect 'documents/:id/edit', :action => 'edit'
99 99 end
100 100 document_routes.with_options :conditions => {:method => :post} do |document_actions|
101 101 document_actions.connect 'projects/:project_id/documents', :action => 'new'
102 102 document_actions.connect 'documents/:id/:action', :action => /destroy|edit/
103 103 end
104 104 end
105 105
106 106 map.with_options :controller => 'issues' do |issues_routes|
107 107 issues_routes.with_options :conditions => {:method => :get} do |issues_views|
108 108 issues_views.connect 'issues', :action => 'index'
109 109 issues_views.connect 'issues.:format', :action => 'index'
110 110 issues_views.connect 'projects/:project_id/issues', :action => 'index'
111 111 issues_views.connect 'projects/:project_id/issues.:format', :action => 'index'
112 112 issues_views.connect 'projects/:project_id/issues/new', :action => 'new'
113 113 issues_views.connect 'projects/:project_id/issues/gantt', :action => 'gantt'
114 114 issues_views.connect 'projects/:project_id/issues/calendar', :action => 'calendar'
115 115 issues_views.connect 'projects/:project_id/issues/:copy_from/copy', :action => 'new'
116 116 issues_views.connect 'issues/:id', :action => 'show', :id => /\d+/
117 117 issues_views.connect 'issues/:id.:format', :action => 'show', :id => /\d+/
118 118 issues_views.connect 'issues/:id/edit', :action => 'edit', :id => /\d+/
119 119 issues_views.connect 'issues/:id/move', :action => 'move', :id => /\d+/
120 120 end
121 121 issues_routes.with_options :conditions => {:method => :post} do |issues_actions|
122 122 issues_actions.connect 'projects/:project_id/issues', :action => 'new'
123 123 issues_actions.connect 'issues/:id/quoted', :action => 'reply', :id => /\d+/
124 124 issues_actions.connect 'issues/:id/:action', :action => /edit|move|destroy/, :id => /\d+/
125 125 end
126 126 issues_routes.connect 'issues/:action'
127 127 end
128 128
129 129 map.with_options :controller => 'issue_relations', :conditions => {:method => :post} do |relations|
130 130 relations.connect 'issues/:issue_id/relations/:id', :action => 'new'
131 131 relations.connect 'issues/:issue_id/relations/:id/destroy', :action => 'destroy'
132 132 end
133 133
134 134 map.with_options :controller => 'reports', :action => 'issue_report', :conditions => {:method => :get} do |reports|
135 135 reports.connect 'projects/:id/issues/report'
136 136 reports.connect 'projects/:id/issues/report/:detail'
137 137 end
138 138
139 139 map.with_options :controller => 'news' do |news_routes|
140 140 news_routes.with_options :conditions => {:method => :get} do |news_views|
141 141 news_views.connect 'news', :action => 'index'
142 142 news_views.connect 'projects/:project_id/news', :action => 'index'
143 143 news_views.connect 'projects/:project_id/news.:format', :action => 'index'
144 144 news_views.connect 'news.:format', :action => 'index'
145 145 news_views.connect 'projects/:project_id/news/new', :action => 'new'
146 146 news_views.connect 'news/:id', :action => 'show'
147 147 news_views.connect 'news/:id/edit', :action => 'edit'
148 148 end
149 149 news_routes.with_options do |news_actions|
150 150 news_actions.connect 'projects/:project_id/news', :action => 'new'
151 151 news_actions.connect 'news/:id/edit', :action => 'edit'
152 152 news_actions.connect 'news/:id/destroy', :action => 'destroy'
153 153 end
154 154 end
155 155
156 156 map.connect 'projects/:id/members/new', :controller => 'members', :action => 'new'
157 157
158 158 map.with_options :controller => 'users' do |users|
159 159 users.with_options :conditions => {:method => :get} do |user_views|
160 user_views.connect 'users', :action => 'list'
161 160 user_views.connect 'users', :action => 'index'
162 161 user_views.connect 'users/:id', :action => 'show', :id => /\d+/
163 162 user_views.connect 'users/new', :action => 'add'
164 163 user_views.connect 'users/:id/edit/:tab', :action => 'edit', :tab => nil
165 164 end
166 165 users.with_options :conditions => {:method => :post} do |user_actions|
167 166 user_actions.connect 'users', :action => 'add'
168 167 user_actions.connect 'users/new', :action => 'add'
169 168 user_actions.connect 'users/:id/edit', :action => 'edit'
170 169 user_actions.connect 'users/:id/memberships', :action => 'edit_membership'
171 170 user_actions.connect 'users/:id/memberships/:membership_id', :action => 'edit_membership'
172 171 user_actions.connect 'users/:id/memberships/:membership_id/destroy', :action => 'destroy_membership'
173 172 end
174 173 end
175 174
176 175 map.with_options :controller => 'projects' do |projects|
177 176 projects.with_options :conditions => {:method => :get} do |project_views|
178 177 project_views.connect 'projects', :action => 'index'
179 178 project_views.connect 'projects.:format', :action => 'index'
180 179 project_views.connect 'projects/new', :action => 'add'
181 180 project_views.connect 'projects/:id', :action => 'show'
182 181 project_views.connect 'projects/:id/:action', :action => /roadmap|changelog|destroy|settings/
183 182 project_views.connect 'projects/:id/files', :action => 'list_files'
184 183 project_views.connect 'projects/:id/files/new', :action => 'add_file'
185 184 project_views.connect 'projects/:id/versions/new', :action => 'add_version'
186 185 project_views.connect 'projects/:id/categories/new', :action => 'add_issue_category'
187 186 project_views.connect 'projects/:id/settings/:tab', :action => 'settings'
188 187 end
189 188
190 189 projects.with_options :action => 'activity', :conditions => {:method => :get} do |activity|
191 190 activity.connect 'projects/:id/activity'
192 191 activity.connect 'projects/:id/activity.:format'
193 192 activity.connect 'activity', :id => nil
194 193 activity.connect 'activity.:format', :id => nil
195 194 end
196 195
197 196 projects.with_options :conditions => {:method => :post} do |project_actions|
198 197 project_actions.connect 'projects/new', :action => 'add'
199 198 project_actions.connect 'projects', :action => 'add'
200 199 project_actions.connect 'projects/:id/:action', :action => /destroy|archive|unarchive/
201 200 project_actions.connect 'projects/:id/files/new', :action => 'add_file'
202 201 project_actions.connect 'projects/:id/versions/new', :action => 'add_version'
203 202 project_actions.connect 'projects/:id/categories/new', :action => 'add_issue_category'
204 203 project_actions.connect 'projects/:id/activities/save', :action => 'save_activities'
205 204 end
206 205
207 206 projects.with_options :conditions => {:method => :delete} do |project_actions|
208 207 project_actions.conditions 'projects/:id/reset_activities', :action => 'reset_activities'
209 208 end
210 209 end
211 210
212 211 map.with_options :controller => 'repositories' do |repositories|
213 212 repositories.with_options :conditions => {:method => :get} do |repository_views|
214 213 repository_views.connect 'projects/:id/repository', :action => 'show'
215 214 repository_views.connect 'projects/:id/repository/edit', :action => 'edit'
216 215 repository_views.connect 'projects/:id/repository/statistics', :action => 'stats'
217 216 repository_views.connect 'projects/:id/repository/revisions', :action => 'revisions'
218 217 repository_views.connect 'projects/:id/repository/revisions.:format', :action => 'revisions'
219 218 repository_views.connect 'projects/:id/repository/revisions/:rev', :action => 'revision'
220 219 repository_views.connect 'projects/:id/repository/revisions/:rev/diff', :action => 'diff'
221 220 repository_views.connect 'projects/:id/repository/revisions/:rev/diff.:format', :action => 'diff'
222 221 repository_views.connect 'projects/:id/repository/revisions/:rev/:action/*path', :requirements => { :rev => /[a-z0-9\.\-_]+/ }
223 222 repository_views.connect 'projects/:id/repository/:action/*path'
224 223 end
225 224
226 225 repositories.connect 'projects/:id/repository/:action', :conditions => {:method => :post}
227 226 end
228 227
229 228 map.connect 'attachments/:id', :controller => 'attachments', :action => 'show', :id => /\d+/
230 229 map.connect 'attachments/:id/:filename', :controller => 'attachments', :action => 'show', :id => /\d+/, :filename => /.*/
231 230 map.connect 'attachments/download/:id/:filename', :controller => 'attachments', :action => 'download', :id => /\d+/, :filename => /.*/
232 231
233 232 map.resources :groups
234 233
235 234 #left old routes at the bottom for backwards compat
236 235 map.connect 'projects/:project_id/issues/:action', :controller => 'issues'
237 236 map.connect 'projects/:project_id/documents/:action', :controller => 'documents'
238 237 map.connect 'projects/:project_id/boards/:action/:id', :controller => 'boards'
239 238 map.connect 'boards/:board_id/topics/:action/:id', :controller => 'messages'
240 239 map.connect 'wiki/:id/:page/:action', :page => nil, :controller => 'wiki'
241 240 map.connect 'issues/:issue_id/relations/:action/:id', :controller => 'issue_relations'
242 241 map.connect 'projects/:project_id/news/:action', :controller => 'news'
243 242 map.connect 'projects/:project_id/timelog/:action/:id', :controller => 'timelog', :project_id => /.+/
244 243 map.with_options :controller => 'repositories' do |omap|
245 244 omap.repositories_show 'repositories/browse/:id/*path', :action => 'browse'
246 245 omap.repositories_changes 'repositories/changes/:id/*path', :action => 'changes'
247 246 omap.repositories_diff 'repositories/diff/:id/*path', :action => 'diff'
248 247 omap.repositories_entry 'repositories/entry/:id/*path', :action => 'entry'
249 248 omap.repositories_entry 'repositories/annotate/:id/*path', :action => 'annotate'
250 249 omap.connect 'repositories/revision/:id/:rev', :action => 'revision'
251 250 end
252 251
253 252 map.with_options :controller => 'sys' do |sys|
254 253 sys.connect 'sys/projects.:format', :action => 'projects', :conditions => {:method => :get}
255 254 sys.connect 'sys/projects/:id/repository.:format', :action => 'create_project_repository', :conditions => {:method => :post}
256 255 end
257 256
258 257 # Install the default route as the lowest priority.
259 258 map.connect ':controller/:action/:id'
260 259 map.connect 'robots.txt', :controller => 'welcome', :action => 'robots'
261 260 # Used for OpenID
262 261 map.root :controller => 'account', :action => 'login'
263 262 end
@@ -1,224 +1,223
1 1 # redMine - project management software
2 2 # Copyright (C) 2006-2007 Jean-Philippe Lang
3 3 #
4 4 # This program is free software; you can redistribute it and/or
5 5 # modify it under the terms of the GNU General Public License
6 6 # as published by the Free Software Foundation; either version 2
7 7 # of the License, or (at your option) any later version.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU General Public License
15 15 # along with this program; if not, write to the Free Software
16 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 18 require File.dirname(__FILE__) + '/../test_helper'
19 19 require 'users_controller'
20 20
21 21 # Re-raise errors caught by the controller.
22 22 class UsersController; def rescue_action(e) raise e end; end
23 23
24 24 class UsersControllerTest < ActionController::TestCase
25 25 include Redmine::I18n
26 26
27 27 fixtures :users, :projects, :members, :member_roles, :roles
28 28
29 29 def setup
30 30 @controller = UsersController.new
31 31 @request = ActionController::TestRequest.new
32 32 @response = ActionController::TestResponse.new
33 33 User.current = nil
34 34 @request.session[:user_id] = 1 # admin
35 35 end
36 36
37 37 def test_index_routing
38 #TODO: unify with list
39 38 assert_generates(
40 39 '/users',
41 40 :controller => 'users', :action => 'index'
42 41 )
42 assert_routing(
43 {:method => :get, :path => '/users'},
44 :controller => 'users', :action => 'index'
45 )
46 assert_recognizes(
47 {:controller => 'users', :action => 'index'},
48 {:method => :get, :path => '/users'}
49 )
43 50 end
44 51
45 52 def test_index
46 53 get :index
47 54 assert_response :success
48 assert_template 'list'
49 end
50
51 def test_list_routing
52 #TODO: rename action to index
53 assert_routing(
54 {:method => :get, :path => '/users'},
55 :controller => 'users', :action => 'list'
56 )
55 assert_template 'index'
57 56 end
58 57
59 def test_list
60 get :list
58 def test_index
59 get :index
61 60 assert_response :success
62 assert_template 'list'
61 assert_template 'index'
63 62 assert_not_nil assigns(:users)
64 63 # active users only
65 64 assert_nil assigns(:users).detect {|u| !u.active?}
66 65 end
67 66
68 def test_list_with_name_filter
69 get :list, :name => 'john'
67 def test_index_with_name_filter
68 get :index, :name => 'john'
70 69 assert_response :success
71 assert_template 'list'
70 assert_template 'index'
72 71 users = assigns(:users)
73 72 assert_not_nil users
74 73 assert_equal 1, users.size
75 74 assert_equal 'John', users.first.firstname
76 75 end
77 76
78 77 def test_show_routing
79 78 assert_routing(
80 79 {:method => :get, :path => '/users/44'},
81 80 :controller => 'users', :action => 'show', :id => '44'
82 81 )
83 82 assert_recognizes(
84 83 {:controller => 'users', :action => 'show', :id => '44'},
85 84 {:method => :get, :path => '/users/44'}
86 85 )
87 86 end
88 87
89 88 def test_show
90 89 @request.session[:user_id] = nil
91 90 get :show, :id => 2
92 91 assert_response :success
93 92 assert_template 'show'
94 93 assert_not_nil assigns(:user)
95 94 end
96 95
97 96 def test_show_should_not_fail_when_custom_values_are_nil
98 97 user = User.find(2)
99 98
100 99 # Create a custom field to illustrate the issue
101 100 custom_field = CustomField.create!(:name => 'Testing', :field_format => 'text')
102 101 custom_value = user.custom_values.build(:custom_field => custom_field).save!
103 102
104 103 get :show, :id => 2
105 104 assert_response :success
106 105 end
107 106
108 107
109 108 def test_show_inactive
110 109 get :show, :id => 5
111 110 assert_response 404
112 111 assert_nil assigns(:user)
113 112 end
114 113
115 114 def test_show_should_not_reveal_users_with_no_visible_activity_or_project
116 115 @request.session[:user_id] = nil
117 116 get :show, :id => 9
118 117 assert_response 404
119 118 end
120 119
121 120 def test_add_routing
122 121 assert_routing(
123 122 {:method => :get, :path => '/users/new'},
124 123 :controller => 'users', :action => 'add'
125 124 )
126 125 assert_recognizes(
127 126 #TODO: remove this and replace with POST to collection, need to modify form
128 127 {:controller => 'users', :action => 'add'},
129 128 {:method => :post, :path => '/users/new'}
130 129 )
131 130 assert_recognizes(
132 131 {:controller => 'users', :action => 'add'},
133 132 {:method => :post, :path => '/users'}
134 133 )
135 134 end
136 135
137 136 def test_edit_routing
138 137 assert_routing(
139 138 {:method => :get, :path => '/users/444/edit'},
140 139 :controller => 'users', :action => 'edit', :id => '444'
141 140 )
142 141 assert_routing(
143 142 {:method => :get, :path => '/users/222/edit/membership'},
144 143 :controller => 'users', :action => 'edit', :id => '222', :tab => 'membership'
145 144 )
146 145 assert_recognizes(
147 146 #TODO: use PUT on user_path, modify form
148 147 {:controller => 'users', :action => 'edit', :id => '444'},
149 148 {:method => :post, :path => '/users/444/edit'}
150 149 )
151 150 end
152 151
153 152 def test_edit
154 153 ActionMailer::Base.deliveries.clear
155 154 post :edit, :id => 2, :user => {:firstname => 'Changed'}
156 155 assert_equal 'Changed', User.find(2).firstname
157 156 assert ActionMailer::Base.deliveries.empty?
158 157 end
159 158
160 159 def test_edit_with_activation_should_send_a_notification
161 160 u = User.new(:firstname => 'Foo', :lastname => 'Bar', :mail => 'foo.bar@somenet.foo', :language => 'fr')
162 161 u.login = 'foo'
163 162 u.status = User::STATUS_REGISTERED
164 163 u.save!
165 164 ActionMailer::Base.deliveries.clear
166 165 Setting.bcc_recipients = '1'
167 166
168 167 post :edit, :id => u.id, :user => {:status => User::STATUS_ACTIVE}
169 168 assert u.reload.active?
170 169 mail = ActionMailer::Base.deliveries.last
171 170 assert_not_nil mail
172 171 assert_equal ['foo.bar@somenet.foo'], mail.bcc
173 172 assert mail.body.include?(ll('fr', :notice_account_activated))
174 173 end
175 174
176 175 def test_edit_with_password_change_should_send_a_notification
177 176 ActionMailer::Base.deliveries.clear
178 177 Setting.bcc_recipients = '1'
179 178
180 179 u = User.find(2)
181 180 post :edit, :id => u.id, :user => {}, :password => 'newpass', :password_confirmation => 'newpass', :send_information => '1'
182 181 assert_equal User.hash_password('newpass'), u.reload.hashed_password
183 182
184 183 mail = ActionMailer::Base.deliveries.last
185 184 assert_not_nil mail
186 185 assert_equal [u.mail], mail.bcc
187 186 assert mail.body.include?('newpass')
188 187 end
189 188
190 189 def test_add_membership_routing
191 190 assert_routing(
192 191 {:method => :post, :path => '/users/123/memberships'},
193 192 :controller => 'users', :action => 'edit_membership', :id => '123'
194 193 )
195 194 end
196 195
197 196 def test_edit_membership_routing
198 197 assert_routing(
199 198 {:method => :post, :path => '/users/123/memberships/55'},
200 199 :controller => 'users', :action => 'edit_membership', :id => '123', :membership_id => '55'
201 200 )
202 201 end
203 202
204 203 def test_edit_membership
205 204 post :edit_membership, :id => 2, :membership_id => 1,
206 205 :membership => { :role_ids => [2]}
207 206 assert_redirected_to :action => 'edit', :id => '2', :tab => 'memberships'
208 207 assert_equal [2], Member.find(1).role_ids
209 208 end
210 209
211 210 def test_destroy_membership
212 211 assert_routing(
213 212 #TODO: use DELETE method on user_membership_path, modify form
214 213 {:method => :post, :path => '/users/567/memberships/12/destroy'},
215 214 :controller => 'users', :action => 'destroy_membership', :id => '567', :membership_id => '12'
216 215 )
217 216 end
218 217
219 218 def test_destroy_membership
220 219 post :destroy_membership, :id => 2, :membership_id => 1
221 220 assert_redirected_to :action => 'edit', :id => '2', :tab => 'memberships'
222 221 assert_nil Member.find_by_id(1)
223 222 end
224 223 end
General Comments 0
You need to be logged in to leave comments. Login now