Commit e075c701 authored by Douglas Barbosa Alexandre's avatar Douglas Barbosa Alexandre

Merge branch '348257-support-filtering-by-author-username-in-the-epics-api' into 'master'

Allow filtering epics by author_username and not[author_username]

See merge request gitlab-org/gitlab!77151
parents 0e7cb428 5d759493
......@@ -64,6 +64,7 @@ GET /groups/:id/epics?state=opened
| ------------------- | ---------------- | ---------- | --------------------------------------------------------------------------------------------------------------------------- |
| `id` | integer/string | yes | The ID or [URL-encoded path of the group](index.md#namespaced-path-encoding) owned by the authenticated user |
| `author_id` | integer | no | Return epics created by the given user `id` |
| `author_username` | string | no | Return epics created by the user with the given `username`. Available in [GitLab 14.7](https://gitlab.com/gitlab-org/gitlab/-/issues/348257) and later |
| `labels` | string | no | Return epics matching a comma-separated list of labels names. Label names from the epic group or a parent group can be used |
| `with_labels_details` | boolean | no | If `true`, response returns more details for each label in labels field: `:name`, `:color`, `:description`, `:description_html`, `:text_color`. Default is `false`. Available in [GitLab 12.7](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/21413) and later |
| `order_by` | string | no | Return epics ordered by `created_at`, `updated_at`, or `title` fields. Default is `created_at` |
......@@ -77,7 +78,7 @@ GET /groups/:id/epics?state=opened
| `include_ancestor_groups` | boolean | no | Include epics from the requested group's ancestors. Default is `false` |
| `include_descendant_groups` | boolean | no | Include epics from the requested group's descendants. Default is `true` |
| `my_reaction_emoji` | string | no | Return epics reacted by the authenticated user by the given emoji. `None` returns epics not given a reaction. `Any` returns epics given at least one reaction. Available in [GitLab 13.0](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/31479) and later |
| `not` | Hash | no | Return epics that do not match the parameters supplied. Accepts: `author_id` and `labels`. Available in [GitLab 14.6](https://gitlab.com/gitlab-org/gitlab/-/issues/347525) and later |
| `not` | Hash | no | Return epics that do not match the parameters supplied. Accepts: `author_id`, `author_username` ([GitLab 14.7](https://gitlab.com/gitlab-org/gitlab/-/issues/348257) and later) and `labels`. Available in [GitLab 14.6](https://gitlab.com/gitlab-org/gitlab/-/issues/347525) and later |
```shell
curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/groups/1/epics"
......
......@@ -16,7 +16,10 @@ module API
helpers do
params :negatable_epic_filter_params do
optional :labels, type: Array[String], coerce_with: ::API::Validations::Types::CommaSeparatedToArray.coerce, desc: 'Comma-separated list of label names'
optional :author_id, type: Integer, desc: 'Return epics which are not authored by the user with the given ID'
optional :author_username, type: String, desc: 'Return epics which are not authored by the given username'
mutually_exclusive :author_id, :author_username
end
end
......@@ -36,7 +39,11 @@ module API
optional :search, type: String, desc: 'Search epics for text present in the title or description'
optional :state, type: String, values: %w[opened closed all], default: 'all',
desc: 'Return opened, closed, or all epics'
optional :author_id, type: Integer, desc: 'Return epics which are authored by the user with the given ID'
optional :author_username, type: String, desc: 'Return epics which are authored by the given username'
mutually_exclusive :author_id, :author_username
optional :labels, type: Array[String], coerce_with: Validations::Types::CommaSeparatedToArray.coerce, desc: 'Comma-separated list of label names'
optional :with_labels_details, type: Boolean, desc: 'Return titles of labels and other details', default: false
optional :created_after, type: DateTime, desc: 'Return epics created after the specified time'
......
......@@ -210,6 +210,18 @@ RSpec.describe API::Epics do
expect_paginated_array_response([epic.id])
end
it 'returns epics not authored by the given author username' do
get api(url), params: { not: { author_username: user2.username } }
expect_paginated_array_response([epic.id])
end
it 'does not allow filtering by negating author_id and author_username together' do
get api(url), params: { not: { author_id: user2.id, author_username: user2.username } }
expect(response).to have_gitlab_http_status(:bad_request)
end
it 'returns epics without the given label' do
get api(url), params: { not: { labels: label.title } }
......@@ -222,6 +234,18 @@ RSpec.describe API::Epics do
expect_paginated_array_response([epic2.id])
end
it 'returns epics authored by the given author username' do
get api(url), params: { author_username: user2.username }
expect_paginated_array_response([epic2.id])
end
it 'does not allow filtering by author_id and author_username together' do
get api(url), params: { author_id: user2.id, author_username: user2.username }
expect(response).to have_gitlab_http_status(:bad_request)
end
it 'returns epics reacted to by current user' do
create(:award_emoji, awardable: epic, user: user, name: 'star')
create(:award_emoji, awardable: epic2, user: user2, name: 'star')
......
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