From 134b162ba0d5e2852b25e68563c8619805cc32ac Mon Sep 17 00:00:00 2001 From: MAEDA Go Date: Wed, 18 Mar 2026 13:27:53 +0900 Subject: [PATCH] New email notification option: Only for things I watch --- app/models/user.rb | 3 +++ config/locales/en.yml | 1 + test/unit/mailer_test.rb | 22 ++++++++++++++++++++++ test/unit/user_test.rb | 10 +++++----- 4 files changed, 31 insertions(+), 5 deletions(-) diff --git a/app/models/user.rb b/app/models/user.rb index bec279eb2..085d4988e 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -89,6 +89,7 @@ class User < Principal ['only_my_events', :label_user_mail_option_only_my_events], ['only_assigned', :label_user_mail_option_only_assigned], ['only_owner', :label_user_mail_option_only_owner], + ['only_my_watches', :label_user_mail_option_only_my_watches], ['none', :label_user_mail_option_none] ] @@ -870,6 +871,8 @@ class User < Principal is_or_belongs_to?(object.assigned_to) || is_or_belongs_to?(object.previous_assignee) when 'only_owner' object.author == self + when 'only_my_watches' + object.watched_by?(self) end when News # always send to project members except when mail_notification is set to 'none' diff --git a/config/locales/en.yml b/config/locales/en.yml index 1ea7b4170..90e67bfd8 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -975,6 +975,7 @@ en: 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_owner: "Only for things I watch or I am the owner of" + label_user_mail_option_only_my_watches: "Only for things I watch" 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" label_registration_activation_by_email: Self account activation by email verification diff --git a/test/unit/mailer_test.rb b/test/unit/mailer_test.rb index 792cb7897..ab880ef45 100644 --- a/test/unit/mailer_test.rb +++ b/test/unit/mailer_test.rb @@ -471,6 +471,28 @@ class MailerTest < ActiveSupport::TestCase assert_include user.mail, recipients end + test "#issue_add should notify issue watchers with only_my_watches mail notification" do + issue = Issue.find(1) + user = User.find(9) + user.mail_notification = 'only_my_watches' + user.save! + + Watcher.create!(:watchable => issue, :user => user) + assert Mailer.deliver_issue_add(issue) + assert_include user.mail, recipients + end + + test "#issue_add should not notify the author with only_my_watches mail notification unless watched" do + author = User.find(1) + author.mail_notification = 'only_my_watches' + author.save! + + issue = Issue.generate!(project_id: 1, author: author) + + assert Mailer.deliver_issue_add(issue) + assert_not_include author.mail, recipients + end + test "#issue_add should not notify watchers not allowed to view the issue" do issue = Issue.find(1) user = User.find(9) diff --git a/test/unit/user_test.rb b/test/unit/user_test.rb index d7b170970..8a63017c9 100644 --- a/test/unit/user_test.rb +++ b/test/unit/user_test.rb @@ -1089,15 +1089,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 -- 2.50.1