Commit 93a9fce9 authored by Heinrich Lee Yu's avatar Heinrich Lee Yu

Merge branch 'issue-227174' into 'master'

FIX: handle argument error in the api layer

Closes #227174

See merge request gitlab-org/gitlab!41167
parents 57c427fc 26b68d8d
---
title: Handle todos api argument error
merge_request: 41167
author: gaga5lala
type: fixed
...@@ -21,12 +21,12 @@ Parameters: ...@@ -21,12 +21,12 @@ Parameters:
| Attribute | Type | Required | Description | | Attribute | Type | Required | Description |
| --------- | ---- | -------- | ----------- | | --------- | ---- | -------- | ----------- |
| `action` | string | no | The action to be filtered. Can be `assigned`, `mentioned`, `build_failed`, `marked`, `approval_required`, `unmergeable` or `directly_addressed`. | | `action` | string | no | The action to be filtered. Can be `assigned`, `mentioned`, `build_failed`, `marked`, `approval_required`, `unmergeable`, `directly_addressed` or `merge_train_removed`. |
| `author_id` | integer | no | The ID of an author | | `author_id` | integer | no | The ID of an author |
| `project_id` | integer | no | The ID of a project | | `project_id` | integer | no | The ID of a project |
| `group_id` | integer | no | The ID of a group | | `group_id` | integer | no | The ID of a group |
| `state` | string | no | The state of the todo. Can be either `pending` or `done` | | `state` | string | no | The state of the todo. Can be either `pending` or `done` |
| `type` | string | no | The type of a todo. Can be either `Issue` or `MergeRequest` | | `type` | string | no | The type of a todo. Can be either `Issue`, `MergeRequest`, `DesignManagement::Design` or `AlertManagement::Alert` |
```shell ```shell
curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/todos" curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/todos"
......
...@@ -39,8 +39,17 @@ module API ...@@ -39,8 +39,17 @@ module API
resource :todos do resource :todos do
helpers do helpers do
params :todo_filters do
optional :action, String, values: Todo::ACTION_NAMES.values.map(&:to_s)
optional :author_id, Integer
optional :state, String, values: Todo.state_machine.states.map(&:name).map(&:to_s)
optional :type, String, values: TodosFinder.todo_types
optional :project_id, Integer
optional :group_id, Integer
end
def find_todos def find_todos
TodosFinder.new(current_user, params).execute TodosFinder.new(current_user, declared_params(include_missing: false)).execute
end end
def issuable_and_awardable?(type) def issuable_and_awardable?(type)
...@@ -72,7 +81,7 @@ module API ...@@ -72,7 +81,7 @@ module API
success Entities::Todo success Entities::Todo
end end
params do params do
use :pagination use :pagination, :todo_filters
end end
get do get do
todos = paginate(find_todos.with_entity_associations) todos = paginate(find_todos.with_entity_associations)
......
...@@ -34,6 +34,29 @@ RSpec.describe API::Todos do ...@@ -34,6 +34,29 @@ RSpec.describe API::Todos do
end end
context 'when authenticated' do context 'when authenticated' do
context 'when invalid params' do
context "invalid action" do
it 'returns 400' do
get api('/todos', john_doe), params: { action: 'InvalidAction' }
expect(response).to have_gitlab_http_status(:bad_request)
end
end
context "invalid state" do
it 'returns 400' do
get api('/todos', john_doe), params: { state: 'InvalidState' }
expect(response).to have_gitlab_http_status(:bad_request)
end
end
context "invalid type" do
it 'returns 400' do
get api('/todos', john_doe), params: { type: 'InvalidType' }
expect(response).to have_gitlab_http_status(:bad_request)
end
end
end
it 'returns an array of pending todos for current user' do it 'returns an array of pending todos for current user' do
get api('/todos', john_doe) get api('/todos', john_doe)
......
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