summaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2009-12-18 20:35:16 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2009-12-18 20:35:16 +0000
commitbeb20e7c6e906b1b5c892841c1948cb50df86e3e (patch)
tree0b9b9c2736951f5a5ea5c306f93c02d6132700e7 /app
parent111950108aca2f528ecb0ba00042d92d9b6a8c0d (diff)
downloadredmine-beb20e7c6e906b1b5c892841c1948cb50df86e3e.tar.gz
redmine-beb20e7c6e906b1b5c892841c1948cb50df86e3e.zip
Adds 'follows' relation (#1432).
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@3190 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app')
-rw-r--r--app/models/issue_relation.rb17
1 files changed, 16 insertions, 1 deletions
diff --git a/app/models/issue_relation.rb b/app/models/issue_relation.rb
index d26292c37..2728d77aa 100644
--- a/app/models/issue_relation.rb
+++ b/app/models/issue_relation.rb
@@ -23,20 +23,24 @@ class IssueRelation < ActiveRecord::Base
TYPE_DUPLICATES = "duplicates"
TYPE_BLOCKS = "blocks"
TYPE_PRECEDES = "precedes"
+ TYPE_FOLLOWS = "follows"
TYPES = { TYPE_RELATES => { :name => :label_relates_to, :sym_name => :label_relates_to, :order => 1 },
TYPE_DUPLICATES => { :name => :label_duplicates, :sym_name => :label_duplicated_by, :order => 2 },
TYPE_BLOCKS => { :name => :label_blocks, :sym_name => :label_blocked_by, :order => 3 },
TYPE_PRECEDES => { :name => :label_precedes, :sym_name => :label_follows, :order => 4 },
+ TYPE_FOLLOWS => { :name => :label_follows, :sym_name => :label_precedes, :order => 5 }
}.freeze
validates_presence_of :issue_from, :issue_to, :relation_type
- validates_inclusion_of :relation_type, :in => TYPES.keys
+ validates_inclusion_of :relation_type, :in => [TYPE_RELATES, TYPE_DUPLICATES, TYPE_BLOCKS, TYPE_PRECEDES]
validates_numericality_of :delay, :allow_nil => true
validates_uniqueness_of :issue_to_id, :scope => :issue_from_id
attr_protected :issue_from_id, :issue_to_id
+ before_validation :reverse_if_needed
+
def validate
if issue_from && issue_to
errors.add :issue_to_id, :invalid if issue_from_id == issue_to_id
@@ -78,4 +82,15 @@ class IssueRelation < ActiveRecord::Base
def <=>(relation)
TYPES[self.relation_type][:order] <=> TYPES[relation.relation_type][:order]
end
+
+ private
+
+ def reverse_if_needed
+ if (TYPE_FOLLOWS == relation_type)
+ issue_tmp = issue_to
+ self.issue_to = issue_from
+ self.issue_from = issue_tmp
+ self.relation_type = TYPE_PRECEDES
+ end
+ end
end