Commit d43c8604 authored by Jean-Philippe Lang's avatar Jean-Philippe Lang

Allow commits to reference issues of parent projects and subprojects (#4674).

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@3357 e93f8b46-1217-0410-a6f0-8f06a7374b81
parent df46d704
......@@ -108,7 +108,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)
......
......@@ -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
......
......@@ -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} %>
......
......@@ -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')
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment