##// END OF EJS Templates
Refactor: split UsersController#edit into #edit and #update...
Eric Davis -
r4116:86ba692bf531
parent child
Show More
@@ -116,7 +116,16 class UsersController < ApplicationController
116 116 @notification_options = @user.valid_notification_options
117 117 @notification_option = @user.mail_notification
118 118
119 if request.post?
119 @auth_sources = AuthSource.find(:all)
120 @membership ||= Member.new
121 end
122
123 verify :method => :put, :only => :update, :render => {:nothing => true, :status => :method_not_allowed }
124 def update
125 @user = User.find(params[:id])
126 @notification_options = @user.valid_notification_options
127 @notification_option = @user.mail_notification
128
120 129 @user.admin = params[:user][:admin] if params[:user][:admin]
121 130 @user.login = params[:user][:login] if params[:user][:login]
122 131 if params[:password].present? && (@user.auth_source_id.nil? || params[:user][:auth_source_id].blank?)
@@ -142,10 +151,12 class UsersController < ApplicationController
142 151 end
143 152 flash[:notice] = l(:notice_successful_update)
144 153 redirect_to :back
145 end
146 end
154 else
147 155 @auth_sources = AuthSource.find(:all)
148 156 @membership ||= Member.new
157
158 render :action => :edit
159 end
149 160 rescue ::ActionController::RedirectBackError
150 161 redirect_to :controller => 'users', :action => 'edit', :id => @user
151 162 end
@@ -34,14 +34,14 module UsersHelper
34 34 end
35 35
36 36 def change_status_link(user)
37 url = {:controller => 'users', :action => 'edit', :id => user, :page => params[:page], :status => params[:status], :tab => nil}
37 url = {:controller => 'users', :action => 'update', :id => user, :page => params[:page], :status => params[:status], :tab => nil}
38 38
39 39 if user.locked?
40 link_to l(:button_unlock), url.merge(:user => {:status => User::STATUS_ACTIVE}), :method => :post, :class => 'icon icon-unlock'
40 link_to l(:button_unlock), url.merge(:user => {:status => User::STATUS_ACTIVE}), :method => :put, :class => 'icon icon-unlock'
41 41 elsif user.registered?
42 link_to l(:button_activate), url.merge(:user => {:status => User::STATUS_ACTIVE}), :method => :post, :class => 'icon icon-unlock'
42 link_to l(:button_activate), url.merge(:user => {:status => User::STATUS_ACTIVE}), :method => :put, :class => 'icon icon-unlock'
43 43 elsif user != User.current
44 link_to l(:button_lock), url.merge(:user => {:status => User::STATUS_LOCKED}), :method => :post, :class => 'icon icon-lock'
44 link_to l(:button_lock), url.merge(:user => {:status => User::STATUS_LOCKED}), :method => :put, :class => 'icon icon-lock'
45 45 end
46 46 end
47 47
@@ -1,4 +1,4
1 <% labelled_tabular_form_for :user, @user, :url => { :controller => 'users', :action => "edit", :tab => nil }, :html => { :class => nil } do |f| %>
1 <% labelled_tabular_form_for :user, @user, :url => { :controller => 'users', :action => "update", :tab => nil }, :html => { :method => :put, :class => nil } do |f| %>
2 2 <%= render :partial => 'form', :locals => { :f => f } %>
3 3 <% if @user.active? -%>
4 4 <p><label><%= check_box_tag 'send_information', 1, true %> <%= l(:label_send_information) %></label>
@@ -1,4 +1,4
1 <% form_for(:user, :url => { :action => 'edit' }) do %>
1 <% form_for(:user, :url => { :action => 'update' }, :html => {:method => :put}) do %>
2 2 <div class="box">
3 3 <% Group.all.sort.each do |group| %>
4 4 <label><%= check_box_tag 'user[group_ids][]', group.id, @user.groups.include?(group) %> <%=h group %></label><br />
@@ -148,11 +148,11 ActionController::Routing::Routes.draw do |map|
148 148 end
149 149 users.with_options :conditions => {:method => :post} do |user_actions|
150 150 user_actions.connect 'users/new', :action => 'create'
151 user_actions.connect 'users/:id/edit', :action => 'edit'
152 151 user_actions.connect 'users/:id/memberships', :action => 'edit_membership'
153 152 user_actions.connect 'users/:id/memberships/:membership_id', :action => 'edit_membership'
154 153 user_actions.connect 'users/:id/memberships/:membership_id/destroy', :action => 'destroy_membership'
155 154 end
155 users.connect 'users/:id/edit', :action => 'update', :conditions => {:method => :put}
156 156 end
157 157
158 158 # For nice "roadmap" in the url for the index action
@@ -153,9 +153,9 class UsersControllerTest < ActionController::TestCase
153 153
154 154 end
155 155
156 def test_edit
156 def test_update
157 157 ActionMailer::Base.deliveries.clear
158 post :edit, :id => 2, :user => {:firstname => 'Changed'}, :notification_option => 'all', :pref => {:hide_mail => '1', :comments_sorting => 'desc'}
158 put :update, :id => 2, :user => {:firstname => 'Changed'}, :notification_option => 'all', :pref => {:hide_mail => '1', :comments_sorting => 'desc'}
159 159
160 160 user = User.find(2)
161 161 assert_equal 'Changed', user.firstname
@@ -165,7 +165,7 class UsersControllerTest < ActionController::TestCase
165 165 assert ActionMailer::Base.deliveries.empty?
166 166 end
167 167
168 def test_edit_with_activation_should_send_a_notification
168 def test_update_with_activation_should_send_a_notification
169 169 u = User.new(:firstname => 'Foo', :lastname => 'Bar', :mail => 'foo.bar@somenet.foo', :language => 'fr')
170 170 u.login = 'foo'
171 171 u.status = User::STATUS_REGISTERED
@@ -173,7 +173,7 class UsersControllerTest < ActionController::TestCase
173 173 ActionMailer::Base.deliveries.clear
174 174 Setting.bcc_recipients = '1'
175 175
176 post :edit, :id => u.id, :user => {:status => User::STATUS_ACTIVE}
176 put :update, :id => u.id, :user => {:status => User::STATUS_ACTIVE}
177 177 assert u.reload.active?
178 178 mail = ActionMailer::Base.deliveries.last
179 179 assert_not_nil mail
@@ -181,12 +181,12 class UsersControllerTest < ActionController::TestCase
181 181 assert mail.body.include?(ll('fr', :notice_account_activated))
182 182 end
183 183
184 def test_edit_with_password_change_should_send_a_notification
184 def test_updat_with_password_change_should_send_a_notification
185 185 ActionMailer::Base.deliveries.clear
186 186 Setting.bcc_recipients = '1'
187 187
188 188 u = User.find(2)
189 post :edit, :id => u.id, :user => {}, :password => 'newpass', :password_confirmation => 'newpass', :send_information => '1'
189 put :update, :id => u.id, :user => {}, :password => 'newpass', :password_confirmation => 'newpass', :send_information => '1'
190 190 assert_equal User.hash_password('newpass'), u.reload.hashed_password
191 191
192 192 mail = ActionMailer::Base.deliveries.last
@@ -195,13 +195,13 class UsersControllerTest < ActionController::TestCase
195 195 assert mail.body.include?('newpass')
196 196 end
197 197
198 test "POST :edit with a password change to an AuthSource user switching to Internal authentication" do
198 test "put :update with a password change to an AuthSource user switching to Internal authentication" do
199 199 # Configure as auth source
200 200 u = User.find(2)
201 201 u.auth_source = AuthSource.find(1)
202 202 u.save!
203 203
204 post :edit, :id => u.id, :user => {:auth_source_id => ''}, :password => 'newpass', :password_confirmation => 'newpass'
204 put :update, :id => u.id, :user => {:auth_source_id => ''}, :password => 'newpass', :password_confirmation => 'newpass'
205 205
206 206 assert_equal nil, u.reload.auth_source
207 207 assert_equal User.hash_password('newpass'), u.reload.hashed_password
@@ -35,7 +35,7 class AdminTest < ActionController::IntegrationTest
35 35 assert_kind_of User, logged_user
36 36 assert_equal "Paul", logged_user.firstname
37 37
38 post "users/edit", :id => user.id, :user => { :status => User::STATUS_LOCKED }
38 put "users/#{user.id}/edit", :id => user.id, :user => { :status => User::STATUS_LOCKED }
39 39 assert_redirected_to "/users/#{ user.id }/edit"
40 40 locked_user = User.try_to_login("psmith", "psmith09")
41 41 assert_equal nil, locked_user
@@ -251,10 +251,11 class RoutingTest < ActionController::IntegrationTest
251 251 should_route :get, "/users/222/edit/membership", :controller => 'users', :action => 'edit', :id => '222', :tab => 'membership'
252 252
253 253 should_route :post, "/users/new", :controller => 'users', :action => 'create'
254 should_route :post, "/users/444/edit", :controller => 'users', :action => 'edit', :id => '444'
255 254 should_route :post, "/users/123/memberships", :controller => 'users', :action => 'edit_membership', :id => '123'
256 255 should_route :post, "/users/123/memberships/55", :controller => 'users', :action => 'edit_membership', :id => '123', :membership_id => '55'
257 256 should_route :post, "/users/567/memberships/12/destroy", :controller => 'users', :action => 'destroy_membership', :id => '567', :membership_id => '12'
257
258 should_route :put, "/users/444/edit", :controller => 'users', :action => 'update', :id => '444'
258 259 end
259 260
260 261 # TODO: should they all be scoped under /projects/:project_id ?
General Comments 0
You need to be logged in to leave comments. Login now