Commit 94652de7 authored by Sean McGivern's avatar Sean McGivern

Merge branch '38096-fix-missing-write-of-resource-weight-events-on-moved-issues' into 'master'

Fix missing write of weight events for moved issues

See merge request gitlab-org/gitlab!22461
parents ab108cd3 d0e4810a
...@@ -18,6 +18,7 @@ module Issuable ...@@ -18,6 +18,7 @@ module Issuable
new_entity.update(update_attributes) new_entity.update(update_attributes)
copy_resource_label_events copy_resource_label_events
copy_resource_weight_events
end end
private private
...@@ -60,6 +61,20 @@ module Issuable ...@@ -60,6 +61,20 @@ module Issuable
end end
end end
def copy_resource_weight_events
return unless original_entity.respond_to?(:resource_weight_events)
original_entity.resource_weight_events.find_in_batches do |batch|
events = batch.map do |event|
event.attributes
.except('id', 'reference', 'reference_html')
.merge('issue_id' => new_entity.id)
end
Gitlab::Database.bulk_insert(ResourceWeightEvent.table_name, events)
end
end
def entity_key def entity_key
new_entity.class.name.parameterize('_').foreign_key new_entity.class.name.parameterize('_').foreign_key
end end
......
...@@ -11,7 +11,7 @@ module EE ...@@ -11,7 +11,7 @@ module EE
super super
ActiveRecord::Base.no_touching do ActiveRecord::Base.no_touching do
handle_weight_change handle_weight_change(is_update)
handle_date_change_note if is_update handle_date_change_note if is_update
end end
end end
...@@ -28,11 +28,13 @@ module EE ...@@ -28,11 +28,13 @@ module EE
end end
end end
def handle_weight_change def handle_weight_change(is_update)
return unless issuable.previous_changes.include?('weight') return unless issuable.previous_changes.include?('weight')
if weight_changes_tracking_enabled? if weight_changes_tracking_enabled?
EE::ResourceEvents::ChangeWeightService.new([issuable], current_user, Time.now).execute # Only create a resource event here if is_update is true to exclude the move issue operation.
# ResourceEvents for moved issues are written within AttributesRewriter.
EE::ResourceEvents::ChangeWeightService.new([issuable], current_user, Time.now).execute if is_update
else else
::SystemNoteService.change_weight_note(issuable, issuable.project, current_user) ::SystemNoteService.change_weight_note(issuable, issuable.project, current_user)
end end
......
# frozen_string_literal: true
require 'spec_helper'
# Regression test for https://gitlab.com/gitlab-org/gitlab/merge_requests/22461
describe 'Resource weight events', :js do
include Spec::Support::Helpers::Features::NotesHelpers
describe 'move issue by quick action' do
let(:user) { create(:user) }
let(:project) { create(:project, :public, :repository) }
let(:issue) { create(:issue, project: project, weight: nil, due_date: Date.new(2016, 8, 28)) }
before do
project.add_maintainer(user)
sign_in(user)
visit project_issue_path(project, issue)
wait_for_all_requests
end
after do
wait_for_requests
end
context 'when original issue has weight events' do
let(:target_project) { create(:project, :public) }
before do
target_project.add_maintainer(user)
add_note("/weight 2")
wait_for_requests
add_note("/weight 3\n/move #{target_project.full_path}")
end
it "creates expected weight events on the moved issue" do
expect(page).to have_content "Moved this issue to #{target_project.full_path}."
expect(issue.reload).to be_closed
visit project_issue_path(target_project, issue)
wait_for_all_requests
expect(page).to have_content 'changed weight to 2'
expect(page).to have_content 'changed weight to 3'
visit project_issue_path(project, issue)
wait_for_all_requests
expect(page).to have_content 'changed weight to 2'
expect(page).to have_content 'changed weight to 3'
expect(page).to have_content 'Closed'
end
end
end
end
...@@ -62,13 +62,8 @@ describe Issuable::CommonSystemNotesService do ...@@ -62,13 +62,8 @@ describe Issuable::CommonSystemNotesService do
stub_feature_flags(track_issue_weight_change_events: true) stub_feature_flags(track_issue_weight_change_events: true)
end end
it 'creates a resource weight event' do it 'does not create a resource weight event' do
subject expect { subject }.not_to change { ResourceWeightEvent.count }
event = issuable.resource_weight_events.last
expect(event.weight).to eq(5)
expect(event.user_id).to eq(user.id)
end end
it 'does not create a system note' do it 'does not create a system note' do
......
...@@ -28,6 +28,21 @@ describe Issues::MoveService do ...@@ -28,6 +28,21 @@ describe Issues::MoveService do
.not_to raise_error # Sidekiq::Worker::EnqueueFromTransactionError .not_to raise_error # Sidekiq::Worker::EnqueueFromTransactionError
end end
end end
context 'resource weight events' do
let!(:event1) { create(:resource_weight_event, issue: old_issue, weight: 1) }
let!(:event2) { create(:resource_weight_event, issue: old_issue, weight: 42) }
let!(:event3) { create(:resource_weight_event, issue: old_issue, weight: 5) }
let!(:another_old_issue) { create(:issue, project: new_project, author: user) }
let!(:event4) { create(:resource_weight_event, issue: another_old_issue, weight: 2) }
it 'creates expected resource weight events' do
new_issue = move_service.execute(old_issue, new_project)
expect(new_issue.resource_weight_events.map(&:weight)).to contain_exactly(1, 42, 5)
end
end
end end
describe '#rewrite_related_issues' do describe '#rewrite_related_issues' do
......
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