]> source.dussan.org Git - redmine.git/commitdiff
Fix: Copying an issue fails if the issue is watched by a locked user (#28765).
authorGo MAEDA <maeda@farend.jp>
Sat, 19 May 2018 00:44:10 +0000 (00:44 +0000)
committerGo MAEDA <maeda@farend.jp>
Sat, 19 May 2018 00:44:10 +0000 (00:44 +0000)
Patch by Marius BALTEANU.

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

app/helpers/issues_helper.rb
app/models/issue.rb
test/functional/issues_controller_test.rb
test/unit/issue_test.rb

index 1c2fd1b5d4398d00ce65304bc1109751a503b914..d1fb28961c6844dd74b2236827e1c86d80f812bf 100644 (file)
@@ -312,7 +312,7 @@ module IssuesHelper
   # Returns an array of users that are proposed as watchers
   # on the new issue form
   def users_for_new_issue_watchers(issue)
-    users = issue.watcher_users
+    users = issue.watcher_users.select{|u| u.status == User::STATUS_ACTIVE}
     if issue.project.users.count <= 20
       users = (users + issue.project.users.sort).uniq
     end
index 8583d43e53453f13996f37d1ca8506e39aec5865..9b55c2a74072aa11e8d7f3e631860fb8a946a942 100644 (file)
@@ -274,7 +274,8 @@ class Issue < ActiveRecord::Base
       end
     end
     unless options[:watchers] == false
-      self.watcher_user_ids = issue.watcher_user_ids.dup
+      self.watcher_user_ids =
+        issue.watcher_users.select{|u| u.status == User::STATUS_ACTIVE}.map(&:id)
     end
     @copied_from = issue
     @copy_options = options
index fc5b035766da850a726452eb57d8a61d69d812d2..99336f682c46b2f88dd865abec83d4cdfa25e438 100644 (file)
@@ -3916,6 +3916,29 @@ class IssuesControllerTest < Redmine::ControllerTest
     assert_select 'input[type=hidden][name=?][value=?]', 'issue[watcher_user_ids][]', '', 1
   end
 
+  def test_new_as_copy_should_not_propose_locked_watchers
+    @request.session[:user_id] = 2
+
+    issue = Issue.find(1)
+    user = User.generate!
+    user2 = User.generate!
+
+    Watcher.create!(:watchable => issue, :user => user)
+    Watcher.create!(:watchable => issue, :user => user2)
+
+    user2.status = User::STATUS_LOCKED
+    user2.save!
+    get :new, :params => {
+        :project_id => 1,
+        :copy_from => 1
+      }
+
+    assert_select 'input[type=checkbox][name=?][checked=checked]', 'issue[watcher_user_ids][]', 1
+    assert_select 'input[type=checkbox][name=?][checked=checked][value=?]', 'issue[watcher_user_ids][]', user.id.to_s
+    assert_select 'input[type=checkbox][name=?][checked=checked][value=?]', 'issue[watcher_user_ids][]', user2.id.to_s, 0
+    assert_select 'input[type=hidden][name=?][value=?]', 'issue[watcher_user_ids][]', '', 1
+  end
+
   def test_new_as_copy_with_invalid_issue_should_respond_with_404
     @request.session[:user_id] = 2
     get :new, :params => {
index 880c0a6067a597be4ce54730717641f9e9e2ebfb..48a12c6e425470eab5ec8b4302c0a656b8fd2080 100644 (file)
@@ -1375,6 +1375,24 @@ class IssueTest < ActiveSupport::TestCase
     assert_not_nil copied_closed.closed_on
   end
 
+  def test_copy_should_not_copy_locked_watchers
+    user = User.find(2)
+    user2 = User.find(3)
+    issue = Issue.find(8)
+
+    Watcher.create!(:user => user, :watchable => issue)
+    Watcher.create!(:user => user2, :watchable => issue)
+
+    user2.status = User::STATUS_LOCKED
+    user2.save!
+
+    issue = Issue.new.copy_from(8)
+
+    assert issue.save
+    assert issue.watched_by?(user)
+    assert !issue.watched_by?(user2)
+  end
+
   def test_should_not_call_after_project_change_on_creation
     issue = Issue.new(:project_id => 1, :tracker_id => 1, :status_id => 1,
                       :subject => 'Test', :author_id => 1)