Project

General

Profile

Defect #34108 » fixed-34108-v2.patch

Yuichi HARADA, 2020-10-14 07:49

View differences:

app/models/issue.rb
1848 1848
  # Closes duplicates if the issue is being closed
1849 1849
  def close_duplicates
1850 1850
    if Setting.close_duplicate_issues? && closing?
1851
      # Check that there are no circular dependency of relationships
1852
      relations_to.where(:relation_type => IssueRelation::TYPE_DUPLICATES).each do |relation|
1853
        unless relation.valid?
1854
          errors.add :base, relation.errors.full_messages.first
1855
          throw :abort
1856
        end
1857
      end
1858

  
1851 1859
      duplicates.each do |duplicate|
1852 1860
        # Reload is needed in case the duplicate was updated by a previous duplicate
1853 1861
        duplicate.reload
app/models/issue_relation.rb
239 239
      issue_from.blocks? issue_to
240 240
    when 'blocks'
241 241
      issue_to.blocks? issue_from
242
    when 'duplicated'
243
      self.class.where(issue_from_id: issue_from, issue_to_id: issue_to, relation_type: TYPE_DUPLICATES).exists?
244
    when 'duplicates'
245
      self.class.where(issue_from_id: issue_to, issue_to_id: issue_from, relation_type: TYPE_DUPLICATES).exists?
242 246
    when 'relates'
243 247
      self.class.where(issue_from_id: issue_to, issue_to_id: issue_from).present?
244 248
    else
test/unit/issue_relation_test.rb
189 189
    assert_not_equal [], r.errors[:base]
190 190
  end
191 191

  
192
  def test_validates_circular_dependency_on_reverse_relations_using_duplicates
193
    with_locale 'en' do
194
      IssueRelation.delete_all
195
      issue1 = issues(:issues_001)
196
      issue2 = issues(:issues_002)
197
      assert IssueRelation.create!(
198
              :issue_from => issue1, :issue_to => issue2,
199
              :relation_type => IssueRelation::TYPE_DUPLICATES
200
            )
201
      r = IssueRelation.new(
202
            :issue_from => issue2, :issue_to => issue1,
203
            :relation_type => IssueRelation::TYPE_DUPLICATES
204
          )
205
      assert !r.save
206
      assert_include 'This relation would create a circular dependency', r.errors.full_messages
207
    end
208
  end
209

  
192 210
  def test_create_with_initialized_journals_should_create_journals
193 211
    from = Issue.find(1)
194 212
    to   = Issue.find(2)
test/unit/issue_test.rb
1605 1605
    assert !issue1.reload.closed?
1606 1606
  end
1607 1607

  
1608
  def test_should_not_close_duplicated_issue_with_circular_dependency
1609
    IssueRelation.delete_all
1610
    issue1 = issues(:issues_001)
1611
    issue2 = issues(:issues_002)
1612

  
1613
    IssueRelation.create(:issue_from => issue1, :issue_to => issue2,
1614
                         :relation_type => IssueRelation::TYPE_DUPLICATES).save!(:validate => false)
1615
    IssueRelation.create(:issue_from => issue2, :issue_to => issue1,
1616
                         :relation_type => IssueRelation::TYPE_DUPLICATES).save!(:validate => false)
1617

  
1618
    assert_equal 1, issue1.duplicates.count
1619
    assert_equal issue2, issue1.duplicates.first
1620
    assert_equal 1, issue2.duplicates.count
1621
    assert_equal issue1, issue2.duplicates.first
1622

  
1623
    issue1.init_journal(users(:users_002), "Closing issue")
1624
    issue1.status = IssueStatus.where(:is_closed => true).first
1625
    assert !issue1.save
1626
    assert_include 'This relation would create a circular dependency', issue1.errors.full_messages
1627
  end
1628

  
1608 1629
  def test_assignable_versions
1609 1630
    issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 1,
1610 1631
                      :status_id => 1, :fixed_version_id => 1,
(3-3/4)