Moves mail_notification param to user hash param so that it can be set using the User API.

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@4496 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang 2010-12-12 14:19:24 +00:00
parent 1d4f28a54d
commit 9e2d401f43
5 changed files with 15 additions and 23 deletions

View File

@ -54,12 +54,11 @@ class MyController < ApplicationController
@pref = @user.pref @pref = @user.pref
if request.post? if request.post?
@user.safe_attributes = params[:user] @user.safe_attributes = params[:user]
@user.mail_notification = params[:notification_option] || 'only_my_events'
@user.pref.attributes = params[:pref] @user.pref.attributes = params[:pref]
@user.pref[:no_self_notified] = (params[:no_self_notified] == '1') @user.pref[:no_self_notified] = (params[:no_self_notified] == '1')
if @user.save if @user.save
@user.pref.save @user.pref.save
@user.notified_project_ids = (params[:notification_option] == 'selected' ? params[:notified_project_ids] : []) @user.notified_project_ids = (@user.mail_notification == 'selected' ? params[:notified_project_ids] : [])
set_language_if_valid @user.language set_language_if_valid @user.language
flash[:notice] = l(:notice_account_updated) flash[:notice] = l(:notice_account_updated)
redirect_to :action => 'account' redirect_to :action => 'account'
@ -67,7 +66,6 @@ class MyController < ApplicationController
end end
end end
@notification_options = @user.valid_notification_options @notification_options = @user.valid_notification_options
@notification_option = @user.mail_notification #? ? 'all' : (@user.notified_projects_ids.empty? ? 'none' : 'selected')
end end
# Manage user's password # Manage user's password

View File

@ -86,31 +86,28 @@ class UsersController < ApplicationController
def new def new
@notification_options = User::MAIL_NOTIFICATION_OPTIONS @notification_options = User::MAIL_NOTIFICATION_OPTIONS
@notification_option = Setting.default_notification_option
@user = User.new(:language => Setting.default_language) @user = User.new(:language => Setting.default_language, :mail_notification => Setting.default_notification_option)
@auth_sources = AuthSource.find(:all) @auth_sources = AuthSource.find(:all)
end end
verify :method => :post, :only => :create, :render => {:nothing => true, :status => :method_not_allowed } verify :method => :post, :only => :create, :render => {:nothing => true, :status => :method_not_allowed }
def create def create
@notification_options = User::MAIL_NOTIFICATION_OPTIONS @notification_options = User::MAIL_NOTIFICATION_OPTIONS
@notification_option = Setting.default_notification_option
@user = User.new @user = User.new(:language => Setting.default_language, :mail_notification => Setting.default_notification_option)
@user.safe_attributes = params[:user] @user.safe_attributes = params[:user]
@user.admin = params[:user][:admin] || false @user.admin = params[:user][:admin] || false
@user.login = params[:user][:login] @user.login = params[:user][:login]
@user.password, @user.password_confirmation = params[:user][:password], params[:user][:password_confirmation] unless @user.auth_source_id @user.password, @user.password_confirmation = params[:user][:password], params[:user][:password_confirmation] unless @user.auth_source_id
# TODO: Similar to My#account # TODO: Similar to My#account
@user.mail_notification = params[:notification_option] || 'only_my_events'
@user.pref.attributes = params[:pref] @user.pref.attributes = params[:pref]
@user.pref[:no_self_notified] = (params[:no_self_notified] == '1') @user.pref[:no_self_notified] = (params[:no_self_notified] == '1')
if @user.save if @user.save
@user.pref.save @user.pref.save
@user.notified_project_ids = (params[:notification_option] == 'selected' ? params[:notified_project_ids] : []) @user.notified_project_ids = (@user.mail_notification == 'selected' ? params[:notified_project_ids] : [])
Mailer.deliver_account_information(@user, params[:password]) if params[:send_information] Mailer.deliver_account_information(@user, params[:password]) if params[:send_information]
@ -126,7 +123,6 @@ class UsersController < ApplicationController
end end
else else
@auth_sources = AuthSource.find(:all) @auth_sources = AuthSource.find(:all)
@notification_option = @user.mail_notification
# Clear password input # Clear password input
@user.password = @user.password_confirmation = nil @user.password = @user.password_confirmation = nil
@ -140,7 +136,6 @@ class UsersController < ApplicationController
def edit def edit
@user = User.find(params[:id]) @user = User.find(params[:id])
@notification_options = @user.valid_notification_options @notification_options = @user.valid_notification_options
@notification_option = @user.mail_notification
@auth_sources = AuthSource.find(:all) @auth_sources = AuthSource.find(:all)
@membership ||= Member.new @membership ||= Member.new
@ -150,7 +145,6 @@ class UsersController < ApplicationController
def update def update
@user = User.find(params[:id]) @user = User.find(params[:id])
@notification_options = @user.valid_notification_options @notification_options = @user.valid_notification_options
@notification_option = @user.mail_notification
@user.admin = params[:user][:admin] if params[:user][:admin] @user.admin = params[:user][:admin] if params[:user][:admin]
@user.login = params[:user][:login] if params[:user][:login] @user.login = params[:user][:login] if params[:user][:login]
@ -162,13 +156,12 @@ class UsersController < ApplicationController
# Was the account actived ? (do it before User#save clears the change) # Was the account actived ? (do it before User#save clears the change)
was_activated = (@user.status_change == [User::STATUS_REGISTERED, User::STATUS_ACTIVE]) was_activated = (@user.status_change == [User::STATUS_REGISTERED, User::STATUS_ACTIVE])
# TODO: Similar to My#account # TODO: Similar to My#account
@user.mail_notification = params[:notification_option] || 'only_my_events'
@user.pref.attributes = params[:pref] @user.pref.attributes = params[:pref]
@user.pref[:no_self_notified] = (params[:no_self_notified] == '1') @user.pref[:no_self_notified] = (params[:no_self_notified] == '1')
if @user.save if @user.save
@user.pref.save @user.pref.save
@user.notified_project_ids = (params[:notification_option] == 'selected' ? params[:notified_project_ids] : []) @user.notified_project_ids = (@user.mail_notification == 'selected' ? params[:notified_project_ids] : [])
if was_activated if was_activated
Mailer.deliver_account_activated(@user) Mailer.deliver_account_activated(@user)

