##// END OF EJS Templates
Converted User#mail_notification from a boolean to a string....
Eric Davis -
r4102:0316af7f6bfa
parent child
Show More
@@ -0,0 +1,9
1 class ChangeUsersMailNotificationToString < ActiveRecord::Migration
2 def self.up
3 change_column :users, :mail_notification, :string, :default => '', :null => false
4 end
5
6 def self.down
7 change_column :users, :mail_notification, :boolean, :default => true, :null => false
8 end
9 end
@@ -0,0 +1,11
1 # Patch the data from a boolean change.
2 class UpdateMailNotificationValues < ActiveRecord::Migration
3 def self.up
4 User.update_all("mail_notification = 'all'", "mail_notification = '1'")
5 User.update_all("mail_notification = 'only_my_events'", "mail_notification = '0'")
6 end
7
8 def self.down
9 # No-op
10 end
11 end
@@ -54,7 +54,7 class MyController < ApplicationController
54 @pref = @user.pref
54 @pref = @user.pref
55 if request.post?
55 if request.post?
56 @user.attributes = params[:user]
56 @user.attributes = params[:user]
57 @user.mail_notification = (params[:notification_option] == 'all')
57 @user.mail_notification = params[:notification_option] || 'only_my_events'
58 @user.pref.attributes = params[:pref]
58 @user.pref.attributes = params[:pref]
59 @user.pref[:no_self_notified] = (params[:no_self_notified] == '1')
59 @user.pref[:no_self_notified] = (params[:no_self_notified] == '1')
60 if @user.save
60 if @user.save
@@ -66,12 +66,14 class MyController < ApplicationController
66 return
66 return
67 end
67 end
68 end
68 end
69 @notification_options = [[l(:label_user_mail_option_all), 'all'],
69 @notification_options = User::MAIL_NOTIFICATION_OPTIONS
70 [l(:label_user_mail_option_none), 'none']]
71 # Only users that belong to more than 1 project can select projects for which they are notified
70 # Only users that belong to more than 1 project can select projects for which they are notified
72 # Note that @user.membership.size would fail since AR ignores :include association option when doing a count
71 # Note that @user.membership.size would fail since AR ignores
73 @notification_options.insert 1, [l(:label_user_mail_option_selected), 'selected'] if @user.memberships.length > 1
72 # :include association option when doing a count
74 @notification_option = @user.mail_notification? ? 'all' : (@user.notified_projects_ids.empty? ? 'none' : 'selected')
73 if @user.memberships.length < 1
74 @notification_options.delete_if {|option| option.first == :selected}
75 end
76 @notification_option = @user.mail_notification #? ? 'all' : (@user.notified_projects_ids.empty? ? 'none' : 'selected')
75 end
77 end
76
78
77 # Manage user's password
79 # Manage user's password
@@ -382,7 +382,7 class Project < ActiveRecord::Base
382
382
383 # Returns the mail adresses of users that should be always notified on project events
383 # Returns the mail adresses of users that should be always notified on project events
384 def recipients
384 def recipients
385 members.select {|m| m.mail_notification? || m.user.mail_notification?}.collect {|m| m.user.mail}
385 members.select {|m| m.mail_notification? || m.user.mail_notification == 'all'}.collect {|m| m.user.mail}
386 end
386 end
387
387
388 # Returns the users that should be notified on project events
388 # Returns the users that should be notified on project events
@@ -33,6 +33,15 class User < Principal
33 :username => '#{login}'
33 :username => '#{login}'
34 }
34 }
35
35
36 MAIL_NOTIFICATION_OPTIONS = [
37 [:all, :label_user_mail_option_all],
38 [:selected, :label_user_mail_option_selected],
39 [:none, :label_user_mail_option_none],
40 [:only_my_events, :label_user_mail_option_only_my_events],
41 [:only_assigned, :label_user_mail_option_only_assigned],
42 [:only_owner, :label_user_mail_option_only_owner]
43 ]
44
36 has_and_belongs_to_many :groups, :after_add => Proc.new {|user, group| group.user_added(user)},
45 has_and_belongs_to_many :groups, :after_add => Proc.new {|user, group| group.user_added(user)},
37 :after_remove => Proc.new {|user, group| group.user_removed(user)}
46 :after_remove => Proc.new {|user, group| group.user_removed(user)}
38 has_many :issue_categories, :foreign_key => 'assigned_to_id', :dependent => :nullify
47 has_many :issue_categories, :foreign_key => 'assigned_to_id', :dependent => :nullify
@@ -65,7 +74,7 class User < Principal
65 validates_confirmation_of :password, :allow_nil => true
74 validates_confirmation_of :password, :allow_nil => true
66
75
67 def before_create
76 def before_create
68 self.mail_notification = false
77 self.mail_notification = 'only_my_events'
69 true
78 true
70 end
79 end
71
80
@@ -32,7 +32,7
32 <div class="splitcontentright">
32 <div class="splitcontentright">
33 <h3><%=l(:field_mail_notification)%></h3>
33 <h3><%=l(:field_mail_notification)%></h3>
34 <div class="box">
34 <div class="box">
35 <%= select_tag 'notification_option', options_for_select(@notification_options, @notification_option),
35 <%= select_tag 'notification_option', options_for_select(@notification_options.collect {|o| [l(o.last), o.first]}, @notification_option.to_sym),
36 :onchange => 'if ($("notification_option").value == "selected") {Element.show("notified-projects")} else {Element.hide("notified-projects")}' %>
36 :onchange => 'if ($("notification_option").value == "selected") {Element.show("notified-projects")} else {Element.hide("notified-projects")}' %>
37 <% content_tag 'div', :id => 'notified-projects', :style => (@notification_option == 'selected' ? '' : 'display:none;') do %>
37 <% content_tag 'div', :id => 'notified-projects', :style => (@notification_option == 'selected' ? '' : 'display:none;') do %>
38 <p><% User.current.projects.each do |project| %>
38 <p><% User.current.projects.each do |project| %>
@@ -725,7 +725,10 en:
725 label_search_titles_only: Search titles only
725 label_search_titles_only: Search titles only
726 label_user_mail_option_all: "For any event on all my projects"
726 label_user_mail_option_all: "For any event on all my projects"
727 label_user_mail_option_selected: "For any event on the selected projects only..."
727 label_user_mail_option_selected: "For any event on the selected projects only..."
728 label_user_mail_option_none: "Only for things I watch or I'm involved in"
728 label_user_mail_option_none: "No events"
729 label_user_mail_option_only_my_events: "Only for things I watch or I'm involved in"
730 label_user_mail_option_only_assigned: "Only for things I am assigned to"
731 label_user_mail_option_only_owner: "Only for things I am the owner of"
729 label_user_mail_no_self_notified: "I don't want to be notified of changes that I make myself"
732 label_user_mail_no_self_notified: "I don't want to be notified of changes that I make myself"
730 label_registration_activation_by_email: account activation by email
733 label_registration_activation_by_email: account activation by email
731 label_registration_manual_activation: manual account activation
734 label_registration_manual_activation: manual account activation
@@ -12,7 +12,7 users_004:
12 firstname: Robert
12 firstname: Robert
13 id: 4
13 id: 4
14 auth_source_id:
14 auth_source_id:
15 mail_notification: true
15 mail_notification: all
16 login: rhill
16 login: rhill
17 type: User
17 type: User
18 users_001:
18 users_001:
@@ -28,7 +28,7 users_001:
28 firstname: redMine
28 firstname: redMine
29 id: 1
29 id: 1
30 auth_source_id:
30 auth_source_id:
31 mail_notification: true
31 mail_notification: all
32 login: admin
32 login: admin
33 type: User
33 type: User
34 users_002:
34 users_002:
@@ -44,7 +44,7 users_002:
44 firstname: John
44 firstname: John
45 id: 2
45 id: 2
46 auth_source_id:
46 auth_source_id:
47 mail_notification: true
47 mail_notification: all
48 login: jsmith
48 login: jsmith
49 type: User
49 type: User
50 users_003:
50 users_003:
@@ -60,7 +60,7 users_003:
60 firstname: Dave
60 firstname: Dave
61 id: 3
61 id: 3
62 auth_source_id:
62 auth_source_id:
63 mail_notification: true
63 mail_notification: all
64 login: dlopper
64 login: dlopper
65 type: User
65 type: User
66 users_005:
66 users_005:
@@ -77,7 +77,7 users_005:
77 lastname: Lopper2
77 lastname: Lopper2
78 firstname: Dave2
78 firstname: Dave2
79 auth_source_id:
79 auth_source_id:
80 mail_notification: true
80 mail_notification: all
81 login: dlopper2
81 login: dlopper2
82 type: User
82 type: User
83 users_006:
83 users_006:
@@ -93,7 +93,7 users_006:
93 lastname: Anonymous
93 lastname: Anonymous
94 firstname: ''
94 firstname: ''
95 auth_source_id:
95 auth_source_id:
96 mail_notification: false
96 mail_notification: only_my_events
97 login: ''
97 login: ''
98 type: AnonymousUser
98 type: AnonymousUser
99 users_007:
99 users_007:
@@ -109,7 +109,7 users_007:
109 lastname: One
109 lastname: One
110 firstname: Some
110 firstname: Some
111 auth_source_id:
111 auth_source_id:
112 mail_notification: false
112 mail_notification: only_my_events
113 login: someone
113 login: someone
114 type: User
114 type: User
115 users_008:
115 users_008:
@@ -125,7 +125,7 users_008:
125 lastname: Misc
125 lastname: Misc
126 firstname: User
126 firstname: User
127 auth_source_id:
127 auth_source_id:
128 mail_notification: false
128 mail_notification: only_my_events
129 login: miscuser8
129 login: miscuser8
130 type: User
130 type: User
131 users_009:
131 users_009:
@@ -141,7 +141,7 users_009:
141 lastname: Misc
141 lastname: Misc
142 firstname: User
142 firstname: User
143 auth_source_id:
143 auth_source_id:
144 mail_notification: false
144 mail_notification: only_my_events
145 login: miscuser9
145 login: miscuser9
146 type: User
146 type: User
147 groups_010:
147 groups_010:
@@ -153,4 +153,4 groups_011:
153 lastname: B Team
153 lastname: B Team
154 type: Group
154 type: Group
155
155
156 No newline at end of file
156
@@ -285,7 +285,7 class UserTest < ActiveSupport::TestCase
285 end
285 end
286
286
287 def test_mail_notification_all
287 def test_mail_notification_all
288 @jsmith.mail_notification = true
288 @jsmith.mail_notification = 'all'
289 @jsmith.notified_project_ids = []
289 @jsmith.notified_project_ids = []
290 @jsmith.save
290 @jsmith.save
291 @jsmith.reload
291 @jsmith.reload
@@ -293,15 +293,15 class UserTest < ActiveSupport::TestCase
293 end
293 end
294
294
295 def test_mail_notification_selected
295 def test_mail_notification_selected
296 @jsmith.mail_notification = false
296 @jsmith.mail_notification = 'selected'
297 @jsmith.notified_project_ids = [1]
297 @jsmith.notified_project_ids = [1]
298 @jsmith.save
298 @jsmith.save
299 @jsmith.reload
299 @jsmith.reload
300 assert Project.find(1).recipients.include?(@jsmith.mail)
300 assert Project.find(1).recipients.include?(@jsmith.mail)
301 end
301 end
302
302
303 def test_mail_notification_none
303 def test_mail_notification_only_my_events
304 @jsmith.mail_notification = false
304 @jsmith.mail_notification = 'only_my_events'
305 @jsmith.notified_project_ids = []
305 @jsmith.notified_project_ids = []
306 @jsmith.save
306 @jsmith.save
307 @jsmith.reload
307 @jsmith.reload
General Comments 0
You need to be logged in to leave comments. Login now