summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZeger-Jan van de Weg <zegerjan@gitlab.com>2016-03-25 22:21:50 +0100
committerZeger-Jan van de Weg <zegerjan@gitlab.com>2016-03-25 22:24:52 +0100
commita883299c3e4f286e6d8b22a58be59c91666d4242 (patch)
tree44acf35d12260d821c850f629b1fb4b878ba36cd
parent43e49f52e30199c9724329e71f375874eb76d554 (diff)
downloadgitlab-ce-api-ability-to-backdate-newly-created-issues-12628.tar.gz
Back dating of issues when creating throught the APIapi-ability-to-backdate-newly-created-issues-12628
-rw-r--r--CHANGELOG1
-rw-r--r--app/models/ability.rb1
-rw-r--r--doc/api/issues.md1
-rw-r--r--lib/api/issues.rb16
-rw-r--r--spec/requests/api/issues_spec.rb11
5 files changed, 24 insertions, 6 deletions
diff --git a/CHANGELOG b/CHANGELOG
index 5d9f4961ef5..ef40c367dee 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -3,6 +3,7 @@ Please view this file on the master branch, on stable branches it's out of date.
v 8.7.0 (unreleased)
- Preserve time notes/comments have been updated at when moving issue
- Make HTTP(s) label consistent on clone bar (Stan Hu)
+ - Allow back dating on issues when created through the API
- Fix avatar stretching by providing a cropping feature
v 8.6.2 (unreleased)
diff --git a/app/models/ability.rb b/app/models/ability.rb
index fa2345f6faa..95336654d6d 100644
--- a/app/models/ability.rb
+++ b/app/models/ability.rb
@@ -236,6 +236,7 @@ class Ability
:remove_project,
:archive_project,
:remove_fork_project,
+ :backdate_issue,
:destroy_merge_request,
:destroy_issue
]
diff --git a/doc/api/issues.md b/doc/api/issues.md
index 18d64c41986..76596228f35 100644
--- a/doc/api/issues.md
+++ b/doc/api/issues.md
@@ -237,6 +237,7 @@ POST /projects/:id/issues
| `assignee_id` | integer | no | The ID of a user to assign issue |
| `milestone_id` | integer | no | The ID of a milestone to assign issue |
| `labels` | string | no | Comma-separated label names for an issue |
+| `created_at` | string | no | Date time string, OSI 8601 formatted, e.g. `2016-03-11T03:45:40Z` |
```bash
curl -X POST -H "PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK" https://gitlab.example.com/api/v3/projects/4/issues?title=Issues%20with%20auth&labels=bug
diff --git a/lib/api/issues.rb b/lib/api/issues.rb
index e5ae88eb96f..78f7ac37139 100644
--- a/lib/api/issues.rb
+++ b/lib/api/issues.rb
@@ -111,17 +111,21 @@ module API
# Create a new project issue
#
# Parameters:
- # id (required) - The ID of a project
- # title (required) - The title of an issue
- # description (optional) - The description of an issue
- # assignee_id (optional) - The ID of a user to assign issue
+ # id (required) - The ID of a project
+ # title (required) - The title of an issue
+ # description (optional) - The description of an issue
+ # assignee_id (optional) - The ID of a user to assign issue
# milestone_id (optional) - The ID of a milestone to assign issue
- # labels (optional) - The labels of an issue
+ # labels (optional) - The labels of an issue
+ # created_at (optional) - The date
# Example Request:
# POST /projects/:id/issues
post ":id/issues" do
required_attributes! [:title]
- attrs = attributes_for_keys [:title, :description, :assignee_id, :milestone_id]
+
+ keys = [:title, :description, :assignee_id, :milestone_id]
+ keys << :created_at if current_user.can?(:backdate_issue, user_project)
+ attrs = attributes_for_keys(keys)
# Validate label names in advance
if (errors = validate_label_params(params)).any?
diff --git a/spec/requests/api/issues_spec.rb b/spec/requests/api/issues_spec.rb
index ce55cb7b0ae..822d3ad3017 100644
--- a/spec/requests/api/issues_spec.rb
+++ b/spec/requests/api/issues_spec.rb
@@ -318,6 +318,17 @@ describe API::API, api: true do
'is too long (maximum is 255 characters)'
])
end
+
+ context 'when an admin or owner makes the request' do
+ it "accepts the creation date to be set" do
+ post api("/projects/#{project.id}/issues", user),
+ title: 'new issue', labels: 'label, label2', created_at: 2.weeks.ago
+
+ expect(response.status).to eq(201)
+ # this take about a second, so probably not equal
+ expect(Time.parse(json_response['created_at'])).to be <= 2.weeks.ago
+ end
+ end
end
describe 'POST /projects/:id/issues with spam filtering' do