From b0739821e81f439d6bc65b15245da68b9545192d Mon Sep 17 00:00:00 2001 From: Go MAEDA Date: Tue, 1 Sep 2020 14:08:45 +0000 Subject: [PATCH] Locked users in a group receive notifications when the group is added as a watcher (#4511, #33935). Patch by Yuichi HARADA. git-svn-id: http://svn.redmine.org/redmine/trunk@19998 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- .../lib/acts_as_watchable.rb | 2 +- test/unit/mailer_test.rb | 21 ++++++++++++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/lib/plugins/acts_as_watchable/lib/acts_as_watchable.rb b/lib/plugins/acts_as_watchable/lib/acts_as_watchable.rb index 6b16e18a5..bb71a2884 100644 --- a/lib/plugins/acts_as_watchable/lib/acts_as_watchable.rb +++ b/lib/plugins/acts_as_watchable/lib/acts_as_watchable.rb @@ -73,7 +73,7 @@ module Redmine def notified_watchers notified = watcher_users.active.to_a - notified = notified.map {|n| n.is_a?(Group) ? n.users : n}.flatten + notified = notified.map {|n| n.is_a?(Group) ? n.users.active : n}.flatten notified.uniq! notified.reject! {|user| user.mail.blank? || user.mail_notification == 'none'} if respond_to?(:visible?) diff --git a/test/unit/mailer_test.rb b/test/unit/mailer_test.rb index b676a4503..0e820ce29 100644 --- a/test/unit/mailer_test.rb +++ b/test/unit/mailer_test.rb @@ -30,7 +30,8 @@ class MailerTest < ActiveSupport::TestCase :issue_statuses, :enumerations, :messages, :boards, :repositories, :wikis, :wiki_pages, :wiki_contents, :wiki_content_versions, :versions, - :comments + :comments, + :groups_users, :watchers def setup ActionMailer::Base.deliveries.clear @@ -602,6 +603,24 @@ class MailerTest < ActiveSupport::TestCase end end + def test_locked_user_in_group_watcher_should_not_be_notified + locked_user = users(:users_005) + group = Group.generate! + group.users << locked_user + issue = Issue.generate! + Watcher.create!(:watchable => issue, :user => group) + + ActionMailer::Base.deliveries.clear + assert Mailer.deliver_issue_add(issue) + assert_not_include locked_user.mail, recipients + + journal = issue.init_journal(User.current) + issue.update(:status_id => 4) + ActionMailer::Base.deliveries.clear + Mailer.deliver_issue_edit(journal) + assert_not_include locked_user.mail, recipients + end + def test_version_file_added attachements = [ Attachment.find_by_container_type('Version') ] assert Mailer.deliver_attachments_added(attachements) -- 2.39.5