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