##// END OF EJS Templates
Merged r4727 and r4730 from trunk....
Jean-Philippe Lang -
r4651:27a319e66d43
parent child
Show More
@@ -261,12 +261,16 class User < Principal
261 notified_projects_ids
261 notified_projects_ids
262 end
262 end
263
263
264 # Only users that belong to more than 1 project can select projects for which they are notified
265 def valid_notification_options
264 def valid_notification_options
265 self.class.valid_notification_options(self)
266 end
267
268 # Only users that belong to more than 1 project can select projects for which they are notified
269 def self.valid_notification_options(user=nil)
266 # Note that @user.membership.size would fail since AR ignores
270 # Note that @user.membership.size would fail since AR ignores
267 # :include association option when doing a count
271 # :include association option when doing a count
268 if memberships.length < 1
272 if user.nil? || user.memberships.length < 1
269 MAIL_NOTIFICATION_OPTIONS.delete_if {|option| option.first == 'selected'}
273 MAIL_NOTIFICATION_OPTIONS.reject {|option| option.first == 'selected'}
270 else
274 else
271 MAIL_NOTIFICATION_OPTIONS
275 MAIL_NOTIFICATION_OPTIONS
272 end
276 end
@@ -8,7 +8,7
8
8
9 <p><%= setting_check_box :plain_text_mail %></p>
9 <p><%= setting_check_box :plain_text_mail %></p>
10
10
11 <p><%= setting_select(:default_notification_option, User::MAIL_NOTIFICATION_OPTIONS.collect {|o| [l(o.last), o.first.to_s]}) %></p>
11 <p><%= setting_select(:default_notification_option, User.valid_notification_options.collect {|o| [l(o.last), o.first.to_s]}) %></p>
12
12
13 </div>
13 </div>
14
14
@@ -1,5 +1,5
1 # redMine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006 Jean-Philippe Lang
2 # Copyright (C) 2006-2011 Jean-Philippe Lang
3 #
3 #
4 # This program is free software; you can redistribute it and/or
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
5 # modify it under the terms of the GNU General Public License
@@ -303,6 +303,19 class UserTest < ActiveSupport::TestCase
303 assert_nil @dlopper.roles_for_project(Project.find(2)).detect {|role| role.member?}
303 assert_nil @dlopper.roles_for_project(Project.find(2)).detect {|role| role.member?}
304 end
304 end
305
305
306 def test_valid_notification_options
307 # without memberships
308 assert_equal 5, User.find(7).valid_notification_options.size
309 # with memberships
310 assert_equal 6, User.find(2).valid_notification_options.size
311 end
312
313 def test_valid_notification_options_class_method
314 assert_equal 5, User.valid_notification_options.size
315 assert_equal 5, User.valid_notification_options(User.find(7)).size
316 assert_equal 6, User.valid_notification_options(User.find(2)).size
317 end
318
306 def test_mail_notification_all
319 def test_mail_notification_all
307 @jsmith.mail_notification = 'all'
320 @jsmith.mail_notification = 'all'
308 @jsmith.notified_project_ids = []
321 @jsmith.notified_project_ids = []
General Comments 0
You need to be logged in to leave comments. Login now