@@ -43,26 +43,34 class IssueRelation < ActiveRecord::Base | |||||
43 | TYPE_COPIED_TO = "copied_to" |
|
43 | TYPE_COPIED_TO = "copied_to" | |
44 | TYPE_COPIED_FROM = "copied_from" |
|
44 | TYPE_COPIED_FROM = "copied_from" | |
45 |
|
45 | |||
46 | TYPES = { TYPE_RELATES => { :name => :label_relates_to, :sym_name => :label_relates_to, :order => 1, :sym => TYPE_RELATES }, |
|
46 | TYPES = { | |
47 |
|
|
47 | TYPE_RELATES => { :name => :label_relates_to, :sym_name => :label_relates_to, | |
48 | TYPE_DUPLICATED => { :name => :label_duplicated_by, :sym_name => :label_duplicates, :order => 3, :sym => TYPE_DUPLICATES, :reverse => TYPE_DUPLICATES }, |
|
48 | :order => 1, :sym => TYPE_RELATES }, | |
49 |
|
|
49 | TYPE_DUPLICATES => { :name => :label_duplicates, :sym_name => :label_duplicated_by, | |
50 | TYPE_BLOCKED => { :name => :label_blocked_by, :sym_name => :label_blocks, :order => 5, :sym => TYPE_BLOCKS, :reverse => TYPE_BLOCKS }, |
|
50 | :order => 2, :sym => TYPE_DUPLICATED }, | |
51 |
|
|
51 | TYPE_DUPLICATED => { :name => :label_duplicated_by, :sym_name => :label_duplicates, | |
52 |
|
|
52 | :order => 3, :sym => TYPE_DUPLICATES, :reverse => TYPE_DUPLICATES }, | |
53 | TYPE_COPIED_TO => { :name => :label_copied_to, :sym_name => :label_copied_from, :order => 8, :sym => TYPE_COPIED_FROM }, |
|
53 | TYPE_BLOCKS => { :name => :label_blocks, :sym_name => :label_blocked_by, | |
54 | TYPE_COPIED_FROM => { :name => :label_copied_from, :sym_name => :label_copied_to, :order => 9, :sym => TYPE_COPIED_TO, :reverse => TYPE_COPIED_TO } |
|
54 | :order => 4, :sym => TYPE_BLOCKED }, | |
55 | }.freeze |
|
55 | TYPE_BLOCKED => { :name => :label_blocked_by, :sym_name => :label_blocks, | |
|
56 | :order => 5, :sym => TYPE_BLOCKS, :reverse => TYPE_BLOCKS }, | |||
|
57 | TYPE_PRECEDES => { :name => :label_precedes, :sym_name => :label_follows, | |||
|
58 | :order => 6, :sym => TYPE_FOLLOWS }, | |||
|
59 | TYPE_FOLLOWS => { :name => :label_follows, :sym_name => :label_precedes, | |||
|
60 | :order => 7, :sym => TYPE_PRECEDES, :reverse => TYPE_PRECEDES }, | |||
|
61 | TYPE_COPIED_TO => { :name => :label_copied_to, :sym_name => :label_copied_from, | |||
|
62 | :order => 8, :sym => TYPE_COPIED_FROM }, | |||
|
63 | TYPE_COPIED_FROM => { :name => :label_copied_from, :sym_name => :label_copied_to, | |||
|
64 | :order => 9, :sym => TYPE_COPIED_TO, :reverse => TYPE_COPIED_TO } | |||
|
65 | }.freeze | |||
56 |
|
66 | |||
57 | validates_presence_of :issue_from, :issue_to, :relation_type |
|
67 | validates_presence_of :issue_from, :issue_to, :relation_type | |
58 | validates_inclusion_of :relation_type, :in => TYPES.keys |
|
68 | validates_inclusion_of :relation_type, :in => TYPES.keys | |
59 | validates_numericality_of :delay, :allow_nil => true |
|
69 | validates_numericality_of :delay, :allow_nil => true | |
60 | validates_uniqueness_of :issue_to_id, :scope => :issue_from_id |
|
70 | validates_uniqueness_of :issue_to_id, :scope => :issue_from_id | |
61 |
|
||||
62 | validate :validate_issue_relation |
|
71 | validate :validate_issue_relation | |
63 |
|
72 | |||
64 | attr_protected :issue_from_id, :issue_to_id |
|
73 | attr_protected :issue_from_id, :issue_to_id | |
65 |
|
||||
66 | before_save :handle_issue_order |
|
74 | before_save :handle_issue_order | |
67 |
|
75 | |||
68 | def visible?(user=User.current) |
|
76 | def visible?(user=User.current) | |
@@ -87,14 +95,19 class IssueRelation < ActiveRecord::Base | |||||
87 | def validate_issue_relation |
|
95 | def validate_issue_relation | |
88 | if issue_from && issue_to |
|
96 | if issue_from && issue_to | |
89 | errors.add :issue_to_id, :invalid if issue_from_id == issue_to_id |
|
97 | errors.add :issue_to_id, :invalid if issue_from_id == issue_to_id | |
90 | errors.add :issue_to_id, :not_same_project unless issue_from.project_id == issue_to.project_id || Setting.cross_project_issue_relations? |
|
98 | unless issue_from.project_id == issue_to.project_id || | |
91 | #detect circular dependencies depending wether the relation should be reversed |
|
99 | Setting.cross_project_issue_relations? | |
|
100 | errors.add :issue_to_id, :not_same_project | |||
|
101 | end | |||
|
102 | # detect circular dependencies depending wether the relation should be reversed | |||
92 | if TYPES.has_key?(relation_type) && TYPES[relation_type][:reverse] |
|
103 | if TYPES.has_key?(relation_type) && TYPES[relation_type][:reverse] | |
93 | errors.add :base, :circular_dependency if issue_from.all_dependent_issues.include? issue_to |
|
104 | errors.add :base, :circular_dependency if issue_from.all_dependent_issues.include? issue_to | |
94 | else |
|
105 | else | |
95 | errors.add :base, :circular_dependency if issue_to.all_dependent_issues.include? issue_from |
|
106 | errors.add :base, :circular_dependency if issue_to.all_dependent_issues.include? issue_from | |
96 | end |
|
107 | end | |
97 |
|
|
108 | if issue_from.is_descendant_of?(issue_to) || issue_from.is_ancestor_of?(issue_to) | |
|
109 | errors.add :base, :cant_link_an_issue_with_a_descendant | |||
|
110 | end | |||
98 | end |
|
111 | end | |
99 | end |
|
112 | end | |
100 |
|
113 | |||
@@ -114,7 +127,9 class IssueRelation < ActiveRecord::Base | |||||
114 | end |
|
127 | end | |
115 |
|
128 | |||
116 | def label_for(issue) |
|
129 | def label_for(issue) | |
117 | TYPES[relation_type] ? TYPES[relation_type][(self.issue_from_id == issue.id) ? :name : :sym_name] : :unknow |
|
130 | TYPES[relation_type] ? | |
|
131 | TYPES[relation_type][(self.issue_from_id == issue.id) ? :name : :sym_name] : | |||
|
132 | :unknow | |||
118 | end |
|
133 | end | |
119 |
|
134 | |||
120 | def css_classes_for(issue) |
|
135 | def css_classes_for(issue) | |
@@ -140,7 +155,8 class IssueRelation < ActiveRecord::Base | |||||
140 | end |
|
155 | end | |
141 |
|
156 | |||
142 | def successor_soonest_start |
|
157 | def successor_soonest_start | |
143 |
if (TYPE_PRECEDES == self.relation_type) && delay && issue_from && |
|
158 | if (TYPE_PRECEDES == self.relation_type) && delay && issue_from && | |
|
159 | (issue_from.start_date || issue_from.due_date) | |||
144 | (issue_from.due_date || issue_from.start_date) + 1 + delay |
|
160 | (issue_from.due_date || issue_from.start_date) + 1 + delay | |
145 | end |
|
161 | end | |
146 | end |
|
162 | end |
General Comments 0
You need to be logged in to leave comments.
Login now