##// END OF EJS Templates
Extracts user groups assignment from controller....
Jean-Philippe Lang -
r4385:0a2ec6ef0472
parent child
Show More
@@ -145,7 +145,6 class UsersController < ApplicationController
145 if params[:user][:password].present? && (@user.auth_source_id.nil? || params[:user][:auth_source_id].blank?)
145 if params[:user][:password].present? && (@user.auth_source_id.nil? || params[:user][:auth_source_id].blank?)
146 @user.password, @user.password_confirmation = params[:user][:password], params[:user][:password_confirmation]
146 @user.password, @user.password_confirmation = params[:user][:password], params[:user][:password_confirmation]
147 end
147 end
148 @user.group_ids = params[:user][:group_ids] if params[:user][:group_ids]
149 @user.safe_attributes = params[:user]
148 @user.safe_attributes = params[:user]
150 # Was the account actived ? (do it before User#save clears the change)
149 # Was the account actived ? (do it before User#save clears the change)
151 was_activated = (@user.status_change == [User::STATUS_REGISTERED, User::STATUS_ACTIVE])
150 was_activated = (@user.status_change == [User::STATUS_REGISTERED, User::STATUS_ACTIVE])
@@ -60,7 +60,7 class User < Principal
60 attr_accessor :password, :password_confirmation
60 attr_accessor :password, :password_confirmation
61 attr_accessor :last_before_login_on
61 attr_accessor :last_before_login_on
62 # Prevents unauthorized assignments
62 # Prevents unauthorized assignments
63 attr_protected :login, :admin, :password, :password_confirmation, :hashed_password, :group_ids
63 attr_protected :login, :admin, :password, :password_confirmation, :hashed_password
64
64
65 validates_presence_of :login, :firstname, :lastname, :mail, :if => Proc.new { |user| !user.is_a?(AnonymousUser) }
65 validates_presence_of :login, :firstname, :lastname, :mail, :if => Proc.new { |user| !user.is_a?(AnonymousUser) }
66 validates_uniqueness_of :login, :if => Proc.new { |user| !user.login.blank? }, :case_sensitive => false
66 validates_uniqueness_of :login, :if => Proc.new { |user| !user.login.blank? }, :case_sensitive => false
@@ -407,6 +407,9 class User < Principal
407 'auth_source_id',
407 'auth_source_id',
408 :if => lambda {|user, current_user| current_user.admin?}
408 :if => lambda {|user, current_user| current_user.admin?}
409
409
410 safe_attributes 'group_ids',
411 :if => lambda {|user, current_user| current_user.admin? && !user.new_record?}
412
410 # Utility method to help check if a user should be notified about an
413 # Utility method to help check if a user should be notified about an
411 # event.
414 # event.
412 #
415 #
@@ -64,17 +64,24 class MyControllerTest < ActionController::TestCase
64 end
64 end
65
65
66 def test_update_account
66 def test_update_account
67 post :account, :user => {:firstname => "Joe",
67 post :account,
68 :login => "root",
68 :user => {
69 :admin => 1,
69 :firstname => "Joe",
70 :custom_field_values => {"4" => "0100562500"}}
70 :login => "root",
71 :admin => 1,
72 :group_ids => ['10'],
73 :custom_field_values => {"4" => "0100562500"}
74 }
75
71 assert_redirected_to '/my/account'
76 assert_redirected_to '/my/account'
72 user = User.find(2)
77 user = User.find(2)
73 assert_equal user, assigns(:user)
78 assert_equal user, assigns(:user)
74 assert_equal "Joe", user.firstname
79 assert_equal "Joe", user.firstname
75 assert_equal "jsmith", user.login
80 assert_equal "jsmith", user.login
76 assert_equal "0100562500", user.custom_value_for(4).value
81 assert_equal "0100562500", user.custom_value_for(4).value
82 # ignored
77 assert !user.admin?
83 assert !user.admin?
84 assert user.groups.empty?
78 end
85 end
79
86
80 def test_change_password
87 def test_change_password
@@ -183,6 +183,13 class UsersControllerTest < ActionController::TestCase
183 assert ActionMailer::Base.deliveries.empty?
183 assert ActionMailer::Base.deliveries.empty?
184 end
184 end
185
185
186 def test_update_with_group_ids_should_assign_groups
187 put :update, :id => 2, :user => {:group_ids => ['10']}
188
189 user = User.find(2)
190 assert_equal [10], user.group_ids
191 end
192
186 def test_update_with_activation_should_send_a_notification
193 def test_update_with_activation_should_send_a_notification
187 u = User.new(:firstname => 'Foo', :lastname => 'Bar', :mail => 'foo.bar@somenet.foo', :language => 'fr')
194 u = User.new(:firstname => 'Foo', :lastname => 'Bar', :mail => 'foo.bar@somenet.foo', :language => 'fr')
188 u.login = 'foo'
195 u.login = 'foo'
General Comments 0
You need to be logged in to leave comments. Login now