Commit 5821a492 authored by Douglas Barbosa Alexandre's avatar Douglas Barbosa Alexandre

Merge branch '9421-epics-should-clone' into 'master'

Clone epic data when cloning issues

See merge request gitlab-org/gitlab!50097
parents 276f5149 8732440f
...@@ -88,3 +88,5 @@ module Issues ...@@ -88,3 +88,5 @@ module Issues
end end
end end
end end
Issues::CloneService.prepend_if_ee('EE::Issues::CloneService')
# frozen_string_literal: true
module EE
module Issues
module CloneService
extend ::Gitlab::Utils::Override
override :update_new_entity
def update_new_entity
super
add_epic
end
private
def add_epic
return unless epic = original_entity.epic
return unless can?(current_user, :update_epic, epic.group)
updated = ::Issues::UpdateService.new(target_project, current_user, epic: epic).execute(new_entity)
::Gitlab::UsageDataCounters::IssueActivityUniqueCounter.track_issue_changed_epic_action(author: current_user) if updated
end
end
end
end
---
title: Clone epic data when cloning issues
merge_request: 50097
author:
type: added
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Issues::CloneService do
let_it_be(:user) { create(:user) }
let_it_be(:group) { create(:group) }
let_it_be(:old_project) { create(:project, group: group) }
let_it_be(:new_project) { create(:project, group: group) }
let_it_be(:old_issue, reload: true) { create(:issue, project: old_project, author: user) }
let(:clone_service) { described_class.new(old_project, user) }
subject { clone_service.execute(old_issue, new_project) }
before do
group.add_reporter(user)
end
describe '#execute' do
context 'group issue hooks' do
let_it_be(:hook) { create(:group_hook, group: group, issues_events: true) }
it 'executes group issue hooks' do
allow_next_instance_of(WebHookService) do |instance|
allow(instance).to receive(:execute)
end
# Ideally, we'd test that `WebHookWorker.jobs.size` increased by 1,
# but since the entire spec run takes place in a transaction, we never
# actually get to the `after_commit` hook that queues these jobs.
expect { subject }
.not_to raise_error # Sidekiq::Worker::EnqueueFromTransactionError
end
end
context 'resource weight events' do
let_it_be(:old_issue) { create(:issue, project: old_project, author: user, weight: 5) }
let_it_be(:event1) { create(:resource_weight_event, issue: old_issue, weight: 1) }
let_it_be(:event2) { create(:resource_weight_event, issue: old_issue, weight: 42) }
let_it_be(:event3) { create(:resource_weight_event, issue: old_issue, weight: 5) }
let_it_be(:another_old_issue) { create(:issue, project: new_project, author: user) }
let_it_be(:event4) { create(:resource_weight_event, issue: another_old_issue, weight: 2) }
it 'creates expected resource weight events' do
expect(subject.resource_weight_events.map(&:weight)).to contain_exactly(1, 42, 5)
end
end
context 'epics' do
context 'issue assigned to epic' do
let_it_be(:epic) { create(:epic, group: group) }
before do
stub_licensed_features(epics: true)
create(:epic_issue, issue: old_issue, epic: epic)
end
it 'creates epic reference' do
expect(subject.epic).to eq(epic)
end
it 'tracks usage data for changed epic action' do
expect(Gitlab::UsageDataCounters::IssueActivityUniqueCounter).to receive(:track_issue_changed_epic_action).with(author: user)
subject
end
context 'user can not update the epic' do
before do
group.group_member(user).destroy!
old_project.add_reporter(user)
new_project.add_reporter(user)
end
it 'ignores epic reference' do
expect(subject.epic).to be_nil
end
it 'does not send usage data for changed epic action' do
expect(Gitlab::UsageDataCounters::IssueActivityUniqueCounter).not_to receive(:track_issue_changed_epic_action)
subject
end
end
context 'epic update fails' do
it 'does not send usage data for changed epic action' do
allow_next_instance_of(::Issues::UpdateService) do |update_service|
allow(update_service).to receive(:execute).and_return(false)
end
expect(Gitlab::UsageDataCounters::IssueActivityUniqueCounter).not_to receive(:track_issue_changed_epic_action)
subject
end
end
end
end
end
end
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Issues::CloneService do
let_it_be(:user) { create(:user) }
let_it_be(:author) { create(:user) }
let_it_be(:group) { create(:group, :private) }
let_it_be(:epic) { create(:epic, group: group) }
let_it_be(:sub_group_1) { create(:group, :private, parent: group) }
let_it_be(:old_project) { create(:project, namespace: group) }
let_it_be(:new_project) { create(:project, namespace: sub_group_1) }
let_it_be(:old_issue) { create(:issue, project: old_project, author: author, epic: epic) }
subject(:clone_service) do
described_class.new(old_project, user)
end
let(:new_issue) { clone_service.execute(old_issue, new_project) }
context 'user has enough permissions' do
before do
old_project.add_reporter(user)
new_project.add_reporter(user)
end
it 'does not copy epic' do
expect(new_issue.epic).to be_nil
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