Commit c1467f5d authored by Michael Greene's avatar Michael Greene

Allow back dating notes on creation

parent 28a7fe25
...@@ -23,6 +23,7 @@ v 8.7.0 (unreleased) ...@@ -23,6 +23,7 @@ v 8.7.0 (unreleased)
- Fix Error 500 after renaming a project path (Stan Hu) - Fix Error 500 after renaming a project path (Stan Hu)
- Fix a bug whith trailing slash in teamcity_url (Charles May) - Fix a bug whith trailing slash in teamcity_url (Charles May)
- Allow back dating on issues when created or updated through the API - Allow back dating on issues when created or updated through the API
- Allow back dating on issue notes when created through the API
- Fix avatar stretching by providing a cropping feature - Fix avatar stretching by providing a cropping feature
- API: Expose `subscribed` for issues and merge requests (Robert Schilling) - API: Expose `subscribed` for issues and merge requests (Robert Schilling)
- Allow SAML to handle external users based on user's information !3530 - Allow SAML to handle external users based on user's information !3530
......
...@@ -89,6 +89,7 @@ Parameters: ...@@ -89,6 +89,7 @@ Parameters:
- `id` (required) - The ID of a project - `id` (required) - The ID of a project
- `issue_id` (required) - The ID of an issue - `issue_id` (required) - The ID of an issue
- `body` (required) - The content of a note - `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 issue note ### Modify existing issue note
......
...@@ -61,6 +61,7 @@ module API ...@@ -61,6 +61,7 @@ module API
# id (required) - The ID of a project # id (required) - The ID of a project
# noteable_id (required) - The ID of an issue or snippet # noteable_id (required) - The ID of an issue or snippet
# body (required) - The content of a note # body (required) - The content of a note
# created_at (optional) - The date
# Example Request: # Example Request:
# POST /projects/:id/issues/:noteable_id/notes # POST /projects/:id/issues/:noteable_id/notes
# POST /projects/:id/snippets/:noteable_id/notes # POST /projects/:id/snippets/:noteable_id/notes
...@@ -73,6 +74,10 @@ module API ...@@ -73,6 +74,10 @@ module API
noteable_id: params[noteable_id_str] noteable_id: params[noteable_id_str]
} }
if params[:created_at] && (current_user.is_admin? || user_project.owner == current_user)
opts[:created_at] = params[:created_at]
end
@note = ::Notes::CreateService.new(user_project, current_user, opts).execute @note = ::Notes::CreateService.new(user_project, current_user, opts).execute
if @note.valid? if @note.valid?
......
...@@ -158,6 +158,19 @@ describe API::API, api: true do ...@@ -158,6 +158,19 @@ describe API::API, api: true do
post api("/projects/#{project.id}/issues/#{issue.id}/notes"), body: 'hi!' post api("/projects/#{project.id}/issues/#{issue.id}/notes"), body: 'hi!'
expect(response.status).to eq(401) expect(response.status).to eq(401)
end end
context 'when an admin or owner makes the request' do
it 'accepts the creation date to be set' do
creation_time = 2.weeks.ago
post api("/projects/#{project.id}/issues/#{issue.id}/notes", user),
body: 'hi!', created_at: creation_time
expect(response.status).to eq(201)
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_within(1.second).of(creation_time)
end
end
end end
context "when noteable is a Snippet" do context "when noteable is a Snippet" 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