From 4fa35a38e90d9f031290aa4075ae3cb41e87114f Mon Sep 17 00:00:00 2001 From: Marius Balteanu Date: Thu, 16 Jun 2022 21:29:21 +0000 Subject: [PATCH] Merged r21637 and r21638 to 4.2-stable (#37171). git-svn-id: https://svn.redmine.org/redmine/branches/4.2-stable@21640 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/models/issue.rb | 10 ++++++++-- test/unit/issue_test.rb | 16 ++++++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/app/models/issue.rb b/app/models/issue.rb index b5e128678..718639bfe 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -750,14 +750,20 @@ class Issue < ActiveRecord::Base errors.add :start_date, :earlier_than_minimum_start_date, :date => format_date(soonest_start) end - if project && fixed_version - if !assignable_versions.include?(fixed_version) + if project && fixed_version_id + if fixed_version.nil? || assignable_versions.exclude?(fixed_version) errors.add :fixed_version_id, :inclusion elsif reopening? && fixed_version.closed? errors.add :base, I18n.t(:error_can_not_reopen_issue_on_closed_version) end end + if project && category_id + unless project.issue_category_ids.include?(category_id) + errors.add :category_id, :inclusion + end + end + # Checks that the issue can not be added/moved to a disabled tracker if project && (tracker_id_changed? || project_id_changed?) if tracker && !project.trackers.include?(tracker) diff --git a/test/unit/issue_test.rb b/test/unit/issue_test.rb index 34e0162cf..af736e1a3 100644 --- a/test/unit/issue_test.rb +++ b/test/unit/issue_test.rb @@ -1650,6 +1650,14 @@ class IssueTest < ActiveSupport::TestCase assert_equal ['open'], issue.assignable_versions.collect(&:status).uniq end + def test_should_not_be_able_to_set_an_invalid_version_id + issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 1, + :status_id => 1, :fixed_version_id => 424242, + :subject => 'New issue') + assert !issue.save + assert_not_equal [], issue.errors[:fixed_version_id] + end + def test_should_not_be_able_to_assign_a_new_issue_to_a_closed_version issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 1, :status_id => 1, :fixed_version_id => 1, @@ -1721,6 +1729,14 @@ class IssueTest < ActiveSupport::TestCase assert issue.save end + def test_should_not_be_able_to_set_an_invalid_category_id + issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 1, + :status_id => 1, :category_id => 3, + :subject => 'New issue') + assert !issue.save + assert_not_equal [], issue.errors[:category_id] + end + def test_allowed_target_projects_should_include_projects_with_issue_tracking_enabled assert_include Project.find(2), Issue.allowed_target_projects(User.find(2)) end -- 2.39.5