From 0532a1b436bca9e9b9923d56791820cfb58e40f7 Mon Sep 17 00:00:00 2001 From: Go MAEDA Date: Fri, 15 May 2020 23:16:50 +0000 Subject: [PATCH] Merged r19777 from trunk to 4.1-stable (#33417). git-svn-id: http://svn.redmine.org/redmine/branches/4.1-stable@19779 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/models/issue.rb | 7 ++++-- test/integration/api_test/issues_test.rb | 28 ++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/app/models/issue.rb b/app/models/issue.rb index efb55fafb..713acdfe2 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -722,7 +722,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? @@ -737,7 +737,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 @@ -937,6 +937,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) @@ -948,6 +950,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 diff --git a/test/integration/api_test/issues_test.rb b/test/integration/api_test/issues_test.rb index 59a062b3a..19b1a5c56 100644 --- a/test/integration/api_test/issues_test.rb +++ b/test/integration/api_test/issues_test.rb @@ -653,6 +653,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( -- 2.39.5