summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHeinrich Lee Yu <heinrich@gitlab.com>2019-04-16 15:40:25 +0800
committerHeinrich Lee Yu <heinrich@gitlab.com>2019-04-16 19:57:49 +0800
commite0b6838a90b47f34c1109b6a9727f249c6faebca (patch)
tree42eca4e94f51500019b54f3d04277b1ae1307428
parent7994db791ab758d81f7a446eb8e2338336e184fd (diff)
downloadgitlab-ce-58361-issue-create-system-note-timestamp.tar.gz
Set correct timestamps when creating past issues58361-issue-create-system-note-timestamp
Sets `system_note_timestamp` from `created_at`
-rw-r--r--app/models/concerns/noteable.rb2
-rw-r--r--changelogs/unreleased/58361-issue-create-system-note-timestamp.yml5
-rw-r--r--lib/api/issues.rb1
-rw-r--r--spec/requests/api/issues_spec.rb10
4 files changed, 16 insertions, 2 deletions
diff --git a/app/models/concerns/noteable.rb b/app/models/concerns/noteable.rb
index 423ce7e7db1..bfd0c36942b 100644
--- a/app/models/concerns/noteable.rb
+++ b/app/models/concerns/noteable.rb
@@ -13,7 +13,7 @@ module Noteable
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)
def system_note_timestamp
@system_note_timestamp || Time.now # rubocop:disable Gitlab/ModuleWithInstanceVariables
diff --git a/changelogs/unreleased/58361-issue-create-system-note-timestamp.yml b/changelogs/unreleased/58361-issue-create-system-note-timestamp.yml
new file mode 100644
index 00000000000..d8fe3e4aa48
--- /dev/null
+++ b/changelogs/unreleased/58361-issue-create-system-note-timestamp.yml
@@ -0,0 +1,5 @@
+---
+title: Fix system notes timestamp when creating issue in the past
+merge_request: 27406
+author:
+type: fixed
diff --git a/lib/api/issues.rb b/lib/api/issues.rb
index 000c00ea9f9..d0a93b77951 100644
--- a/lib/api/issues.rb
+++ b/lib/api/issues.rb
@@ -192,6 +192,7 @@ module API
params.delete(:iid) unless current_user.can?(:set_issue_iid, user_project)
issue_params = declared_params(include_missing: false)
+ issue_params[:system_note_timestamp] = params[:created_at]
issue_params = convert_parameters_from_legacy_format(issue_params)
diff --git a/spec/requests/api/issues_spec.rb b/spec/requests/api/issues_spec.rb
index 86484ce62f8..0fa34688371 100644
--- a/spec/requests/api/issues_spec.rb
+++ b/spec/requests/api/issues_spec.rb
@@ -1480,12 +1480,20 @@ describe API::Issues do
let(:params) { { title: 'new issue', labels: 'label, label2', created_at: creation_time } }
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
+ end
+ it 'sets the creation time on the new issue' do
expect(response).to have_gitlab_http_status(201)
expect(Time.parse(json_response['created_at'])).to be_like_time(creation_time)
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
context 'by a project owner' do