]> source.dussan.org Git - redmine.git/commitdiff
Updating an issue via REST API causes internal server error if invalid project id...
authorGo MAEDA <maeda@farend.jp>
Thu, 14 May 2020 14:33:07 +0000 (14:33 +0000)
committerGo MAEDA <maeda@farend.jp>
Thu, 14 May 2020 14:33:07 +0000 (14:33 +0000)
Patch by Go MAEDA.

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

app/models/issue.rb
test/integration/api_test/issues_test.rb

index 487b1b552df456de5a7201299d67feacf44ccb61..e665a46cb051fc53a17e6b6afe5290a748db5147 100644 (file)
@@ -723,7 +723,7 @@ class Issue < ActiveRecord::Base
       errors.add :start_date, :earlier_than_minimum_start_date, :date => format_date(soonest_start)
     end
 
-    if fixed_version
+    if project && fixed_version
       if !assignable_versions.include?(fixed_version)
         errors.add :fixed_version_id, :inclusion
       elsif reopening? && fixed_version.closed?
@@ -738,7 +738,7 @@ class Issue < ActiveRecord::Base
       end
     end
 
-    if assigned_to_id_changed? && assigned_to_id.present?
+    if project && assigned_to_id_changed? && assigned_to_id.present?
       unless assignable_users.include?(assigned_to)
         errors.add :assigned_to_id, :invalid
       end
@@ -938,6 +938,8 @@ class Issue < ActiveRecord::Base
 
   # Users the issue can be assigned to
   def assignable_users
+    return [] if project.nil?
+
     users = project.assignable_users(tracker).to_a
     users << author if author && author.active?
     if assigned_to_id_was.present? && assignee = Principal.find_by_id(assigned_to_id_was)
@@ -949,6 +951,7 @@ class Issue < ActiveRecord::Base
   # Versions that the issue can be assigned to
   def assignable_versions
     return @assignable_versions if @assignable_versions
+    return [] if project.nil?
 
     versions = project.shared_versions.open.to_a
     if fixed_version
index fffbc4f7b8de11164fc8198f0046aaa6161586d9..d040728f91cd8270a434fcb91883e978f65a1db4 100644 (file)
@@ -663,6 +663,34 @@ class Redmine::ApiTest::IssuesTest < Redmine::ApiTest::Base
     assert_response 422
   end
 
+  test "POST /issues.json with invalid project_id and any assigned_to_id should respond with 422" do
+    post(
+      '/issues.json',
+      :params => {
+        :issue => {
+          :project_id => 999,
+          :assigned_to_id => 1,
+          :subject => 'API'
+        }
+      },
+      :headers => credentials('jsmith'))
+    assert_response 422
+  end
+
+  test "POST /issues.json with invalid project_id and any fixed_version_id should respond with 422" do
+    post(
+      '/issues.json',
+      :params => {
+        :issue => {
+          :project_id => 999,
+          :fixed_version_id => 1,
+          :subject => 'API'
+        }
+      },
+      :headers => credentials('jsmith'))
+    assert_response 422
+  end
+
   test "PUT /issues/:id.xml" do
     assert_difference('Journal.count') do
       put(