Preserve original author when moving issue
This also wrapps entire process into transation, as rewriting references may have large memory footprint.
This commit is contained in:
parent
4354bfaba5
commit
310b417b0f
2 changed files with 22 additions and 24 deletions
|
@ -4,7 +4,7 @@ module Issues
|
|||
super(project, current_user, params)
|
||||
|
||||
@issue_old = issue
|
||||
@issue_new = nil
|
||||
@issue_new = issue.dup
|
||||
@project_old = @project
|
||||
@project_new = Project.find(new_project_id) if new_project_id
|
||||
end
|
||||
|
@ -12,6 +12,7 @@ module Issues
|
|||
def execute
|
||||
return unless move?
|
||||
|
||||
ActiveRecord::Base.transaction do
|
||||
# New issue tasks
|
||||
#
|
||||
open_new_issue
|
||||
|
@ -22,6 +23,7 @@ module Issues
|
|||
#
|
||||
add_moved_to_note
|
||||
close_old_issue
|
||||
end
|
||||
|
||||
# Notifications
|
||||
#
|
||||
|
@ -42,16 +44,12 @@ module Issues
|
|||
end
|
||||
|
||||
def open_new_issue
|
||||
create_service = CreateService.new(@project_new, current_user, new_issue_params)
|
||||
@issue_new = create_service.execute
|
||||
end
|
||||
|
||||
def new_issue_params
|
||||
new_params = { id: nil, iid: nil, milestone_id: nil, label_ids: [],
|
||||
project_id: @project_new.id,
|
||||
description: rewrite_references(@issue_old) }
|
||||
|
||||
params.merge(new_params)
|
||||
@issue_new.iid = nil
|
||||
@issue_new.project = @project_new
|
||||
@issue_new.labels = []
|
||||
@issue_new.milestone = nil
|
||||
@issue_new.description = rewrite_references(@issue_old)
|
||||
@issue_new.save!
|
||||
end
|
||||
|
||||
def rewrite_notes
|
||||
|
|
|
@ -74,13 +74,13 @@ describe Issues::MoveService, services: true do
|
|||
expect(new_issue.persisted?).to be true
|
||||
end
|
||||
|
||||
it 'persist all changes' do
|
||||
it 'persists all changes' do
|
||||
expect(old_issue.changed?).to be false
|
||||
expect(new_issue.changed?).to be false
|
||||
expect(new_issue.persisted?).to be true
|
||||
end
|
||||
|
||||
it 'changes author' do
|
||||
expect(new_issue.author).to eq user
|
||||
it 'preserves author' do
|
||||
expect(new_issue.author).to eq author
|
||||
end
|
||||
|
||||
it 'removes data that is invalid in new context' do
|
||||
|
|
Loading…
Reference in a new issue