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