Commit d0d89c72 authored by Jan Provaznik's avatar Jan Provaznik

Merge branch '11445-fix-promoted-epic-inherited-discussions' into 'master'

Fix reply to discussion on promoted epic

Closes #11445

See merge request gitlab-org/gitlab-ee!14576
parents 2c6a6156 c0da7dcf
......@@ -23,10 +23,14 @@ module Issuable
end
def rewrite_notes
new_discussion_ids = {}
original_entity.notes_with_associations.find_each do |note|
new_note = note.dup
new_discussion_ids[note.discussion_id] ||= Discussion.discussion_id(new_note)
new_params = {
project: new_entity.project, noteable: new_entity,
project: new_entity.project,
noteable: new_entity,
discussion_id: new_discussion_ids[note.discussion_id],
note: rewrite_content(new_note.note),
note_html: nil,
created_at: note.created_at,
......
......@@ -44,6 +44,10 @@ class Groups::Epics::NotesController < Groups::ApplicationController
EpicNoteSerializer.new(project: nil, noteable: noteable, current_user: current_user)
end
def discussion_serializer
DiscussionSerializer.new(project: nil, noteable: noteable, current_user: current_user, note_entity: EpicNoteEntity)
end
override :create_note_params
def create_note_params
params[:target_type] = 'Epic'
......
---
title: Fix reply to discussion on promoted epic
merge_request: 14576
author:
type: fixed
......@@ -73,6 +73,30 @@ describe Groups::Epics::NotesController do
expect(response).to have_gitlab_http_status(200)
expect(parsed_response[:id]).not_to be_nil
end
context "when epic was promoted from issue" do
let(:project) { create(:project, group: group) }
let(:issue) { create(:issue, project: project) }
let!(:discussion) { create(:discussion_note_on_issue, noteable: issue, project: issue.project) }
let(:epic) { Epics::IssuePromoteService.new(project, user).execute(issue) }
let(:request_params) do
{
note: { note: 'reply note', noteable_id: epic.id, noteable_type: 'Epic' },
group_id: epic.group,
epic_id: epic.iid,
in_reply_to_discussion_id: epic.discussions.first.id,
format: 'json'
}
end
it "creates reply note for discussion" do
post :create, params: request_params
expect(response).to have_gitlab_http_status(200)
expect(parsed_response[:errors]).to be_nil
end
end
end
describe 'PUT update' do
......
......@@ -84,6 +84,22 @@ describe Epics::IssuePromoteService do
expect(issue).to be_closed
end
end
context 'when promoted issue has notes' do
let!(:discussion) { create(:discussion_note_on_issue, noteable: issue, project: issue.project) }
before do
allow(Gitlab::SnowplowTracker).to receive(:track_event).with('epics', 'promote', an_instance_of(Hash))
issue.reload
end
it 'creates a new epic with all notes' do
epic = subject.execute(issue)
expect(epic.notes.count).to eq(issue.notes.count)
expect(epic.notes.where(discussion_id: discussion.discussion_id).count).to eq(0)
expect(issue.notes.where(discussion_id: discussion.discussion_id).count).to eq(1)
end
end
end
end
end
......
......@@ -165,5 +165,18 @@ describe Issuable::Clone::ContentRewriter do
expect(note.note_html).not_to eq(new_note.note_html)
end
end
context "discussion notes" do
let(:note) { create(:note, noteable: original_issue, note: "sample note", project: project1) }
let!(:discussion) { create(:discussion_note_on_issue, in_reply_to: note, note: "reply to sample note") }
it 'rewrites discussion correctly' do
subject.execute
expect(new_issue.notes.count).to eq(original_issue.notes.count)
expect(new_issue.notes.where(discussion_id: discussion.discussion_id).count).to eq(0)
expect(original_issue.notes.where(discussion_id: discussion.discussion_id).count).to eq(1)
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