0001-Validate-category_id-against-available-categories-in.patch

Holger Just, 2022-05-30 18:54

Download (1.66 KB)

View differences:

app/models/issue.rb
759 759
      end
760 760
    end
761 761

  
762
    if project && category_id
763
      unless project.issue_category_ids.include?(category_id)
764
        errors.add :category_id, :inclusion
765
      end
766
    end
767

  
762 768
    # Checks that the issue can not be added/moved to a disabled tracker
763 769
    if project && (tracker_id_changed? || project_id_changed?)
764 770
      if tracker && !project.trackers.include?(tracker)
test/unit/issue_test.rb
1721 1721
    assert issue.save
1722 1722
  end
1723 1723

  
1724
  def test_should_not_be_able_to_set_an_invalid_category_id
1725
    issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 1,
1726
                      :status_id => 1, :category_id => 3,
1727
                      :subject => 'New issue')
1728
    assert !issue.save
1729
    assert_not_equal [], issue.errors[:category_id]
1730
  end
1731

  
1724 1732
  def test_allowed_target_projects_should_include_projects_with_issue_tracking_enabled
1725 1733
    assert_include Project.find(2), Issue.allowed_target_projects(User.find(2))
1726 1734
  end
1727
-