View File

@ -1,8 +1,8 @@
<p> <p>
<%= select_tag 'notification_option', options_for_select(@notification_options.collect {|o| [l(o.last), o.first]}, @notification_option), <%= select_tag 'user[mail_notification]', options_for_select(@notification_options.collect {|o| [l(o.last), o.first]}, @user.mail_notification),
:onchange => 'if ($("notification_option").value == "selected") {Element.show("notified-projects")} else {Element.hide("notified-projects")}' %> :onchange => 'if (this.value == "selected") {Element.show("notified-projects")} else {Element.hide("notified-projects")}' %>
</p> </p>
<% content_tag 'div', :id => 'notified-projects', :style => (@notification_option == 'selected' ? '' : 'display:none;') do %> <% content_tag 'div', :id => 'notified-projects', :style => (@user.mail_notification == 'selected' ? '' : 'display:none;') do %>
<p><% @user.projects.each do |project| %> <p><% @user.projects.each do |project| %>
<label><%= check_box_tag 'notified_project_ids[]', project.id, @user.notified_projects_ids.include?(project.id) %> <%=h project.name %></label><br /> <label><%= check_box_tag 'notified_project_ids[]', project.id, @user.notified_projects_ids.include?(project.id) %> <%=h project.name %></label><br />
<% end %></p> <% end %></p>

View File

@ -139,9 +139,9 @@ class UsersControllerTest < ActionController::TestCase
:login => 'jdoe', :login => 'jdoe',
:password => 'test', :password => 'test',
:password_confirmation => 'test', :password_confirmation => 'test',
:mail => 'jdoe@gmail.com' :mail => 'jdoe@gmail.com',
}, :mail_notification => 'none'
:notification_option => 'none' }
end end
should_assign_to :user should_assign_to :user
@ -173,11 +173,11 @@ class UsersControllerTest < ActionController::TestCase
def test_update def test_update
ActionMailer::Base.deliveries.clear ActionMailer::Base.deliveries.clear
put :update, :id => 2, :user => {:firstname => 'Changed'}, :notification_option => 'all', :pref => {:hide_mail => '1', :comments_sorting => 'desc'} put :update, :id => 2, :user => {:firstname => 'Changed', :mail_notification => 'only_assigned'}, :pref => {:hide_mail => '1', :comments_sorting => 'desc'}
user = User.find(2) user = User.find(2)
assert_equal 'Changed', user.firstname assert_equal 'Changed', user.firstname
assert_equal 'all', user.mail_notification assert_equal 'only_assigned', user.mail_notification
assert_equal true, user.pref[:hide_mail] assert_equal true, user.pref[:hide_mail]
assert_equal 'desc', user.pref[:comments_sorting] assert_equal 'desc', user.pref[:comments_sorting]
assert ActionMailer::Base.deliveries.empty? assert ActionMailer::Base.deliveries.empty?

View File

@ -54,7 +54,7 @@ class ApiTest::UsersTest < ActionController::IntegrationTest
context "POST /users" do context "POST /users" do
context "with valid parameters" do context "with valid parameters" do
setup do setup do
@parameters = {:user => {:login => 'foo', :firstname => 'Firstname', :lastname => 'Lastname', :mail => 'foo@example.net', :password => 'secret'}} @parameters = {:user => {:login => 'foo', :firstname => 'Firstname', :lastname => 'Lastname', :mail => 'foo@example.net', :password => 'secret', :mail_notification => 'only_assigned'}}
end end
context ".xml" do context ".xml" do
@ -73,6 +73,7 @@ class ApiTest::UsersTest < ActionController::IntegrationTest
assert_equal 'Firstname', user.firstname assert_equal 'Firstname', user.firstname
assert_equal 'Lastname', user.lastname assert_equal 'Lastname', user.lastname
assert_equal 'foo@example.net', user.mail assert_equal 'foo@example.net', user.mail
assert_equal 'only_assigned', user.mail_notification
assert !user.admin? assert !user.admin?
assert user.check_password?('secret') assert user.check_password?('secret')