Feature #1935 » never_notify.patch
| app/controllers/my_controller.rb | ||
|---|---|---|
| 57 | 57 |
@user.mail_notification = (params[:notification_option] == 'all') |
| 58 | 58 |
@user.pref.attributes = params[:pref] |
| 59 | 59 |
@user.pref[:no_self_notified] = (params[:no_self_notified] == '1') |
| 60 |
@user.never_notify = (params[:notification_option] == 'never') |
|
| 60 | 61 |
if @user.save |
| 61 | 62 |
@user.pref.save |
| 62 | 63 |
@user.notified_project_ids = (params[:notification_option] == 'selected' ? params[:notified_project_ids] : []) |
| ... | ... | |
| 67 | 68 |
end |
| 68 | 69 |
end |
| 69 | 70 |
@notification_options = [[l(:label_user_mail_option_all), 'all'], |
| 70 |
[l(:label_user_mail_option_none), 'none']] |
|
| 71 |
[l(:label_user_mail_option_none), 'none'], |
|
| 72 |
[l(:label_user_mail_option_never), 'never']] |
|
| 71 | 73 |
# Only users that belong to more than 1 project can select projects for which they are notified |
| 72 | 74 |
# Note that @user.membership.size would fail since AR ignores :include association option when doing a count |
| 73 | 75 |
@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') |
|
| 76 |
@notification_option = @user.mail_notification? ? 'all' : (@user.notified_projects_ids.empty? ? 'none' : 'selected') |
|
| 77 |
@notification_option = 'never' if @user.never_notify? |
|
| 75 | 78 |
end |
| 76 | 79 | |
| 77 | 80 |
# Manage user's password |
| app/models/issue.rb | ||
|---|---|---|
| 210 | 210 |
def recipients |
| 211 | 211 |
recipients = project.recipients |
| 212 | 212 |
# Author and assignee are always notified unless they have been locked |
| 213 |
recipients << author.mail if author && author.active? |
|
| 214 |
recipients << assigned_to.mail if assigned_to && assigned_to.active? |
|
| 213 |
recipients << author.mail if author && author.active? && !author.never_notify?
|
|
| 214 |
recipients << assigned_to.mail if assigned_to && assigned_to.active? && !assigned_to.never_notify?
|
|
| 215 | 215 |
recipients.compact.uniq |
| 216 | 216 |
end |
| 217 | 217 |
|
| app/models/user.rb | ||
|---|---|---|
| 253 | 253 |
end |
| 254 | 254 |
end |
| 255 | 255 |
|
| 256 |
def never_notify? |
|
| 257 |
self.pref[:never_notify] == true |
|
| 258 |
end |
|
| 259 | ||
| 260 |
def never_notify=(notify) |
|
| 261 |
self.pref[:never_notify] = notify |
|
| 262 |
self.pref.save! |
|
| 263 |
self.pref[:never_notify] |
|
| 264 |
end |
|
| 265 | ||
| 256 | 266 |
def self.current=(user) |
| 257 | 267 |
@current_user = user |
| 258 | 268 |
end |
| app/views/my/account.rhtml | ||
|---|---|---|
| 24 | 24 |
<h3><%=l(:field_mail_notification)%></h3> |
| 25 | 25 |
<div class="box"> |
| 26 | 26 |
<%= select_tag 'notification_option', options_for_select(@notification_options, @notification_option), |
| 27 |
:onchange => 'if ($("notification_option").value == "selected") {Element.show("notified-projects")} else {Element.hide("notified-projects")}' %>
|
|
| 27 |
:onchange => 'if ($("notification_option").value == "selected") {Element.show("notified-projects")} else {Element.hide("notified-projects")}; if ($("notification_option").value != "never") {Element.show("self_notification")} else {Element.hide("self_notification")};' %>
|
|
| 28 | 28 |
<% content_tag 'div', :id => 'notified-projects', :style => (@notification_option == 'selected' ? '' : 'display:none;') do %> |
| 29 | 29 |
<p><% User.current.projects.each do |project| %> |
| 30 | 30 |
<label><%= check_box_tag 'notified_project_ids[]', project.id, @user.notified_projects_ids.include?(project.id) %> <%=h project.name %></label><br /> |
| 31 | 31 |
<% end %></p> |
| 32 | 32 |
<p><em><%= l(:text_user_mail_option) %></em></p> |
| 33 | 33 |
<% end %> |
| 34 |
<p><label><%= check_box_tag 'no_self_notified', 1, @user.pref[:no_self_notified] %> <%= l(:label_user_mail_no_self_notified) %></label></p> |
|
| 34 | ||
| 35 |
<% content_tag 'p', :id => 'self_notification', :style => (@notification_option != 'never' ? '' : 'display:none;') do %> |
|
| 36 |
<label><%= check_box_tag 'no_self_notified', 1, @user.pref[:no_self_notified] %> <%= l(:label_user_mail_no_self_notified) %></label> |
|
| 37 |
<% end %> |
|
| 35 | 38 |
</div> |
| 36 | 39 | |
| 37 | 40 |
<h3><%=l(:label_preferences)%></h3> |
| lang/de.yml | ||
|---|---|---|
| 556 | 556 |
label_user_mail_option_all: "Für alle Ereignisse in all meinen Projekten" |
| 557 | 557 |
label_user_mail_option_selected: "Für alle Ereignisse in den ausgewählten Projekten..." |
| 558 | 558 |
label_user_mail_option_none: "Nur für Dinge, die ich beobachte oder an denen ich beteiligt bin" |
| 559 |
label_user_mail_option_never: "Nie per Email benachrichtigen" |
|
| 559 | 560 |
label_user_mail_no_self_notified: "Ich möchte nicht über Änderungen benachrichtigt werden, die ich selbst durchführe." |
| 560 | 561 |
label_registration_activation_by_email: Kontoaktivierung durch E-Mail |
| 561 | 562 |
label_registration_manual_activation: Manuelle Kontoaktivierung |
| lang/en.yml | ||
|---|---|---|
| 556 | 556 |
label_user_mail_option_all: "For any event on all my projects" |
| 557 | 557 |
label_user_mail_option_selected: "For any event on the selected projects only..." |
| 558 | 558 |
label_user_mail_option_none: "Only for things I watch or I'm involved in" |
| 559 |
label_user_mail_option_never: "Never notify me by mail" |
|
| 559 | 560 |
label_user_mail_no_self_notified: "I don't want to be notified of changes that I make myself" |
| 560 | 561 |
label_registration_activation_by_email: account activation by email |
| 561 | 562 |
label_registration_manual_activation: manual account activation |
| test/unit/user_test.rb | ||
|---|---|---|
| 18 | 18 |
require File.dirname(__FILE__) + '/../test_helper' |
| 19 | 19 | |
| 20 | 20 |
class UserTest < Test::Unit::TestCase |
| 21 |
fixtures :users, :members, :projects |
|
| 21 |
fixtures :users, :members, :projects, :issues, :user_preferences
|
|
| 22 | 22 | |
| 23 | 23 |
def setup |
| 24 | 24 |
@admin = User.find(1) |
| ... | ... | |
| 151 | 151 |
assert !@jsmith.projects.first.recipients.include?(@jsmith.mail) |
| 152 | 152 |
end |
| 153 | 153 |
|
| 154 |
def test_mail_notification_never |
|
| 155 |
assert Issue.first.recipients.include?(@jsmith.mail) |
|
| 156 |
@jsmith.mail_notification = false |
|
| 157 |
@jsmith.notified_project_ids = [] |
|
| 158 |
@jsmith.never_notify = true |
|
| 159 |
@jsmith.save |
|
| 160 |
@jsmith.reload |
|
| 161 |
assert @jsmith.preference[:never_notify] == true |
|
| 162 |
assert !Issue.first.recipients.include?(@jsmith.mail) |
|
| 163 |
end |
|
| 164 |
|
|
| 154 | 165 |
def test_comments_sorting_preference |
| 155 | 166 |
assert !@jsmith.wants_comments_in_reverse_order? |
| 156 | 167 |
@jsmith.pref.comments_sorting = 'asc' |
| test/unit/watcher_test.rb | ||
|---|---|---|
| 59 | 59 |
@user.save |
| 60 | 60 |
@issue.reload |
| 61 | 61 |
assert @issue.watcher_recipients.include?(@user.mail) |
| 62 |
|
|
| 63 |
@user.never_notify = true |
|
| 64 |
@user.save |
|
| 65 |
@issue.reload |
|
| 66 |
assert !@issue.watcher_recipients.include?(@user.mail) |
|
| 62 | 67 |
end |
| 63 | 68 |
|
| 64 | 69 |
def test_unwatch |
| vendor/plugins/acts_as_watchable/lib/acts_as_watchable.rb | ||
|---|---|---|
| 52 | 52 |
|
| 53 | 53 |
# Returns an array of watchers' email addresses |
| 54 | 54 |
def watcher_recipients |
| 55 |
self.watchers.collect { |w| w.user.mail if w.user.active? }.compact
|
|
| 55 |
self.watchers.collect { |w| w.user.mail if w.user.active? && !w.user.never_notify? }.compact
|
|
| 56 | 56 |
end |
| 57 | 57 | |
| 58 | 58 |
module ClassMethods |