diff --git a/app/models/project.rb b/app/models/project.rb index f9000829b..672ffcdfa 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -626,7 +626,7 @@ class Project < ApplicationRecord # Returns the users that should be notified on project events def notified_users - users.where('members.mail_notification = ? OR users.mail_notification = ?', true, 'all') + users.where('(members.mail_notification = ? OR users.mail_notification = ?) AND users.mail_notification <> ?', true, 'all', 'only_i_watch') end # Returns a scope of all custom fields enabled for project issues diff --git a/app/models/user.rb b/app/models/user.rb index 4d78070d0..63389601b 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -77,6 +77,7 @@ class User < Principal ['selected', :label_user_mail_option_selected], ['only_my_events', :label_user_mail_option_only_my_events], ['only_assigned', :label_user_mail_option_only_assigned], + ['only_i_watch', :label_user_mail_option_only_i_watch], ['only_owner', :label_user_mail_option_only_owner], ['none', :label_user_mail_option_none] ] @@ -816,7 +817,7 @@ class User < Principal def notify_about?(object) if mail_notification == 'all' true - elsif mail_notification.blank? || mail_notification == 'none' + elsif mail_notification.blank? || mail_notification == 'none' || mail_notification == 'only_i_watch' false else case object diff --git a/config/locales/en.yml b/config/locales/en.yml index 0fa3b0234..9b5aa6f6b 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -946,6 +946,7 @@ en: label_user_mail_option_none: "No events" label_user_mail_option_only_my_events: "Only for things I watch or I'm involved in" label_user_mail_option_only_assigned: "Only for things I watch or I am assigned to" + label_user_mail_option_only_i_watch: "Only for things I watch" label_user_mail_option_only_owner: "Only for things I watch or I am the owner of" label_user_mail_no_self_notified: "I don't want to be notified of changes that I make myself" label_user_mail_notify_about_high_priority_issues_html: "Also notify me about issues with a priority of %{prio} or higher" diff --git a/config/locales/ja.yml b/config/locales/ja.yml index 17faf448c..b39ec7058 100644 --- a/config/locales/ja.yml +++ b/config/locales/ja.yml @@ -759,6 +759,7 @@ ja: label_user_mail_option_none: "通知しない" label_user_mail_option_only_my_events: "ウォッチ中または自分が関係しているもの" label_user_mail_option_only_assigned: "ウォッチ中または自分が担当しているもの" + label_user_mail_option_only_i_watch: "ウォッチ中のもの" label_user_mail_option_only_owner: "ウォッチ中または自分が作成したもの" label_user_mail_no_self_notified: 自分自身による変更の通知は不要 label_registration_activation_by_email: メールでアカウントを有効化 diff --git a/test/unit/project_test.rb b/test/unit/project_test.rb index eacbf0c92..cadfa5862 100644 --- a/test/unit/project_test.rb +++ b/test/unit/project_test.rb @@ -1051,6 +1051,9 @@ class ProjectTest < ActiveSupport::TestCase only_owned_user = User.generate!(:mail_notification => 'only_owner') Member.create!(:project => project, :roles => [role], :principal => only_owned_user) + only_i_watch_user = User.generate!(:mail_notification => 'only_i_watch') + Member.create!(:project => project, :roles => [role], :mail_notification => true, :principal => only_i_watch_user) + assert project.notified_users.include?(user_with_membership_notification), "should include members with a mail notification" assert project.notified_users.include?(all_events_user), @@ -1063,6 +1066,8 @@ class ProjectTest < ActiveSupport::TestCase "should not include users with the 'only_assigned' notification option" assert !project.notified_users.include?(only_owned_user), "should not include users with the 'only_owner' notification option" + assert !project.notified_users.include?(only_i_watch_user), + "should not include users with the 'only_i_watch' notification option" end def test_override_roles_without_builtin_group_memberships diff --git a/test/unit/user_test.rb b/test/unit/user_test.rb index be4e4791f..c0829c72d 100644 --- a/test/unit/user_test.rb +++ b/test/unit/user_test.rb @@ -1043,15 +1043,15 @@ class UserTest < ActiveSupport::TestCase def test_valid_notification_options # without memberships - assert_equal 5, User.find(7).valid_notification_options.size + assert_equal 6, User.find(7).valid_notification_options.size # with memberships - assert_equal 6, User.find(2).valid_notification_options.size + assert_equal 7, User.find(2).valid_notification_options.size end def test_valid_notification_options_class_method - assert_equal 5, User.valid_notification_options.size - assert_equal 5, User.valid_notification_options(User.find(7)).size - assert_equal 6, User.valid_notification_options(User.find(2)).size + assert_equal 6, User.valid_notification_options.size + assert_equal 6, User.valid_notification_options(User.find(7)).size + assert_equal 7, User.valid_notification_options(User.find(2)).size end def test_notified_project_ids_setter_should_coerce_to_unique_integer_array @@ -1261,6 +1261,16 @@ class UserTest < ActiveSupport::TestCase assert_equal expected.include?(option), user.notify_about?(issue) end end + + [author, assignee, member].each do |user| + user.mail_notification = 'all' + assert user.notify_about?(issue) + %w(none only_i_watch).each do |option| + + user.mail_notification = option + assert !user.notify_about?(issue) + end + end end def test_notify_about_issue_for_previous_assignee @@ -1292,7 +1302,7 @@ class UserTest < ActiveSupport::TestCase User::MAIL_NOTIFICATION_OPTIONS.map(&:first).each do |option| user.mail_notification = option - assert_equal (option != 'none'), user.notify_about?(news) + assert_equal (option != 'none' && option != 'only_i_watch'), user.notify_about?(news) end end