@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)
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
# 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?
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
</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} %>
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')