summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRémy Coutable <remy@rymai.me>2016-12-12 14:10:22 +0000
committerRémy Coutable <remy@rymai.me>2016-12-12 14:10:22 +0000
commit7e9a8bb760cf6f9c7b3aa6b2b98bff30b58bc325 (patch)
tree457ca5e95227028b9c991f703eb1276eb06fe2cb
parentb83a9138769e7585bd6aaa739c78cdde809f9aa9 (diff)
parent81a12c10fe7ba6f58ab4d1ae57861aa8899d545f (diff)
downloadgitlab-ce-7e9a8bb760cf6f9c7b3aa6b2b98bff30b58bc325.tar.gz
Merge branch 'api-fix-group-projects-filter' into 'master'
API: Add the project filter to the groups endpoint. Related to #22928. Closes https://gitlab.com/gitlab-org/gitlab-ce/issues/25420 See merge request !8034
-rw-r--r--lib/api/groups.rb11
-rw-r--r--spec/requests/api/groups_spec.rb11
2 files changed, 21 insertions, 1 deletions
diff --git a/lib/api/groups.rb b/lib/api/groups.rb
index fbf7513302b..105d3ee342e 100644
--- a/lib/api/groups.rb
+++ b/lib/api/groups.rb
@@ -1,7 +1,7 @@
module API
class Groups < Grape::API
include PaginationParams
-
+
before { authenticate! }
helpers do
@@ -117,11 +117,20 @@ module API
success Entities::Project
end
params do
+ optional :archived, type: Boolean, default: false, desc: 'Limit by archived status'
+ optional :visibility, type: String, values: %w[public internal private],
+ desc: 'Limit by visibility'
+ optional :search, type: String, desc: 'Return list of authorized projects matching the search criteria'
+ optional :order_by, type: String, values: %w[id name path created_at updated_at last_activity_at],
+ default: 'created_at', desc: 'Return projects ordered by field'
+ optional :sort, type: String, values: %w[asc desc], default: 'desc',
+ desc: 'Return projects sorted in ascending and descending order'
use :pagination
end
get ":id/projects" do
group = find_group!(params[:id])
projects = GroupProjectsFinder.new(group).execute(current_user)
+ projects = filter_projects(projects)
present paginate(projects), with: Entities::Project, user: current_user
end
diff --git a/spec/requests/api/groups_spec.rb b/spec/requests/api/groups_spec.rb
index 548ed8e1892..15647b262b6 100644
--- a/spec/requests/api/groups_spec.rb
+++ b/spec/requests/api/groups_spec.rb
@@ -245,6 +245,17 @@ describe API::Groups, api: true do
expect(project_names).to match_array([project1.name, project3.name])
end
+ it 'filters the groups projects' do
+ public_projet = create(:project, :public, path: 'test1', group: group1)
+
+ get api("/groups/#{group1.id}/projects", user1), visibility: 'public'
+
+ expect(response).to have_http_status(200)
+ expect(json_response).to be_an(Array)
+ expect(json_response.length).to eq(1)
+ expect(json_response.first['name']).to eq(public_projet.name)
+ end
+
it "does not return a non existing group" do
get api("/groups/1328/projects", user1)
expect(response).to have_http_status(404)