summaryrefslogtreecommitdiffstats
path: root/app/models
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2010-01-31 16:25:06 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2010-01-31 16:25:06 +0000
commitd43c860448ce71ca3f35ac6487775deaa0dcb3c3 (patch)
tree70ae267c28cf00c3141774f20641caa074a6f353 /app/models
parentdf46d704e882823c30bc5cf0f2b88da8db98b47f (diff)
downloadredmine-d43c860448ce71ca3f35ac6487775deaa0dcb3c3.tar.gz
redmine-d43c860448ce71ca3f35ac6487775deaa0dcb3c3.zip
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
Diffstat (limited to 'app/models')
-rw-r--r--app/models/changeset.rb15
1 files changed, 13 insertions, 2 deletions
diff --git a/app/models/changeset.rb b/app/models/changeset.rb
index 336632afd..f7145631e 100644
--- a/app/models/changeset.rb
+++ b/app/models/changeset.rb
@@ -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