@@ -54,12 +54,11 class MyController < ApplicationController | |||
|
54 | 54 | @pref = @user.pref |
|
55 | 55 | if request.post? |
|
56 | 56 | @user.safe_attributes = params[:user] |
|
57 | @user.mail_notification = params[:notification_option] || 'only_my_events' | |
|
58 | 57 | @user.pref.attributes = params[:pref] |
|
59 | 58 | @user.pref[:no_self_notified] = (params[:no_self_notified] == '1') |
|
60 | 59 | if @user.save |
|
61 | 60 | @user.pref.save |
|
62 |
@user.notified_project_ids = ( |
|
|
61 | @user.notified_project_ids = (@user.mail_notification == 'selected' ? params[:notified_project_ids] : []) | |
|
63 | 62 | set_language_if_valid @user.language |
|
64 | 63 | flash[:notice] = l(:notice_account_updated) |
|
65 | 64 | redirect_to :action => 'account' |
@@ -67,7 +66,6 class MyController < ApplicationController | |||
|
67 | 66 | end |
|
68 | 67 | end |
|
69 | 68 | @notification_options = @user.valid_notification_options |
|
70 | @notification_option = @user.mail_notification #? ? 'all' : (@user.notified_projects_ids.empty? ? 'none' : 'selected') | |
|
71 | 69 | end |
|
72 | 70 | |
|
73 | 71 | # Manage user's password |
@@ -86,31 +86,28 class UsersController < ApplicationController | |||
|
86 | 86 | |
|
87 | 87 | def new |
|
88 | 88 | @notification_options = User::MAIL_NOTIFICATION_OPTIONS |
|
89 | @notification_option = Setting.default_notification_option | |
|
90 | 89 | |
|
91 | @user = User.new(:language => Setting.default_language) | |
|
90 | @user = User.new(:language => Setting.default_language, :mail_notification => Setting.default_notification_option) | |
|
92 | 91 | @auth_sources = AuthSource.find(:all) |
|
93 | 92 | end |
|
94 | 93 | |
|
95 | 94 | verify :method => :post, :only => :create, :render => {:nothing => true, :status => :method_not_allowed } |
|
96 | 95 | def create |
|
97 | 96 | @notification_options = User::MAIL_NOTIFICATION_OPTIONS |
|
98 | @notification_option = Setting.default_notification_option | |
|
99 | 97 | |
|
100 | @user = User.new | |
|
98 | @user = User.new(:language => Setting.default_language, :mail_notification => Setting.default_notification_option) | |
|
101 | 99 | @user.safe_attributes = params[:user] |
|
102 | 100 | @user.admin = params[:user][:admin] || false |
|
103 | 101 | @user.login = params[:user][:login] |
|
104 | 102 | @user.password, @user.password_confirmation = params[:user][:password], params[:user][:password_confirmation] unless @user.auth_source_id |
|
105 | 103 | |
|
106 | 104 | # TODO: Similar to My#account |
|
107 | @user.mail_notification = params[:notification_option] || 'only_my_events' | |
|
108 | 105 | @user.pref.attributes = params[:pref] |
|
109 | 106 | @user.pref[:no_self_notified] = (params[:no_self_notified] == '1') |
|
110 | 107 | |
|
111 | 108 | if @user.save |
|
112 | 109 | @user.pref.save |
|
113 |
@user.notified_project_ids = ( |
|
|
110 | @user.notified_project_ids = (@user.mail_notification == 'selected' ? params[:notified_project_ids] : []) | |
|
114 | 111 | |
|
115 | 112 | Mailer.deliver_account_information(@user, params[:password]) if params[:send_information] |
|
116 | 113 | |
@@ -126,7 +123,6 class UsersController < ApplicationController | |||
|
126 | 123 | end |
|
127 | 124 | else |
|
128 | 125 | @auth_sources = AuthSource.find(:all) |
|
129 | @notification_option = @user.mail_notification | |
|
130 | 126 | # Clear password input |
|
131 | 127 | @user.password = @user.password_confirmation = nil |
|
132 | 128 | |
@@ -140,7 +136,6 class UsersController < ApplicationController | |||
|
140 | 136 | def edit |
|
141 | 137 | @user = User.find(params[:id]) |
|
142 | 138 | @notification_options = @user.valid_notification_options |
|
143 | @notification_option = @user.mail_notification | |
|
144 | 139 | |
|
145 | 140 | @auth_sources = AuthSource.find(:all) |
|
146 | 141 | @membership ||= Member.new |
@@ -150,7 +145,6 class UsersController < ApplicationController | |||
|
150 | 145 | def update |
|
151 | 146 | @user = User.find(params[:id]) |
|
152 | 147 | @notification_options = @user.valid_notification_options |
|
153 | @notification_option = @user.mail_notification | |
|
154 | 148 | |
|
155 | 149 | @user.admin = params[:user][:admin] if params[:user][:admin] |
|
156 | 150 | @user.login = params[:user][:login] if params[:user][:login] |
@@ -162,13 +156,12 class UsersController < ApplicationController | |||
|
162 | 156 | # Was the account actived ? (do it before User#save clears the change) |
|
163 | 157 | was_activated = (@user.status_change == [User::STATUS_REGISTERED, User::STATUS_ACTIVE]) |
|
164 | 158 | # TODO: Similar to My#account |
|
165 | @user.mail_notification = params[:notification_option] || 'only_my_events' | |
|
166 | 159 | @user.pref.attributes = params[:pref] |
|
167 | 160 | @user.pref[:no_self_notified] = (params[:no_self_notified] == '1') |
|
168 | 161 | |
|
169 | 162 | if @user.save |
|
170 | 163 | @user.pref.save |
|
171 |
@user.notified_project_ids = ( |
|
|
164 | @user.notified_project_ids = (@user.mail_notification == 'selected' ? params[:notified_project_ids] : []) | |
|
172 | 165 | |
|
173 | 166 | if was_activated |
|
174 | 167 | Mailer.deliver_account_activated(@user) |
@@ -1,8 +1,8 | |||
|
1 | 1 | <p> |
|
2 |
<%= select_tag 'notification |
|
|
3 |
:onchange => 'if ( |
|
|
2 | <%= select_tag 'user[mail_notification]', options_for_select(@notification_options.collect {|o| [l(o.last), o.first]}, @user.mail_notification), | |
|
3 | :onchange => 'if (this.value == "selected") {Element.show("notified-projects")} else {Element.hide("notified-projects")}' %> | |
|
4 | 4 | </p> |
|
5 |
<% content_tag 'div', :id => 'notified-projects', :style => (@notifica |
|
|
5 | <% content_tag 'div', :id => 'notified-projects', :style => (@user.mail_notification == 'selected' ? '' : 'display:none;') do %> | |
|
6 | 6 | <p><% @user.projects.each do |project| %> |
|
7 | 7 | <label><%= check_box_tag 'notified_project_ids[]', project.id, @user.notified_projects_ids.include?(project.id) %> <%=h project.name %></label><br /> |
|
8 | 8 | <% end %></p> |
@@ -139,9 +139,9 class UsersControllerTest < ActionController::TestCase | |||
|
139 | 139 | :login => 'jdoe', |
|
140 | 140 | :password => 'test', |
|
141 | 141 | :password_confirmation => 'test', |
|
142 | :mail => 'jdoe@gmail.com' | |
|
143 | }, | |
|
144 | :notification_option => 'none' | |
|
142 | :mail => 'jdoe@gmail.com', | |
|
143 | :mail_notification => 'none' | |
|
144 | } | |
|
145 | 145 | end |
|
146 | 146 | |
|
147 | 147 | should_assign_to :user |
@@ -173,11 +173,11 class UsersControllerTest < ActionController::TestCase | |||
|
173 | 173 | |
|
174 | 174 | def test_update |
|
175 | 175 | ActionMailer::Base.deliveries.clear |
|
176 |
put :update, :id => 2, :user => {:firstname => 'Changed' |
|
|
176 | put :update, :id => 2, :user => {:firstname => 'Changed', :mail_notification => 'only_assigned'}, :pref => {:hide_mail => '1', :comments_sorting => 'desc'} | |
|
177 | 177 | |
|
178 | 178 | user = User.find(2) |
|
179 | 179 | assert_equal 'Changed', user.firstname |
|
180 |
assert_equal ' |
|
|
180 | assert_equal 'only_assigned', user.mail_notification | |
|
181 | 181 | assert_equal true, user.pref[:hide_mail] |
|
182 | 182 | assert_equal 'desc', user.pref[:comments_sorting] |
|
183 | 183 | assert ActionMailer::Base.deliveries.empty? |
@@ -54,7 +54,7 class ApiTest::UsersTest < ActionController::IntegrationTest | |||
|
54 | 54 | context "POST /users" do |
|
55 | 55 | context "with valid parameters" do |
|
56 | 56 | setup do |
|
57 | @parameters = {:user => {:login => 'foo', :firstname => 'Firstname', :lastname => 'Lastname', :mail => 'foo@example.net', :password => 'secret'}} | |
|
57 | @parameters = {:user => {:login => 'foo', :firstname => 'Firstname', :lastname => 'Lastname', :mail => 'foo@example.net', :password => 'secret', :mail_notification => 'only_assigned'}} | |
|
58 | 58 | end |
|
59 | 59 | |
|
60 | 60 | context ".xml" do |
@@ -73,6 +73,7 class ApiTest::UsersTest < ActionController::IntegrationTest | |||
|
73 | 73 | assert_equal 'Firstname', user.firstname |
|
74 | 74 | assert_equal 'Lastname', user.lastname |
|
75 | 75 | assert_equal 'foo@example.net', user.mail |
|
76 | assert_equal 'only_assigned', user.mail_notification | |
|
76 | 77 | assert !user.admin? |
|
77 | 78 | assert user.check_password?('secret') |
|
78 | 79 |
General Comments 0
You need to be logged in to leave comments.
Login now