Commit e0b6838a authored by Heinrich Lee Yu's avatar Heinrich Lee Yu

Set correct timestamps when creating past issues

Sets `system_note_timestamp` from `created_at`
parent 7994db79
...@@ -13,7 +13,7 @@ module Noteable ...@@ -13,7 +13,7 @@ module Noteable
end end
end end
# The timestamp of the note (e.g. the :updated_at attribute if provided via # The timestamp of the note (e.g. the :created_at or :updated_at attribute if provided via
# API call) # API call)
def system_note_timestamp def system_note_timestamp
@system_note_timestamp || Time.now # rubocop:disable Gitlab/ModuleWithInstanceVariables @system_note_timestamp || Time.now # rubocop:disable Gitlab/ModuleWithInstanceVariables
......
---
title: Fix system notes timestamp when creating issue in the past
merge_request: 27406
author:
type: fixed
...@@ -192,6 +192,7 @@ module API ...@@ -192,6 +192,7 @@ module API
params.delete(:iid) unless current_user.can?(:set_issue_iid, user_project) params.delete(:iid) unless current_user.can?(:set_issue_iid, user_project)
issue_params = declared_params(include_missing: false) issue_params = declared_params(include_missing: false)
issue_params[:system_note_timestamp] = params[:created_at]
issue_params = convert_parameters_from_legacy_format(issue_params) issue_params = convert_parameters_from_legacy_format(issue_params)
......
...@@ -1480,12 +1480,20 @@ describe API::Issues do ...@@ -1480,12 +1480,20 @@ describe API::Issues do
let(:params) { { title: 'new issue', labels: 'label, label2', created_at: creation_time } } let(:params) { { title: 'new issue', labels: 'label, label2', created_at: creation_time } }
context 'by an admin' do context 'by an admin' do
it 'sets the creation time on the new issue' do before do
post api("/projects/#{project.id}/issues", admin), params: params post api("/projects/#{project.id}/issues", admin), params: params
end
it 'sets the creation time on the new issue' do
expect(response).to have_gitlab_http_status(201) expect(response).to have_gitlab_http_status(201)
expect(Time.parse(json_response['created_at'])).to be_like_time(creation_time) expect(Time.parse(json_response['created_at'])).to be_like_time(creation_time)
end end
it 'sets the system notes timestamp based on creation time' do
issue = Issue.find(json_response['id'])
expect(issue.resource_label_events.last.created_at).to be_like_time(creation_time)
end
end end
context 'by a project owner' do context 'by a project owner' 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