From: Jean-Philippe Lang Date: Sun, 12 Dec 2010 14:19:24 +0000 (+0000) Subject: Moves mail_notification param to user hash param so that it can be set using the... X-Git-Tag: 1.1.0~100 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=9e2d401f43d9136e887cb099a72ecc33d9dd88f5;p=redmine.git 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 --- diff --git a/app/controllers/my_controller.rb b/app/controllers/my_controller.rb index e552caa16..26641b527 100644 --- a/app/controllers/my_controller.rb +++ b/app/controllers/my_controller.rb @@ -54,12 +54,11 @@ class MyController < ApplicationController @pref = @user.pref if request.post? @user.safe_attributes = params[:user] - @user.mail_notification = params[:notification_option] || 'only_my_events' @user.pref.attributes = params[:pref] @user.pref[:no_self_notified] = (params[:no_self_notified] == '1') if @user.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 flash[:notice] = l(:notice_account_updated) redirect_to :action => 'account' @@ -67,7 +66,6 @@ class MyController < ApplicationController end end @notification_options = @user.valid_notification_options - @notification_option = @user.mail_notification #? ? 'all' : (@user.notified_projects_ids.empty? ? 'none' : 'selected') end # Manage user's password diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 9c7f2a17d..15ba71830 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -86,31 +86,28 @@ class UsersController < ApplicationController def new @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) end verify :method => :post, :only => :create, :render => {:nothing => true, :status => :method_not_allowed } def create @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.admin = params[:user][:admin] || false @user.login = params[:user][:login] @user.password, @user.password_confirmation = params[:user][:password], params[:user][:password_confirmation] unless @user.auth_source_id # TODO: Similar to My#account - @user.mail_notification = params[:notification_option] || 'only_my_events' @user.pref.attributes = params[:pref] @user.pref[:no_self_notified] = (params[:no_self_notified] == '1') if @user.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] @@ -126,7 +123,6 @@ class UsersController < ApplicationController end else @auth_sources = AuthSource.find(:all) - @notification_option = @user.mail_notification # Clear password input @user.password = @user.password_confirmation = nil @@ -140,7 +136,6 @@ class UsersController < ApplicationController def edit @user = User.find(params[:id]) @notification_options = @user.valid_notification_options - @notification_option = @user.mail_notification @auth_sources = AuthSource.find(:all) @membership ||= Member.new @@ -150,7 +145,6 @@ class UsersController < ApplicationController def update @user = User.find(params[:id]) @notification_options = @user.valid_notification_options - @notification_option = @user.mail_notification @user.admin = params[:user][:admin] if params[:user][:admin] @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_activated = (@user.status_change == [User::STATUS_REGISTERED, User::STATUS_ACTIVE]) # TODO: Similar to My#account - @user.mail_notification = params[:notification_option] || 'only_my_events' @user.pref.attributes = params[:pref] @user.pref[:no_self_notified] = (params[:no_self_notified] == '1') if @user.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 Mailer.deliver_account_activated(@user) diff --git a/app/views/users/_mail_notifications.html.erb b/app/views/users/_mail_notifications.html.erb index 776bdd3f4..5a8216d2a 100644 --- a/app/views/users/_mail_notifications.html.erb +++ b/app/views/users/_mail_notifications.html.erb @@ -1,8 +1,8 @@

-<%= select_tag 'notification_option', options_for_select(@notification_options.collect {|o| [l(o.last), o.first]}, @notification_option), - :onchange => 'if ($("notification_option").value == "selected") {Element.show("notified-projects")} else {Element.hide("notified-projects")}' %> +<%= select_tag 'user[mail_notification]', options_for_select(@notification_options.collect {|o| [l(o.last), o.first]}, @user.mail_notification), + :onchange => 'if (this.value == "selected") {Element.show("notified-projects")} else {Element.hide("notified-projects")}' %>

-<% 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 %>

<% @user.projects.each do |project| %>
<% end %>

diff --git a/test/functional/users_controller_test.rb b/test/functional/users_controller_test.rb index 8b879cc30..0b3231f93 100644 --- a/test/functional/users_controller_test.rb +++ b/test/functional/users_controller_test.rb @@ -139,9 +139,9 @@ class UsersControllerTest < ActionController::TestCase :login => 'jdoe', :password => 'test', :password_confirmation => 'test', - :mail => 'jdoe@gmail.com' - }, - :notification_option => 'none' + :mail => 'jdoe@gmail.com', + :mail_notification => 'none' + } end should_assign_to :user @@ -173,11 +173,11 @@ class UsersControllerTest < ActionController::TestCase def test_update 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) 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 'desc', user.pref[:comments_sorting] assert ActionMailer::Base.deliveries.empty? diff --git a/test/integration/api_test/users_test.rb b/test/integration/api_test/users_test.rb index 83be388a7..f19a64989 100644 --- a/test/integration/api_test/users_test.rb +++ b/test/integration/api_test/users_test.rb @@ -54,7 +54,7 @@ class ApiTest::UsersTest < ActionController::IntegrationTest context "POST /users" do context "with valid parameters" 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 context ".xml" do @@ -73,6 +73,7 @@ class ApiTest::UsersTest < ActionController::IntegrationTest assert_equal 'Firstname', user.firstname assert_equal 'Lastname', user.lastname assert_equal 'foo@example.net', user.mail + assert_equal 'only_assigned', user.mail_notification assert !user.admin? assert user.check_password?('secret')