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