diff --git a/changelogs/unreleased/fix-group-api-archived.yml b/changelogs/unreleased/fix-group-api-archived.yml new file mode 100644 index 0000000000000000000000000000000000000000..549d6f48fe9d54a5c1d55c563e3ab62cf433bc06 --- /dev/null +++ b/changelogs/unreleased/fix-group-api-archived.yml @@ -0,0 +1,5 @@ +--- +title: Remove default "archived" parameter value from Groups API's projects endpoint +merge_request: 34018 +author: Justin Sleep +type: fixed diff --git a/lib/api/groups.rb b/lib/api/groups.rb index 85c0c6bfa17d780a783491f616a8ccf52232482e..9ac3ac818fcdec9415c601787f07a68644b2adf0 100644 --- a/lib/api/groups.rb +++ b/lib/api/groups.rb @@ -218,7 +218,7 @@ def delete_group(group) success Entities::Project end 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, desc: 'Limit by visibility' optional :search, type: String, desc: 'Return list of authorized projects matching the search criteria' @@ -255,7 +255,7 @@ def delete_group(group) success Entities::Project end 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, desc: 'Limit by visibility' optional :search, type: String, desc: 'Return list of authorized projects matching the search criteria' diff --git a/spec/requests/api/groups_spec.rb b/spec/requests/api/groups_spec.rb index 79ab9158461bf900c34dd78799535c7a81446f90..fac9f4dfe004d5f2c4b4c83579762de609852f42 100644 --- a/spec/requests/api/groups_spec.rb +++ b/spec/requests/api/groups_spec.rb @@ -15,6 +15,7 @@ let_it_be(:project1) { create(:project, namespace: group1) } 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(:archived_project) { create(:project, namespace: group1, archived: true) } before do group1.add_owner(user1) @@ -471,7 +472,7 @@ def response_project_ids(json_response, key) 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['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'].length).to eq(1) expect(json_response['shared_projects'][0]['id']).to eq(project.id) @@ -696,7 +697,7 @@ def make_upload_request expect(json_response['parent_id']).to eq(nil) expect(json_response['created_at']).to be_present 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'].length).to eq(0) expect(json_response['default_branch_protection']).to eq(::Gitlab::Access::MAINTAINER_PROJECT_ACCESS) @@ -822,20 +823,51 @@ def make_upload_request expect(response).to have_gitlab_http_status(:ok) 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'] } - 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 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 get api("/groups/#{group1.id}/projects", user1), params: { simple: true } expect(response).to have_gitlab_http_status(:ok) 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'] } - 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 end @@ -861,7 +893,7 @@ def make_upload_request 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(2) + expect(json_response.length).to eq(3) end it "returns projects including those in subgroups" do @@ -874,7 +906,7 @@ def make_upload_request 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(4) + expect(json_response.length).to eq(5) end it "does not return a non existing group" do @@ -959,7 +991,7 @@ def make_upload_request expect(response).to have_gitlab_http_status(:ok) expect(response).to include_pagination_headers 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 it 'does not return a non existing group' do