Commit 1c9315e3 authored by Rémy Coutable's avatar Rémy Coutable

Merge branch 'fix-group-api-archived' into 'master'

Fix archived parameter for Group API's projects endpoint

See merge request gitlab-org/gitlab!34018
parents 91479fec ad2743df
---
title: Remove default "archived" parameter value from Groups API's projects endpoint
merge_request: 34018
author: Justin Sleep
type: fixed
...@@ -218,7 +218,7 @@ module API ...@@ -218,7 +218,7 @@ module API
success Entities::Project success Entities::Project
end end
params do params do
optional :archived, type: Boolean, default: false, desc: 'Limit by archived status' optional :archived, type: Boolean, desc: 'Limit by archived status'
optional :visibility, type: String, values: Gitlab::VisibilityLevel.string_values, optional :visibility, type: String, values: Gitlab::VisibilityLevel.string_values,
desc: 'Limit by visibility' desc: 'Limit by visibility'
optional :search, type: String, desc: 'Return list of authorized projects matching the search criteria' optional :search, type: String, desc: 'Return list of authorized projects matching the search criteria'
...@@ -255,7 +255,7 @@ module API ...@@ -255,7 +255,7 @@ module API
success Entities::Project success Entities::Project
end end
params do params do
optional :archived, type: Boolean, default: false, desc: 'Limit by archived status' optional :archived, type: Boolean, desc: 'Limit by archived status'
optional :visibility, type: String, values: Gitlab::VisibilityLevel.string_values, optional :visibility, type: String, values: Gitlab::VisibilityLevel.string_values,
desc: 'Limit by visibility' desc: 'Limit by visibility'
optional :search, type: String, desc: 'Return list of authorized projects matching the search criteria' optional :search, type: String, desc: 'Return list of authorized projects matching the search criteria'
......
...@@ -15,6 +15,7 @@ RSpec.describe API::Groups do ...@@ -15,6 +15,7 @@ RSpec.describe API::Groups do
let_it_be(:project1) { create(:project, namespace: group1) } let_it_be(:project1) { create(:project, namespace: group1) }
let_it_be(:project2) { create(:project, namespace: group2) } let_it_be(:project2) { create(:project, namespace: group2) }
let_it_be(:project3) { create(:project, namespace: group1, path: 'test', visibility_level: Gitlab::VisibilityLevel::PRIVATE) } let_it_be(:project3) { create(:project, namespace: group1, path: 'test', visibility_level: Gitlab::VisibilityLevel::PRIVATE) }
let_it_be(:archived_project) { create(:project, namespace: group1, archived: true) }
before do before do
group1.add_owner(user1) group1.add_owner(user1)
...@@ -471,7 +472,7 @@ RSpec.describe API::Groups do ...@@ -471,7 +472,7 @@ RSpec.describe API::Groups do
expect(json_response['shared_with_groups'][0]['group_access_level']).to eq(link.group_access) expect(json_response['shared_with_groups'][0]['group_access_level']).to eq(link.group_access)
expect(json_response['shared_with_groups'][0]).to have_key('expires_at') expect(json_response['shared_with_groups'][0]).to have_key('expires_at')
expect(json_response['projects']).to be_an Array expect(json_response['projects']).to be_an Array
expect(json_response['projects'].length).to eq(2) expect(json_response['projects'].length).to eq(3)
expect(json_response['shared_projects']).to be_an Array expect(json_response['shared_projects']).to be_an Array
expect(json_response['shared_projects'].length).to eq(1) expect(json_response['shared_projects'].length).to eq(1)
expect(json_response['shared_projects'][0]['id']).to eq(project.id) expect(json_response['shared_projects'][0]['id']).to eq(project.id)
...@@ -696,7 +697,7 @@ RSpec.describe API::Groups do ...@@ -696,7 +697,7 @@ RSpec.describe API::Groups do
expect(json_response['parent_id']).to eq(nil) expect(json_response['parent_id']).to eq(nil)
expect(json_response['created_at']).to be_present expect(json_response['created_at']).to be_present
expect(json_response['projects']).to be_an Array expect(json_response['projects']).to be_an Array
expect(json_response['projects'].length).to eq(2) expect(json_response['projects'].length).to eq(3)
expect(json_response['shared_projects']).to be_an Array expect(json_response['shared_projects']).to be_an Array
expect(json_response['shared_projects'].length).to eq(0) expect(json_response['shared_projects'].length).to eq(0)
expect(json_response['default_branch_protection']).to eq(::Gitlab::Access::MAINTAINER_PROJECT_ACCESS) expect(json_response['default_branch_protection']).to eq(::Gitlab::Access::MAINTAINER_PROJECT_ACCESS)
...@@ -822,20 +823,51 @@ RSpec.describe API::Groups do ...@@ -822,20 +823,51 @@ RSpec.describe API::Groups do
expect(response).to have_gitlab_http_status(:ok) expect(response).to have_gitlab_http_status(:ok)
expect(response).to include_pagination_headers expect(response).to include_pagination_headers
expect(json_response.length).to eq(2) expect(json_response.length).to eq(3)
project_names = json_response.map { |proj| proj['name'] } project_names = json_response.map { |proj| proj['name'] }
expect(project_names).to match_array([project1.name, project3.name]) expect(project_names).to match_array([project1.name, project3.name, archived_project.name])
expect(json_response.first['visibility']).to be_present expect(json_response.first['visibility']).to be_present
end end
context 'and using archived' do
it "returns the group's archived projects" do
get api("/groups/#{group1.id}/projects?archived=true", user1)
expect(response).to have_gitlab_http_status(:ok)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array
expect(json_response.length).to eq(Project.public_or_visible_to_user(user1).where(archived: true).size)
expect(json_response.map { |project| project['id'] }).to include(archived_project.id)
end
it "returns the group's non-archived projects" do
get api("/groups/#{group1.id}/projects?archived=false", user1)
expect(response).to have_gitlab_http_status(:ok)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array
expect(json_response.length).to eq(Project.public_or_visible_to_user(user1).where(archived: false).size)
expect(json_response.map { |project| project['id'] }).not_to include(archived_project.id)
end
it "returns all of the group's projects" do
get api("/groups/#{group1.id}/projects", user1)
expect(response).to have_gitlab_http_status(:ok)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array
expect(json_response.map { |project| project['id'] }).to contain_exactly(*Project.public_or_visible_to_user(user1).pluck(:id))
end
end
it "returns the group's projects with simple representation" do it "returns the group's projects with simple representation" do
get api("/groups/#{group1.id}/projects", user1), params: { simple: true } get api("/groups/#{group1.id}/projects", user1), params: { simple: true }
expect(response).to have_gitlab_http_status(:ok) expect(response).to have_gitlab_http_status(:ok)
expect(response).to include_pagination_headers expect(response).to include_pagination_headers
expect(json_response.length).to eq(2) expect(json_response.length).to eq(3)
project_names = json_response.map { |proj| proj['name'] } project_names = json_response.map { |proj| proj['name'] }
expect(project_names).to match_array([project1.name, project3.name]) expect(project_names).to match_array([project1.name, project3.name, archived_project.name])
expect(json_response.first['visibility']).not_to be_present expect(json_response.first['visibility']).not_to be_present
end end
...@@ -861,7 +893,7 @@ RSpec.describe API::Groups do ...@@ -861,7 +893,7 @@ RSpec.describe API::Groups do
expect(response).to have_gitlab_http_status(:ok) expect(response).to have_gitlab_http_status(:ok)
expect(response).to include_pagination_headers expect(response).to include_pagination_headers
expect(json_response).to be_an(Array) expect(json_response).to be_an(Array)
expect(json_response.length).to eq(2) expect(json_response.length).to eq(3)
end end
it "returns projects including those in subgroups" do it "returns projects including those in subgroups" do
...@@ -874,7 +906,7 @@ RSpec.describe API::Groups do ...@@ -874,7 +906,7 @@ RSpec.describe API::Groups do
expect(response).to have_gitlab_http_status(:ok) expect(response).to have_gitlab_http_status(:ok)
expect(response).to include_pagination_headers expect(response).to include_pagination_headers
expect(json_response).to be_an(Array) expect(json_response).to be_an(Array)
expect(json_response.length).to eq(4) expect(json_response.length).to eq(5)
end end
it "does not return a non existing group" do it "does not return a non existing group" do
...@@ -959,7 +991,7 @@ RSpec.describe API::Groups do ...@@ -959,7 +991,7 @@ RSpec.describe API::Groups do
expect(response).to have_gitlab_http_status(:ok) expect(response).to have_gitlab_http_status(:ok)
expect(response).to include_pagination_headers expect(response).to include_pagination_headers
project_names = json_response.map { |proj| proj['name'] } project_names = json_response.map { |proj| proj['name'] }
expect(project_names).to match_array([project1.name, project3.name]) expect(project_names).to match_array([project1.name, project3.name, archived_project.name])
end end
it 'does not return a non existing group' do it 'does not return a non existing group' 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