Commit 32b248af authored by Heinrich Lee Yu's avatar Heinrich Lee Yu

Merge branch '197170-issues-api-endpoint-missmatch-web-ui' into 'master'

Add non_archived param issues API

See merge request gitlab-org/gitlab!30381
parents b26e9115 3fa2c870
---
title: Add non_archived argument to issues API endpoint
merge_request: 30381
author:
type: added
......@@ -67,6 +67,7 @@ GET /issues?confidential=true
| `updated_before` | datetime | no | Return issues updated on or before the given time |
| `confidential` | boolean | no | Filter confidential or public issues. |
| `not` | Hash | no | Return issues that do not match the parameters supplied. Accepts: `labels`, `milestone`, `author_id`, `author_username`, `assignee_id`, `assignee_username`, `my_reaction_emoji`, `search`, `in` |
| `non_archived` | boolean | no | Return issues only from non-archived projects. If `false`, response will return issues from both archived and non-archived projects. Default is `true`. _(Introduced in [GitLab 13.0](https://gitlab.com/gitlab-org/gitlab/-/issues/197170))_ |
```shell
curl --header "PRIVATE-TOKEN: <your_access_token>" https://gitlab.example.com/api/v4/issues
......
......@@ -95,6 +95,8 @@ module API
use :issues_params
optional :scope, type: String, values: %w[created-by-me assigned-to-me created_by_me assigned_to_me all], default: 'created_by_me',
desc: 'Return issues for the given scope: `created_by_me`, `assigned_to_me` or `all`'
optional :non_archived, type: Boolean, default: true,
desc: 'Return issues from non archived projects'
end
get do
authenticate! unless params[:scope] == 'all'
......
......@@ -3,26 +3,26 @@
require 'spec_helper'
describe API::Issues do
let_it_be(:user2) { create(:user) }
let_it_be(:admin) { create(:user, :admin) }
let_it_be(:non_member) { create(:user) }
let_it_be(:user) { create(:user) }
let(:user2) { create(:user) }
let(:non_member) { create(:user) }
let_it_be(:guest) { create(:user) }
let_it_be(:author) { create(:author) }
let_it_be(:assignee) { create(:assignee) }
let(:admin) { create(:user, :admin) }
let(:issue_title) { 'foo' }
let(:issue_description) { 'closed' }
let(:no_milestone_title) { 'None' }
let(:any_milestone_title) { 'Any' }
let_it_be(:issue_title) { 'foo' }
let_it_be(:issue_description) { 'closed' }
let_it_be(:no_milestone_title) { 'None' }
let_it_be(:any_milestone_title) { 'Any' }
before do
stub_licensed_features(multiple_issue_assignees: false, issue_weights: false)
end
describe 'GET /groups/:id/issues' do
let!(:group) { create(:group) }
let!(:group_project) { create(:project, :public, :repository, creator_id: user.id, namespace: group) }
let!(:private_mrs_project) do
let_it_be(:group) { create(:group) }
let_it_be(:group_project) { create(:project, :public, :repository, creator_id: user.id, namespace: group) }
let_it_be(:private_mrs_project) do
create(:project, :public, :repository, creator_id: user.id, namespace: group, merge_requests_access_level: ProjectFeature::PRIVATE)
end
......@@ -455,6 +455,29 @@ describe API::Issues do
it_behaves_like 'labeled issues with labels and label_name params'
end
context 'with archived projects' do
let_it_be(:archived_issue) do
create(
:issue, author: user, assignees: [user],
project: create(:project, :public, :archived, creator_id: user.id, namespace: group)
)
end
it 'returns only non archived projects issues' do
get api(base_url, user)
expect_paginated_array_response([group_closed_issue.id, group_confidential_issue.id, group_issue.id])
end
it 'returns issues from archived projects if non_archived it set to false' do
get api(base_url, user), params: { non_archived: false }
expect_paginated_array_response(
[archived_issue.id, group_closed_issue.id, group_confidential_issue.id, group_issue.id]
)
end
end
it 'returns an array of issues found by iids' do
get api(base_url, user), params: { iids: [group_issue.iid] }
......
......@@ -780,28 +780,20 @@ describe API::Issues do
end
context 'filtering by non_archived' do
let_it_be(:group1) { create(:group) }
let_it_be(:archived_project) { create(:project, :archived, namespace: group1) }
let_it_be(:active_project) { create(:project, namespace: group1) }
let_it_be(:issue1) { create(:issue, project: active_project) }
let_it_be(:issue2) { create(:issue, project: active_project) }
let_it_be(:issue3) { create(:issue, project: archived_project) }
let_it_be(:archived_project) { create(:project, :archived, creator_id: user.id, namespace: user.namespace) }
let_it_be(:archived_issue) { create(:issue, author: user, project: archived_project) }
let_it_be(:active_issue) { create(:issue, author: user, project: project) }
before do
archived_project.add_developer(user)
active_project.add_developer(user)
end
it 'returns issues from non archived projects only by default' do
get api("/groups/#{group1.id}/issues", user), params: { scope: 'all' }
it 'returns issues from non archived projects by default' do
get api('/issues', user)
expect_paginated_array_response([issue2.id, issue1.id])
expect_paginated_array_response(active_issue.id, issue.id, closed_issue.id)
end
it 'returns issues from archived and non archived projects when non_archived is false' do
get api("/groups/#{group1.id}/issues", user), params: { non_archived: false, scope: 'all' }
it 'returns issues from archived project with non_archived set as false' do
get api("/issues", user), params: { non_archived: false }
expect_paginated_array_response([issue3.id, issue2.id, issue1.id])
expect_paginated_array_response(active_issue.id, archived_issue.id, issue.id, closed_issue.id)
end
end
end
......
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