Commit 548c7601 authored by Sean McGivern's avatar Sean McGivern

Merge branch 'move-epic-issue' into 'master'

Update epic issue when an issue is moved

See merge request gitlab-org/gitlab-ee!4550
parents 9090d0c2 1a128382
module Issues
class MoveService < Issues::BaseService
prepend ::EE::Issues::MoveService
MoveError = Class.new(StandardError)
def execute(issue, new_project)
......
---
title: Update epic issue reference when moving an issue
merge_request:
author:
type: fixed
module EE
module Issues
module MoveService
def update_old_issue
rewrite_epic_issue
super
end
private
# rubocop:disable Gitlab/ModuleWithInstanceVariables
def rewrite_epic_issue
return unless epic_issue = @old_issue.epic_issue
return unless can?(current_user, :update_epic, epic_issue.epic.group)
epic_issue.update(issue_id: @new_issue.id)
@old_issue.reload
end
# rubocop:enable Gitlab/ModuleWithInstanceVariables
end
end
end
require 'spec_helper'
describe Issues::MoveService do
let(:user) { create(:user) }
let(:old_project) { create(:project) }
let(:new_project) { create(:project, group: create(:group)) }
let(:old_issue) { create(:issue, project: old_project, author: user) }
let(:move_service) { described_class.new(old_project, user) }
describe '#rewrite_epic_issue' do
context 'issue assigned to epic' do
let!(:epic_issue) { create(:epic_issue, issue: old_issue) }
before do
stub_licensed_features(epics: true)
old_project.add_reporter(user)
new_project.add_reporter(user)
end
it 'updates epic issue reference' do
epic_issue.epic.group.add_reporter(user)
new_issue = move_service.execute(old_issue, new_project)
expect(new_issue.epic_issue).to eq(epic_issue)
end
it 'ignores epic issue reference if user can not update the epic' do
new_issue = move_service.execute(old_issue, new_project)
expect(new_issue.epic_issue).to be_nil
end
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment