]> source.dussan.org Git - redmine.git/commitdiff
Disable auto watch for the anonymous user (#38238).
authorGo MAEDA <maeda@farend.jp>
Sun, 26 Feb 2023 07:48:19 +0000 (07:48 +0000)
committerGo MAEDA <maeda@farend.jp>
Sun, 26 Feb 2023 07:48:19 +0000 (07:48 +0000)
Patch by Felix Schäfer.

git-svn-id: https://svn.redmine.org/redmine/trunk@22116 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/models/issue.rb
app/models/journal.rb
test/unit/issue_test.rb
test/unit/journal_test.rb

index 4edf4fa1b814fd0b00beee2eab6cba81a3a8ea68..88c808321aed7075f99a1c4bcade5d58adcb87eb 100644 (file)
@@ -2025,8 +2025,8 @@ class Issue < ActiveRecord::Base
   end
 
   def add_auto_watcher
-    if author &&
-        author.allowed_to?(:add_issue_watchers, project) &&
+    if author&.active? &&
+        author&.allowed_to?(:add_issue_watchers, project) &&
         author.pref.auto_watch_on?('issue_created') &&
         self.watcher_user_ids.exclude?(author.id)
       self.set_watcher(author, true)
index 24c02dfbd390b9a2183cca176eec59af4f570914..4b4139a149c7ea870aa46bc015acfe8d3db7d85f 100644 (file)
@@ -336,8 +336,8 @@ class Journal < ActiveRecord::Base
   end
 
   def add_watcher
-    if user &&
-        user.allowed_to?(:add_issue_watchers, project) &&
+    if user&.active? &&
+        user&.allowed_to?(:add_issue_watchers, project) &&
         user.pref.auto_watch_on?('issue_contributed_to') &&
         !Watcher.any_watched?(Array.wrap(journalized), user)
       journalized.set_watcher(user, true)
index 5795d2bb1af262e8b781dadabf2b88e106e4a3cc..08bc50df86fd47ef4dea7d8407b29263be2ccc8a 100644 (file)
@@ -3479,6 +3479,21 @@ class IssueTest < ActiveSupport::TestCase
     end
   end
 
+  def test_create_should_not_add_anonymous_as_watcher
+    Role.anonymous.add_permission!(:add_issue_watchers)
+
+    user = User.anonymous
+    assert user.pref.auto_watch_on?('issue_contributed_to')
+
+    journal = Journal.new(:journalized => Issue.first, :notes => 'notes', :user => user)
+
+    assert_no_difference 'Watcher.count' do
+      assert journal.save
+      assert journal.valid?
+      assert journal.journalized.valid?
+    end
+  end
+
   def test_like_should_escape_query
     issue = Issue.generate!(:subject => "asdf")
     r = Issue.like('as_f')
index 511b1641537e7f871913e2424bbbe5e7bb3f4b50..373de93a2156479fda12b2cb484abf35f77ab7b1 100644 (file)
@@ -142,6 +142,21 @@ class JournalTest < ActiveSupport::TestCase
     end
   end
 
+  def test_create_should_not_add_anonymous_as_watcher
+    Role.anonymous.add_permission!(:add_issue_watchers)
+
+    user = User.anonymous
+    assert user.pref.auto_watch_on?('issue_contributed_to')
+
+    journal = Journal.new(:journalized => Issue.first, :notes => 'notes', :user => user)
+
+    assert_no_difference 'Watcher.count' do
+      assert journal.save
+      assert journal.valid?
+      assert journal.journalized.valid?
+    end
+  end
+
   def test_visible_scope_for_anonymous
     # Anonymous user should see issues of public projects only
     journals = Journal.visible(User.anonymous).to_a