]> source.dussan.org Git - redmine.git/commitdiff
Merged r3357 from trunk.
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Sun, 7 Feb 2010 11:45:31 +0000 (11:45 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Sun, 7 Feb 2010 11:45:31 +0000 (11:45 +0000)
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/branches/0.9-stable@3380 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/controllers/issues_controller.rb
app/models/changeset.rb
app/views/issues/show.rhtml
test/unit/changeset_test.rb

index d2e7b5aaa401c41673e97f9f083dc99dc5ac0c68..06692cdec6b3c85269ad1e840e3b71cf26ef1a75 100644 (file)
@@ -106,7 +106,7 @@ class IssuesController < ApplicationController
     @journals = @issue.journals.find(:all, :include => [:user, :details], :order => "#{Journal.table_name}.created_on ASC")
     @journals.each_with_index {|j,i| j.indice = i+1}
     @journals.reverse! if User.current.wants_comments_in_reverse_order?
-    @changesets = @issue.changesets
+    @changesets = @issue.changesets.visible.all
     @changesets.reverse! if User.current.wants_comments_in_reverse_order?
     @allowed_statuses = @issue.new_statuses_allowed_to(User.current)
     @edit_allowed = User.current.allowed_to?(:edit_issues, @project)
index 336632afd3fe460902df773e10a7fd0642e9ce8a..f7145631e0ee625d78533fd5bc080ff77fd91e93 100644 (file)
@@ -41,6 +41,9 @@ class Changeset < ActiveRecord::Base
   validates_uniqueness_of :revision, :scope => :repository_id
   validates_uniqueness_of :scmid, :scope => :repository_id, :allow_nil => true
   
+  named_scope :visible, lambda {|*args| { :include => {:repository => :project},
+                                          :conditions => Project.allowed_to_condition(args.first || User.current, :view_changesets) } }
+                                          
   def revision=(r)
     write_attribute :revision, (r.nil? ? nil : r.to_s)
   end
@@ -90,13 +93,13 @@ class Changeset < ActiveRecord::Base
       # find any issue ID in the comments
       target_issue_ids = []
       comments.scan(%r{([\s\(\[,-]|^)#(\d+)(?=[[:punct:]]|\s|<|$)}).each { |m| target_issue_ids << m[1] }
-      referenced_issues += repository.project.issues.find_all_by_id(target_issue_ids)
+      referenced_issues += find_referenced_issues_by_id(target_issue_ids)
     end
     
     comments.scan(Regexp.new("(#{kw_regexp})[\s:]+(([\s,;&]*#?\\d+)+)", Regexp::IGNORECASE)).each do |match|
       action = match[0]
       target_issue_ids = match[1].scan(/\d+/)
-      target_issues = repository.project.issues.find_all_by_id(target_issue_ids)
+      target_issues = find_referenced_issues_by_id(target_issue_ids)
       if fix_status && fix_keywords.include?(action.downcase)
         # update status of issues
         logger.debug "Issues fixed by changeset #{self.revision}: #{issue_ids.join(', ')}." if logger && logger.debug?
@@ -148,6 +151,14 @@ class Changeset < ActiveRecord::Base
   
   private
 
+  # Finds issues that can be referenced by the commit message
+  # i.e. issues that belong to the repository project, a subproject or a parent project
+  def find_referenced_issues_by_id(ids)
+    Issue.find_all_by_id(ids, :include => :project).select {|issue|
+      project == issue.project || project.is_ancestor_of?(issue.project) || project.is_descendant_of?(issue.project)
+    }
+  end
+  
   def split_comments
     comments =~ /\A(.+?)\r?\n(.*)$/m
     @short_comments = $1 || comments
index 90a9d963d8e68dea0cddf3c0a8d1d169a64744c6..6c83c44fb08c69dea7e46d5fa0d24fd46eb14b9b 100644 (file)
@@ -73,7 +73,7 @@
 
 </div>
 
-<% if @changesets.any? && User.current.allowed_to?(:view_changesets, @project) %>
+<% if @changesets.any? %>
 <div id="issue-changesets">
 <h3><%=l(:label_associated_revisions)%></h3>
 <%= render :partial => 'changesets', :locals => { :changesets => @changesets} %>
index 02736a9a0fe64bc631645de4b55be6439bbd78df..8d57c43abbd56c9d169e5f541b2e00bf27bc88a3 100644 (file)
@@ -74,6 +74,29 @@ class ChangesetTest < ActiveSupport::TestCase
 
     assert_equal [1,2,3], c.issue_ids.sort
   end
+  
+  def test_commit_referencing_a_subproject_issue
+    c = Changeset.new(:repository => Project.find(1).repository,
+                      :committed_on => Time.now,
+                      :comments => 'refs #5, a subproject issue')
+    c.scan_comment_for_issue_ids
+    
+    assert_equal [5], c.issue_ids.sort
+    assert c.issues.first.project != c.project
+  end
+
+  def test_commit_referencing_a_parent_project_issue
+    # repository of child project
+    r = Repository::Subversion.create!(:project => Project.find(3), :url => 'svn://localhost/test')
+      
+    c = Changeset.new(:repository => r,
+                      :committed_on => Time.now,
+                      :comments => 'refs #2, an issue of a parent project')
+    c.scan_comment_for_issue_ids
+    
+    assert_equal [2], c.issue_ids.sort
+    assert c.issues.first.project != c.project
+  end
 
   def test_previous
     changeset = Changeset.find_by_revision('3')