@@ -45,6 +45,7 class IssueRelationsController < ApplicationController | |||||
45 | if params[:relation] && m = params[:relation][:issue_to_id].to_s.strip.match(/^#?(\d+)$/) |
|
45 | if params[:relation] && m = params[:relation][:issue_to_id].to_s.strip.match(/^#?(\d+)$/) | |
46 | @relation.issue_to = Issue.visible.find_by_id(m[1].to_i) |
|
46 | @relation.issue_to = Issue.visible.find_by_id(m[1].to_i) | |
47 | end |
|
47 | end | |
|
48 | @relation.init_journals(User.current) | |||
48 | saved = @relation.save |
|
49 | saved = @relation.save | |
49 |
|
50 | |||
50 | respond_to do |format| |
|
51 | respond_to do |format| | |
@@ -64,6 +65,7 class IssueRelationsController < ApplicationController | |||||
64 |
|
65 | |||
65 | def destroy |
|
66 | def destroy | |
66 | raise Unauthorized unless @relation.deletable? |
|
67 | raise Unauthorized unless @relation.deletable? | |
|
68 | @relation.init_journals(User.current) | |||
67 | @relation.destroy |
|
69 | @relation.destroy | |
68 |
|
70 | |||
69 | respond_to do |format| |
|
71 | respond_to do |format| |
@@ -406,6 +406,7 class IssuesController < ApplicationController | |||||
406 | def build_new_issue_from_params |
|
406 | def build_new_issue_from_params | |
407 | if params[:id].blank? |
|
407 | if params[:id].blank? | |
408 | @issue = Issue.new |
|
408 | @issue = Issue.new | |
|
409 | @issue.init_journal(User.current) | |||
409 | if params[:copy_from] |
|
410 | if params[:copy_from] | |
410 | begin |
|
411 | begin | |
411 | @copy_from = Issue.visible.find(params[:copy_from]) |
|
412 | @copy_from = Issue.visible.find(params[:copy_from]) |
@@ -667,6 +667,11 class Issue < ActiveRecord::Base | |||||
667 | @current_journal |
|
667 | @current_journal | |
668 | end |
|
668 | end | |
669 |
|
669 | |||
|
670 | # Returns the current journal or nil if it's not initialized | |||
|
671 | def current_journal | |||
|
672 | @current_journal | |||
|
673 | end | |||
|
674 | ||||
670 | # Returns the id of the last journal or nil |
|
675 | # Returns the id of the last journal or nil | |
671 | def last_journal_id |
|
676 | def last_journal_id | |
672 | if new_record? |
|
677 | if new_record? | |
@@ -1308,6 +1313,9 class Issue < ActiveRecord::Base | |||||
1308 | return unless copy? && !@after_create_from_copy_handled |
|
1313 | return unless copy? && !@after_create_from_copy_handled | |
1309 |
|
1314 | |||
1310 | if (@copied_from.project_id == project_id || Setting.cross_project_issue_relations?) && @copy_options[:link] != false |
|
1315 | if (@copied_from.project_id == project_id || Setting.cross_project_issue_relations?) && @copy_options[:link] != false | |
|
1316 | if @current_journal | |||
|
1317 | @copied_from.init_journal(@current_journal.user) | |||
|
1318 | end | |||
1311 | relation = IssueRelation.new(:issue_from => @copied_from, :issue_to => self, :relation_type => IssueRelation::TYPE_COPIED_TO) |
|
1319 | relation = IssueRelation.new(:issue_from => @copied_from, :issue_to => self, :relation_type => IssueRelation::TYPE_COPIED_TO) | |
1312 | unless relation.save |
|
1320 | unless relation.save | |
1313 | logger.error "Could not create relation while copying ##{@copied_from.id} to ##{id} due to validation errors: #{relation.errors.full_messages.join(', ')}" if logger |
|
1321 | logger.error "Could not create relation while copying ##{@copied_from.id} to ##{id} due to validation errors: #{relation.errors.full_messages.join(', ')}" if logger | |
@@ -1328,6 +1336,9 class Issue < ActiveRecord::Base | |||||
1328 | next |
|
1336 | next | |
1329 | end |
|
1337 | end | |
1330 | copy = Issue.new.copy_from(child, copy_options) |
|
1338 | copy = Issue.new.copy_from(child, copy_options) | |
|
1339 | if @current_journal | |||
|
1340 | copy.init_journal(@current_journal.user) | |||
|
1341 | end | |||
1331 | copy.author = author |
|
1342 | copy.author = author | |
1332 | copy.project = project |
|
1343 | copy.project = project | |
1333 | copy.parent_issue_id = copied_issue_ids[child.parent_id] |
|
1344 | copy.parent_issue_id = copied_issue_ids[child.parent_id] | |
@@ -1477,6 +1488,30 class Issue < ActiveRecord::Base | |||||
1477 | end |
|
1488 | end | |
1478 | end |
|
1489 | end | |
1479 |
|
1490 | |||
|
1491 | # Called after a relation is added | |||
|
1492 | def relation_added(relation) | |||
|
1493 | if @current_journal | |||
|
1494 | @current_journal.details << JournalDetail.new( | |||
|
1495 | :property => 'relation', | |||
|
1496 | :prop_key => relation.relation_type_for(self), | |||
|
1497 | :value => relation.other_issue(self).try(:id) | |||
|
1498 | ) | |||
|
1499 | @current_journal.save | |||
|
1500 | end | |||
|
1501 | end | |||
|
1502 | ||||
|
1503 | # Called after a relation is removed | |||
|
1504 | def relation_removed(relation) | |||
|
1505 | if @current_journal | |||
|
1506 | @current_journal.details << JournalDetail.new( | |||
|
1507 | :property => 'relation', | |||
|
1508 | :prop_key => relation.relation_type_for(self), | |||
|
1509 | :old_value => relation.other_issue(self).try(:id) | |||
|
1510 | ) | |||
|
1511 | @current_journal.save | |||
|
1512 | end | |||
|
1513 | end | |||
|
1514 | ||||
1480 | # Default assignment based on category |
|
1515 | # Default assignment based on category | |
1481 | def default_assign |
|
1516 | def default_assign | |
1482 | if assigned_to.nil? && category && category.assigned_to |
|
1517 | if assigned_to.nil? && category && category.assigned_to |
@@ -72,8 +72,8 class IssueRelation < ActiveRecord::Base | |||||
72 |
|
72 | |||
73 | attr_protected :issue_from_id, :issue_to_id |
|
73 | attr_protected :issue_from_id, :issue_to_id | |
74 | before_save :handle_issue_order |
|
74 | before_save :handle_issue_order | |
75 | after_create :create_journal_after_create |
|
75 | after_create :call_issues_relation_added_callback | |
76 | after_destroy :create_journal_after_delete |
|
76 | after_destroy :call_issues_relation_removed_callback | |
77 |
|
77 | |||
78 | def visible?(user=User.current) |
|
78 | def visible?(user=User.current) | |
79 | (issue_from.nil? || issue_from.visible?(user)) && (issue_to.nil? || issue_to.visible?(user)) |
|
79 | (issue_from.nil? || issue_from.visible?(user)) && (issue_to.nil? || issue_to.visible?(user)) | |
@@ -168,6 +168,11 class IssueRelation < ActiveRecord::Base | |||||
168 | r == 0 ? id <=> relation.id : r |
|
168 | r == 0 ? id <=> relation.id : r | |
169 | end |
|
169 | end | |
170 |
|
170 | |||
|
171 | def init_journals(user) | |||
|
172 | issue_from.init_journal(user) if issue_from | |||
|
173 | issue_to.init_journal(user) if issue_to | |||
|
174 | end | |||
|
175 | ||||
171 | private |
|
176 | private | |
172 |
|
177 | |||
173 | # Reverses the relation if needed so that it gets stored in the proper way |
|
178 | # Reverses the relation if needed so that it gets stored in the proper way | |
@@ -182,29 +187,19 class IssueRelation < ActiveRecord::Base | |||||
182 | end |
|
187 | end | |
183 | end |
|
188 | end | |
184 |
|
189 | |||
185 | def create_journal_after_create |
|
190 | def call_issues_relation_added_callback | |
186 | journal = issue_from.init_journal(User.current) |
|
191 | call_issues_callback :relation_added | |
187 | journal.details << JournalDetail.new(:property => 'relation', |
|
192 | end | |
188 | :prop_key => relation_type_for(issue_from), |
|
193 | ||
189 | :value => issue_to.id) |
|
194 | def call_issues_relation_removed_callback | |
190 | journal.save |
|
195 | call_issues_callback :relation_removed | |
191 | journal = issue_to.init_journal(User.current) |
|
196 | end | |
192 | journal.details << JournalDetail.new(:property => 'relation', |
|
197 | ||
193 | :prop_key => relation_type_for(issue_to), |
|
198 | def call_issues_callback(name) | |
194 | :value => issue_from.id) |
|
199 | [issue_from, issue_to].each do |issue| | |
195 | journal.save |
|
200 | if issue | |
196 | end |
|
201 | issue.send name, self | |
197 |
|
202 | end | ||
198 | def create_journal_after_delete |
|
203 | end | |
199 | journal = issue_from.init_journal(User.current) |
|
|||
200 | journal.details << JournalDetail.new(:property => 'relation', |
|
|||
201 | :prop_key => relation_type_for(issue_from), |
|
|||
202 | :old_value => issue_to.id) |
|
|||
203 | journal.save |
|
|||
204 | journal = issue_to.init_journal(User.current) |
|
|||
205 | journal.details << JournalDetail.new(:property => 'relation', |
|
|||
206 | :prop_key => relation_type_for(issue_to), |
|
|||
207 | :old_value => issue_from.id) |
|
|||
208 | journal.save |
|
|||
209 | end |
|
204 | end | |
210 | end |
|
205 | end |
@@ -169,13 +169,14 class IssueRelationTest < ActiveSupport::TestCase | |||||
169 | assert_not_equal [], r.errors[:base] |
|
169 | assert_not_equal [], r.errors[:base] | |
170 | end |
|
170 | end | |
171 |
|
171 | |||
172 |
def test_create_should_ |
|
172 | def test_create_with_initialized_journals_should_create_journals | |
173 | from = Issue.find(1) |
|
173 | from = Issue.find(1) | |
174 | to = Issue.find(2) |
|
174 | to = Issue.find(2) | |
175 | from_journals = from.journals.size |
|
175 | from_journals = from.journals.size | |
176 | to_journals = to.journals.size |
|
176 | to_journals = to.journals.size | |
177 | relation = IssueRelation.new(:issue_from => from, :issue_to => to, |
|
177 | relation = IssueRelation.new(:issue_from => from, :issue_to => to, | |
178 | :relation_type => IssueRelation::TYPE_PRECEDES) |
|
178 | :relation_type => IssueRelation::TYPE_PRECEDES) | |
|
179 | relation.init_journals User.find(1) | |||
179 | assert relation.save |
|
180 | assert relation.save | |
180 | from.reload |
|
181 | from.reload | |
181 | to.reload |
|
182 | to.reload | |
@@ -192,12 +193,13 class IssueRelationTest < ActiveSupport::TestCase | |||||
192 | assert_nil to.journals.last.details.last.old_value |
|
193 | assert_nil to.journals.last.details.last.old_value | |
193 | end |
|
194 | end | |
194 |
|
195 | |||
195 |
def test_de |
|
196 | def test_destroy_with_initialized_journals_should_create_journals | |
196 | relation = IssueRelation.find(1) |
|
197 | relation = IssueRelation.find(1) | |
197 | from = relation.issue_from |
|
198 | from = relation.issue_from | |
198 | to = relation.issue_to |
|
199 | to = relation.issue_to | |
199 | from_journals = from.journals.size |
|
200 | from_journals = from.journals.size | |
200 | to_journals = to.journals.size |
|
201 | to_journals = to.journals.size | |
|
202 | relation.init_journals User.find(1) | |||
201 | assert relation.destroy |
|
203 | assert relation.destroy | |
202 | from.reload |
|
204 | from.reload | |
203 | to.reload |
|
205 | to.reload |
@@ -207,17 +207,15 class JournalTest < ActiveSupport::TestCase | |||||
207 | def test_visible_details_should_include_relations_to_visible_issues_only |
|
207 | def test_visible_details_should_include_relations_to_visible_issues_only | |
208 | issue = Issue.generate! |
|
208 | issue = Issue.generate! | |
209 | visible_issue = Issue.generate! |
|
209 | visible_issue = Issue.generate! | |
210 | IssueRelation.create!(:issue_from => issue, :issue_to => visible_issue, :relation_type => 'relates') |
|
|||
211 | hidden_issue = Issue.generate!(:is_private => true) |
|
210 | hidden_issue = Issue.generate!(:is_private => true) | |
212 | IssueRelation.create!(:issue_from => issue, :issue_to => hidden_issue, :relation_type => 'relates') |
|
211 | ||
213 | issue.reload |
|
212 | journal = Journal.new | |
214 | assert_equal 1, issue.journals.size |
|
213 | journal.details << JournalDetail.new(:property => 'relation', :prop_key => 'relates', :value => visible_issue.id) | |
215 | journal = issue.journals.first |
|
214 | journal.details << JournalDetail.new(:property => 'relation', :prop_key => 'relates', :value => hidden_issue.id) | |
216 | assert_equal 2, journal.details.size |
|
|||
217 |
|
215 | |||
218 | visible_details = journal.visible_details(User.anonymous) |
|
216 | visible_details = journal.visible_details(User.anonymous) | |
219 | assert_equal 1, visible_details.size |
|
217 | assert_equal 1, visible_details.size | |
220 | assert_equal visible_issue.id.to_s, visible_details.first.value |
|
218 | assert_equal visible_issue.id.to_s, visible_details.first.value.to_s | |
221 |
|
219 | |||
222 | visible_details = journal.visible_details(User.find(2)) |
|
220 | visible_details = journal.visible_details(User.find(2)) | |
223 | assert_equal 2, visible_details.size |
|
221 | assert_equal 2, visible_details.size |
@@ -410,6 +410,7 class MailerTest < ActiveSupport::TestCase | |||||
410 |
|
410 | |||
411 | def test_issue_edit_with_relation_should_notify_users_who_can_see_the_related_issue |
|
411 | def test_issue_edit_with_relation_should_notify_users_who_can_see_the_related_issue | |
412 | issue = Issue.generate! |
|
412 | issue = Issue.generate! | |
|
413 | issue.init_journal(User.find(1)) | |||
413 | private_issue = Issue.generate!(:is_private => true) |
|
414 | private_issue = Issue.generate!(:is_private => true) | |
414 | IssueRelation.create!(:issue_from => issue, :issue_to => private_issue, :relation_type => 'relates') |
|
415 | IssueRelation.create!(:issue_from => issue, :issue_to => private_issue, :relation_type => 'relates') | |
415 | issue.reload |
|
416 | issue.reload |
General Comments 0
You need to be logged in to leave comments.
Login now