summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKia Mei Somabes <kia@aelogica.com>2018-07-12 09:26:09 +0000
committerRémy Coutable <remy@rymai.me>2018-07-12 09:26:09 +0000
commit37af75a2e024bf35f09e6f014626019e960ad9b9 (patch)
treef156e2fc0ced165327e9a48ce3ae153608ff2bb4
parentd2c5ac61cd964e6c3ff22021734002b6e591a128 (diff)
downloadgitlab-ce-37af75a2e024bf35f09e6f014626019e960ad9b9.tar.gz
Resolve "do not set updated_at when creating note"
-rw-r--r--changelogs/unreleased/46930-fix-updated_at-if-created_at-is-set-note-api.yml5
-rw-r--r--doc/api/notes.md2
-rw-r--r--lib/api/helpers/notes_helpers.rb2
-rw-r--r--spec/support/shared_examples/requests/api/notes.rb1
4 files changed, 10 insertions, 0 deletions
diff --git a/changelogs/unreleased/46930-fix-updated_at-if-created_at-is-set-note-api.yml b/changelogs/unreleased/46930-fix-updated_at-if-created_at-is-set-note-api.yml
new file mode 100644
index 00000000000..d95714a5267
--- /dev/null
+++ b/changelogs/unreleased/46930-fix-updated_at-if-created_at-is-set-note-api.yml
@@ -0,0 +1,5 @@
+---
+title: Fix updated_at if created_at is set for Note API
+merge_request:
+author:
+type: fixed
diff --git a/doc/api/notes.md b/doc/api/notes.md
index d29c5b94915..c271d46688f 100644
--- a/doc/api/notes.md
+++ b/doc/api/notes.md
@@ -218,6 +218,7 @@ Parameters:
- `id` (required) - The ID or [URL-encoded path of the project](README.md#namespaced-path-encoding)
- `snippet_id` (required) - The ID of a snippet
- `body` (required) - The content of a note
+- `created_at` (optional) - Date time string, ISO 8601 formatted, e.g. 2016-03-11T03:45:40Z
```bash
curl --request POST --header "PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK" https://gitlab.example.com/api/v4/projects/5/snippet/11/notes?body=note
@@ -340,6 +341,7 @@ Parameters:
- `id` (required) - The ID or [URL-encoded path of the project](README.md#namespaced-path-encoding)
- `merge_request_iid` (required) - The IID of a merge request
- `body` (required) - The content of a note
+- `created_at` (optional) - Date time string, ISO 8601 formatted, e.g. 2016-03-11T03:45:40Z
### Modify existing merge request note
diff --git a/lib/api/helpers/notes_helpers.rb b/lib/api/helpers/notes_helpers.rb
index b4bfb677d72..e2984b08eca 100644
--- a/lib/api/helpers/notes_helpers.rb
+++ b/lib/api/helpers/notes_helpers.rb
@@ -97,6 +97,8 @@ module API
current_user.admin? || parent.owned_by?(current_user)
end
+ opts[:updated_at] = opts[:created_at] if opts[:created_at]
+
project = parent if parent.is_a?(Project)
::Notes::CreateService.new(project, current_user, opts).execute
end
diff --git a/spec/support/shared_examples/requests/api/notes.rb b/spec/support/shared_examples/requests/api/notes.rb
index 79b2196660c..1b563021244 100644
--- a/spec/support/shared_examples/requests/api/notes.rb
+++ b/spec/support/shared_examples/requests/api/notes.rb
@@ -121,6 +121,7 @@ shared_examples 'noteable API' do |parent_type, noteable_type, id_name|
expect(json_response['body']).to eq('hi!')
expect(json_response['author']['username']).to eq(user.username)
expect(Time.parse(json_response['created_at'])).to be_like_time(creation_time)
+ expect(Time.parse(json_response['updated_at'])).to be_like_time(creation_time)
end
end