Commit 9c8d6d8e authored by Igor Drozdov's avatar Igor Drozdov

Merge branch '233708-fix-resource-event-timestamps' into 'master'

Use issuable.system_note_timestamp when present

See merge request gitlab-org/gitlab!53237
parents c397b417 991c50e7
......@@ -2,12 +2,11 @@
module ResourceEvents
class BaseChangeTimeboxService
attr_reader :resource, :user, :event_created_at
attr_reader :resource, :user
def initialize(resource, user, created_at: Time.current)
def initialize(resource, user)
@resource = resource
@user = user
@event_created_at = created_at
end
def execute
......@@ -27,7 +26,7 @@ module ResourceEvents
{
user_id: user.id,
created_at: event_created_at,
created_at: resource.system_note_timestamp,
key => resource.id
}
end
......
......@@ -4,8 +4,8 @@ module ResourceEvents
class ChangeMilestoneService < BaseChangeTimeboxService
attr_reader :milestone, :old_milestone
def initialize(resource, user, created_at: Time.current, old_milestone:)
super(resource, user, created_at: created_at)
def initialize(resource, user, old_milestone:)
super(resource, user)
@milestone = resource&.milestone
@old_milestone = old_milestone
......
---
title: Use user-provided timestamp when updating issue and merge request milestones,
iterations, and weights using the API
merge_request: 53237
author:
type: fixed
......@@ -42,7 +42,7 @@ module EE
def handle_weight_change
return unless issuable.previous_changes.include?('weight')
::ResourceEvents::ChangeWeightService.new(issuable, current_user, Time.current).execute
::ResourceEvents::ChangeWeightService.new(issuable, current_user).execute
end
def handle_health_status_change
......
......@@ -4,8 +4,8 @@ module ResourceEvents
class ChangeIterationService < ::ResourceEvents::BaseChangeTimeboxService
attr_reader :iteration, :old_iteration_id
def initialize(resource, user, created_at: Time.current, old_iteration_id:)
super(resource, user, created_at: created_at)
def initialize(resource, user, old_iteration_id:)
super(resource, user)
@iteration = resource&.iteration
@old_iteration_id = old_iteration_id
......
......@@ -2,12 +2,11 @@
module ResourceEvents
class ChangeWeightService
attr_reader :resource, :user, :event_created_at
attr_reader :resource, :user
def initialize(resource, user, created_at)
def initialize(resource, user)
@resource = resource
@user = user
@event_created_at = created_at
end
def execute
......@@ -24,7 +23,7 @@ module ResourceEvents
base_data = { user_id: user.id, issue_id: resource.id }
changes << base_data.merge({ weight: resource.previous_weight, created_at: resource.previous_updated_at }) if resource.first_weight_event?
changes << base_data.merge({ weight: resource.weight, created_at: event_created_at })
changes << base_data.merge({ weight: resource.weight, created_at: resource.system_note_timestamp })
changes
end
......
......@@ -6,8 +6,8 @@ RSpec.describe ResourceEvents::ChangeIterationService do
let_it_be(:timebox) { create(:iteration) }
let(:created_at_time) { Time.utc(2019, 12, 30) }
let(:add_timebox_args) { { created_at: created_at_time, old_iteration_id: nil } }
let(:remove_timebox_args) { { created_at: created_at_time, old_iteration_id: timebox.id } }
let(:add_timebox_args) { { old_iteration_id: nil } }
let(:remove_timebox_args) { { old_iteration_id: timebox.id } }
[:issue, :merge_request].each do |issuable|
it_behaves_like 'timebox(milestone or iteration) resource events creator', ResourceIterationEvent do
......
......@@ -8,10 +8,11 @@ RSpec.describe ResourceEvents::ChangeWeightService do
let(:issue) { create(:issue, weight: 3) }
let(:created_at_time) { Time.utc(2019, 1, 1, 12, 30, 48, '123.123'.to_r) }
subject { described_class.new(issue, user, created_at_time).execute }
subject { described_class.new(issue, user).execute }
before do
ResourceWeightEvent.new(issue: issue, user: user).save!
issue.system_note_timestamp = created_at_time
end
it 'creates the expected event record' do
......
......@@ -6,8 +6,8 @@ RSpec.describe ResourceEvents::ChangeMilestoneService do
let_it_be(:timebox) { create(:milestone) }
let(:created_at_time) { Time.utc(2019, 12, 30) }
let(:add_timebox_args) { { created_at: created_at_time, old_milestone: nil } }
let(:remove_timebox_args) { { created_at: created_at_time, old_milestone: timebox } }
let(:add_timebox_args) { { old_milestone: nil } }
let(:remove_timebox_args) { { old_milestone: timebox } }
[:issue, :merge_request].each do |issuable|
it_behaves_like 'timebox(milestone or iteration) resource events creator', ResourceMilestoneEvent do
......
......@@ -3,6 +3,10 @@
RSpec.shared_examples 'timebox(milestone or iteration) resource events creator' do |timebox_event_class|
let_it_be(:user) { create(:user) }
before do
resource.system_note_timestamp = created_at_time
end
context 'when milestone/iteration is added' do
let(:service) { described_class.new(resource, user, **add_timebox_args) }
......
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