Skip to content
Snippets Groups Projects
Commit c8e7d1ed authored by Grzegorz Bizon's avatar Grzegorz Bizon
Browse files

Add issue move implementation to controller

parent 11f817b3
No related branches found
No related tags found
1 merge request!2831Ability to move issue to another project
Loading
Loading
@@ -88,6 +88,11 @@ class Projects::IssuesController < Projects::ApplicationController
 
def update
@issue = Issues::UpdateService.new(project, current_user, issue_params).execute(issue)
move_service = Issues::MoveService.new(project, current_user, params.require(:issue).permit!, @issue)
if move_service.move?
@issue = move_service.execute
end
 
respond_to do |format|
format.js
Loading
Loading
module Issues
class MoveService < Issues::BaseService
def execute(issue_old, project_new)
@issue_old = issue_old
@issue_new = issue_old.dup
@project_new = project_new
def initialize(project, current_user, params, issue)
super(project, current_user, params)
@issue_old = issue
@issue_new = @issue_old.dup
@project_old = @project
 
if params['move_to_project_id']
@project_new = Project.find(params['move_to_project_id'])
end
end
def execute
return unless move?
open_new_issue
rewrite_notes
close_old_issue
Loading
Loading
@@ -14,8 +23,20 @@ module Issues
@issue_new
end
 
def move?
return false unless @project_new
return false unless @issue_new
return false unless can_move?
true
end
private
 
def can_move?
true
end
def open_new_issue
@issue_new.project = @project_new
@issue_new.save!
Loading
Loading
Loading
Loading
@@ -5,26 +5,44 @@ describe Issues::MoveService, services: true do
let(:issue) { create(:issue, title: 'Some issue', description: 'Some issue description') }
let(:current_project) { issue.project }
let(:new_project) { create(:project) }
let(:move_params) { { 'move_to_project_id' => new_project.id } }
let(:move_service) { described_class.new(current_project, user, move_params, issue) }
 
before do
current_project.team << [user, :master]
end
 
describe '#execute' do
let!(:new_issue) do
described_class.new(current_project, user).execute(issue, new_project)
context 'issue movable' do
describe '#move?' do
subject { move_service.move? }
it { is_expected.to be_truthy }
end
 
it 'should create a new issue in a new project' do
expect(new_issue.project).to eq new_project
end
describe '#execute' do
let!(:new_issue) { move_service.execute }
it 'should create a new issue in a new project' do
expect(new_issue.project).to eq new_project
end
it 'should add system note to old issue' do
expect(issue.notes.last.note).to match /^Moved to/
end
 
it 'should add system note to old issue' do
expect(issue.notes.last.note).to match /^Moved to/
it 'should add system note to new issue' do
expect(new_issue.notes.last.note).to match /^Moved from/
end
end
end
context 'issue not movable' do
context 'move not requested' do
let(:move_params) { {} }
 
it 'should add system note to new issue' do
expect(new_issue.notes.last.note).to match /^Moved from/
describe '#move?' do
subject { move_service.move? }
it { is_expected.to be_falsey }
end
end
end
end
Loading
Loading
@@ -486,7 +486,7 @@ describe SystemNoteService, services: true do
end
 
context 'invalid direction' do
let (:direction) { :invalid }
let(:direction) { :invalid }
 
it 'should raise error' do
expect { subject }.to raise_error StandardError, /Invalid direction/
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment