diff --git a/app/controllers/my_controller.rb b/app/controllers/my_controller.rb
index 1cfa3e5..02dffaf 100644
--- a/app/controllers/my_controller.rb
+++ b/app/controllers/my_controller.rb
@@ -57,6 +57,7 @@ class MyController < ApplicationController
@user.mail_notification = (params[:notification_option] == 'all')
@user.pref.attributes = params[:pref]
@user.pref[:no_self_notified] = (params[:no_self_notified] == '1')
+ @user.never_notify = (params[:notification_option] == 'never')
if @user.save
@user.pref.save
@user.notified_project_ids = (params[:notification_option] == 'selected' ? params[:notified_project_ids] : [])
@@ -67,11 +68,13 @@ class MyController < ApplicationController
end
end
@notification_options = [[l(:label_user_mail_option_all), 'all'],
- [l(:label_user_mail_option_none), 'none']]
+ [l(:label_user_mail_option_none), 'none'],
+ [l(:label_user_mail_option_never), 'never']]
# Only users that belong to more than 1 project can select projects for which they are notified
# Note that @user.membership.size would fail since AR ignores :include association option when doing a count
@notification_options.insert 1, [l(:label_user_mail_option_selected), 'selected'] if @user.memberships.length > 1
- @notification_option = @user.mail_notification? ? 'all' : (@user.notified_projects_ids.empty? ? 'none' : 'selected')
+ @notification_option = @user.mail_notification? ? 'all' : (@user.notified_projects_ids.empty? ? 'none' : 'selected')
+ @notification_option = 'never' if @user.never_notify?
end
# Manage user's password
diff --git a/app/models/issue.rb b/app/models/issue.rb
index 4701e41..2f30680 100644
--- a/app/models/issue.rb
+++ b/app/models/issue.rb
@@ -210,8 +210,8 @@ class Issue < ActiveRecord::Base
def recipients
recipients = project.recipients
# Author and assignee are always notified unless they have been locked
- recipients << author.mail if author && author.active?
- recipients << assigned_to.mail if assigned_to && assigned_to.active?
+ recipients << author.mail if author && author.active? && !author.never_notify?
+ recipients << assigned_to.mail if assigned_to && assigned_to.active? && !assigned_to.never_notify?
recipients.compact.uniq
end
diff --git a/app/models/user.rb b/app/models/user.rb
index 72c550b..7bae9b2 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -253,6 +253,16 @@ class User < ActiveRecord::Base
end
end
+ def never_notify?
+ self.pref[:never_notify] == true
+ end
+
+ def never_notify=(notify)
+ self.pref[:never_notify] = notify
+ self.pref.save!
+ self.pref[:never_notify]
+ end
+
def self.current=(user)
@current_user = user
end
diff --git a/app/views/my/account.rhtml b/app/views/my/account.rhtml
index 20210c9..6cb8208 100644
--- a/app/views/my/account.rhtml
+++ b/app/views/my/account.rhtml
@@ -24,14 +24,17 @@
<%=l(:field_mail_notification)%>
<%= select_tag 'notification_option', options_for_select(@notification_options, @notification_option),
- :onchange => 'if ($("notification_option").value == "selected") {Element.show("notified-projects")} else {Element.hide("notified-projects")}' %>
+ :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")};' %>
<% content_tag 'div', :id => 'notified-projects', :style => (@notification_option == 'selected' ? '' : 'display:none;') do %>
<% User.current.projects.each do |project| %>
<% end %>
<%= l(:text_user_mail_option) %>
<% end %>
-
+
+<% content_tag 'p', :id => 'self_notification', :style => (@notification_option != 'never' ? '' : 'display:none;') do %>
+
+<% end %>
<%=l(:label_preferences)%>
diff --git a/lang/de.yml b/lang/de.yml
index a621ecf..42d8945 100644
--- a/lang/de.yml
+++ b/lang/de.yml
@@ -556,6 +556,7 @@ label_search_titles_only: Nur Titel durchsuchen
label_user_mail_option_all: "Für alle Ereignisse in all meinen Projekten"
label_user_mail_option_selected: "Für alle Ereignisse in den ausgewählten Projekten..."
label_user_mail_option_none: "Nur für Dinge, die ich beobachte oder an denen ich beteiligt bin"
+label_user_mail_option_never: "Nie per Email benachrichtigen"
label_user_mail_no_self_notified: "Ich möchte nicht über Änderungen benachrichtigt werden, die ich selbst durchführe."
label_registration_activation_by_email: Kontoaktivierung durch E-Mail
label_registration_manual_activation: Manuelle Kontoaktivierung
diff --git a/lang/en.yml b/lang/en.yml
index 245663f..6240644 100644
--- a/lang/en.yml
+++ b/lang/en.yml
@@ -556,6 +556,7 @@ label_search_titles_only: Search titles only
label_user_mail_option_all: "For any event on all my projects"
label_user_mail_option_selected: "For any event on the selected projects only..."
label_user_mail_option_none: "Only for things I watch or I'm involved in"
+label_user_mail_option_never: "Never notify me by mail"
label_user_mail_no_self_notified: "I don't want to be notified of changes that I make myself"
label_registration_activation_by_email: account activation by email
label_registration_manual_activation: manual account activation
diff --git a/test/unit/user_test.rb b/test/unit/user_test.rb
index b931501..51ec622 100644
--- a/test/unit/user_test.rb
+++ b/test/unit/user_test.rb
@@ -18,7 +18,7 @@
require File.dirname(__FILE__) + '/../test_helper'
class UserTest < Test::Unit::TestCase
- fixtures :users, :members, :projects
+ fixtures :users, :members, :projects, :issues, :user_preferences
def setup
@admin = User.find(1)
@@ -151,6 +151,17 @@ class UserTest < Test::Unit::TestCase
assert !@jsmith.projects.first.recipients.include?(@jsmith.mail)
end
+ def test_mail_notification_never
+ assert Issue.first.recipients.include?(@jsmith.mail)
+ @jsmith.mail_notification = false
+ @jsmith.notified_project_ids = []
+ @jsmith.never_notify = true
+ @jsmith.save
+ @jsmith.reload
+ assert @jsmith.preference[:never_notify] == true
+ assert !Issue.first.recipients.include?(@jsmith.mail)
+ end
+
def test_comments_sorting_preference
assert !@jsmith.wants_comments_in_reverse_order?
@jsmith.pref.comments_sorting = 'asc'
diff --git a/test/unit/watcher_test.rb b/test/unit/watcher_test.rb
index 9566e6a..c72b495 100644
--- a/test/unit/watcher_test.rb
+++ b/test/unit/watcher_test.rb
@@ -59,6 +59,11 @@ class WatcherTest < Test::Unit::TestCase
@user.save
@issue.reload
assert @issue.watcher_recipients.include?(@user.mail)
+
+ @user.never_notify = true
+ @user.save
+ @issue.reload
+ assert !@issue.watcher_recipients.include?(@user.mail)
end
def test_unwatch
diff --git a/vendor/plugins/acts_as_watchable/lib/acts_as_watchable.rb b/vendor/plugins/acts_as_watchable/lib/acts_as_watchable.rb
index 2cb1227..2753074 100644
--- a/vendor/plugins/acts_as_watchable/lib/acts_as_watchable.rb
+++ b/vendor/plugins/acts_as_watchable/lib/acts_as_watchable.rb
@@ -52,7 +52,7 @@ module Redmine
# Returns an array of watchers' email addresses
def watcher_recipients
- self.watchers.collect { |w| w.user.mail if w.user.active? }.compact
+ self.watchers.collect { |w| w.user.mail if w.user.active? && !w.user.never_notify? }.compact
end
module ClassMethods